コンテンツにスキップ

共有設定

ESLint 共有設定 は、開始点となる包括的なルール設定のリストを提供するために存在します。ESLint Stylistic は、そのまま使用できる、または独自の custom 設定の基礎として使用できる、いくつかの組み込み設定を保持しています。

バージョンポリシー

共有設定に新しいルールを追加したり、オプションを調整したりすることは、**破壊的変更ではない**とみなします。必要な変更はマイナーリリースでのみ行うようにします。

設定ファクトリー

クリーンで一貫性のあるコードスタイルを実現する、細かく調整された共有設定。

フォーマットとスタイルのルールは常に意見が分かれます。私たちは、使用を簡素化しながら、ルールを好みに合わせてカスタマイズできるように、共有設定を提供したいと考えています。そのため、他の ESLint プラグインとは異なり、カスタマイズ可能な高レベルのオプションを備えた **ファクトリー関数** を提供しています。

js
// eslint.config.js
import stylistic from '@stylistic/eslint-plugin'

export default [
  stylistic.configs.customize({
    // the following options are the default values
    indent: 2,
    quotes: 'single',
    semi: false,
    jsx: true,
    // ...
  }),
  // ...you other config items
]
js
// .eslintrc.js
const stylistic = require('@stylistic/eslint-plugin')

const customized = stylistic.configs.customize({
  // the following options are the default values
  indent: 2,
  quotes: 'single',
  semi: false,
  jsx: true,
  // ...
})

module.exports = {
  plugins: [
    '@stylistic'
  ],
  rules: {
    ...customized.rules,
    // ...your other rules
  }
}

設定されているルールの完全なリストについては、ソースコード を参照してください。

現在、このファクトリーは @stylistic/eslint-plugin パッケージでのみ利用可能です。

ルールのデフォルト

すべてのルールが使用されているわけではなく、各ルールに設定されているオプションは、ルールの独自のデフォルト値とは異なる場合があることに注意してください。

静的設定

デフォルトに同意する場合は、ファクトリー関数 から事前に生成された静的設定も提供しており、簡単に使用できます。

デフォルトのオプションは次のとおりです。

js
{
  indent: 2,
  quotes: 'single',
  semi: false,
  jsx: true,
}
js
// eslint.config.js
import stylistic from '@stylistic/eslint-plugin'

export default [
  stylistic.configs['recommended-flat'],
  // ...your other config items
]
js
// .eslintrc.js
module.exports = {
  extends: [
    'plugin:@stylistic/recommended-extends'
  ],
  rules: {
    // ...your other rules
  }
}

利用可能なすべてのルールを有効にする

すべてのルールをデフォルトのオプションで有効にしたい場合 (推奨されません)、そのための設定も提供しています。

警告

ESLint Stylistic の多くのルールは、ESLint の 10 年間のコードベースから移行されました。互換性のために、各ルールの元のデフォルトオプションを保持しました。これらは異なる時期に異なる理念で設計されている可能性があるため、デフォルトのオプションが常に一緒に最適に機能するとは限りません。クリーンで一貫性のあるコードスタイルを実現する、細かく調整された設定である ファクトリー関数 を使用することをお勧めします。

js
// eslint.config.js
import stylistic from '@stylistic/eslint-plugin'

export default [
  stylistic.configs['all-flat'],
  // ...your other config items
]
js
// .eslintrc.js
module.exports = {
  extends: [
    'plugin:@stylistic/all-extends'
  ],
  rules: {
    // ...your other rules
  }
}

情報

ルール間の互換性のため、`all` 設定には JSX ルールと修正不可能なルールは含まれていません。これらは手動で設定する必要がある場合があります。

この設定は、各プラグインパッケージでも利用できます。たとえば、`@stylistic/eslint-plugin-js` の場合は次のようになります。

js
// eslint.config.js
import stylisticJs from '@stylistic/eslint-plugin-js'

export default [
  stylisticJs.configs['all-flat'],
  // ...your other config items
]
js
// .eslintrc.js
module.exports = {
  extends: [
    'plugin:@stylistic/js/all-extends'
  ],
  rules: {
    // ...your other rules
  }
}

レガシールールの無効化

レガシールールがまだ含まれていて移行されていないプリセットを拡張している場合は、それらをすべて無効にするための設定プリセットを提供しています。

移行ガイド で詳細をご覧ください。

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