コンテンツへスキップ

@stylistic/js/

yield-star-spacing

ルール詳細

このルールは、`yield*` 式における`*` の周りのスペースを強制します。

オプション

このルールは、`before` と `after` の2つのキーを持つオブジェクトを1つのオプションとして受け取ります。それぞれのキーは、ブール値 `true` または `false` を持ちます。

  • `before` は `yield` と `*` の間のスペースを強制します。`true` の場合、スペースが必要で、それ以外の場合はスペースは許可されません。

  • `after` は `*` と引数の間のスペースを強制します。`true` の場合、スペースが必要で、それ以外の場合はスペースは許可されません。

デフォルトは `{"before": false, "after": true}` です。

JSON
"yield-star-spacing": ["error", {"before": true, "after": false}]

オプションには、文字列による省略記法もあります。

  • `{"before": false, "after": true}` → `"after"`
  • `{"before": true, "after": false}` → `"before"`
  • `{"before": true, "after": true}` → `"both"`
  • `{"before": false, "after": false}` → `"neither"`
JSON
"yield-star-spacing": ["error", "after"]

after

デフォルトの `"after"` オプションを使用したこのルールの**正しい**コードの例

JS
/*eslint @stylistic/js/yield-star-spacing: ["error", "after"]*/
/*eslint-env es6*/

function* generator() {
  yield* other();
}
正しい

before

`"before"` オプションを使用したこのルールの**正しい**コードの例

JS
/*eslint @stylistic/js/yield-star-spacing: ["error", "before"]*/
/*eslint-env es6*/

function *generator() {
  yield *other();
}
正しい

both

`"both"` オプションを使用したこのルールの**正しい**コードの例

JS
/*eslint @stylistic/js/yield-star-spacing: ["error", "both"]*/
/*eslint-env es6*/

function * generator() {
  yield * other();
}
正しい

neither

`"neither"` オプションを使用したこのルールの**正しい**コードの例

JS
/*eslint @stylistic/js/yield-star-spacing: ["error", "neither"]*/
/*eslint-env es6*/

function*generator() {
  yield*other();
}
正しい

使用しない場合

プロジェクトでジェネレーターを使用しない場合、またはスペースの一貫性を気にしていない場合は、このルールは必要ありません。

MITライセンスの下でリリースされています。