オレオレ ESLint プラグイン集。
$ npm install --save-dev @neos21/neos-eslint-pluginESLint v9 以降の Flat Config を前提としています。
eslint.config.ts(or ESM) : 使用したいルールだけをrulesに記載し、warnまたはerrorを指定します
import neosEslintPlugin from '@neos21/neos-eslint-plugin';
export default [
{
files: ['src/**/*.{js,jsx,ts,tsx}'],
plugins: {
'neos-eslint-plugin': neosEslintPlugin
},
rules: {
'neos-eslint-plugin/blank-line-indent' : 'error',
'neos-eslint-plugin/doc-comment-format' : 'error',
'neos-eslint-plugin/newline-before-statement': 'error',
'neos-eslint-plugin/no-space-before-paren' : 'error'
}
}
];全ルールを推奨設定を利用する場合は以下のように書けます。
import neosEslintPlugin from '@neos21/neos-eslint-plugin';
export default [
{ files: ['src/**/*.{js,jsx,ts,tsx}'] },
neosEslintPlugin.configs.recommended
];全ルールをエラーレベルではなくワーニングレベルで出力する場合は以下を使用できます。
import neosEslintPlugin from '@neos21/neos-eslint-plugin';
export default [
{ files: ['src/**/*.{js,jsx,ts,tsx}'] },
neosEslintPlugin.configs.warn
];CommonJS での利用時は .default を付けて require() してください。後の書き方は同じです。
const neosEslintPlugin = require('@neos21/neos-eslint-plugin').default;
module.exports = [...];blank-line-indent: 空行にその行が属するブロックのインデント深さに合わせたスペースを入れる … Auto Fix 対応doc-comment-format: ドキュメンテーションコメントの空行の末尾にスペースを入れる … Auto Fix 対応newline-before-statement:else・else if・catch・finally・whileの直前に改行を入れる … Auto Fix 対応no-space-before-paren:if・else if・catch・for・switch・whileの直後のカッコとの間にスペースを開けない
package.jsonmain: CommonJS のエントリポイントmodule: ESM のエントリポイントtypes: TypeScript 向け型定義.d.tsのエントリポイントexports: Node.js v12 以降向けのエントリポイント定義require: CommonJSimport: ESMtypes: TypeScript
files:npm publish時に同梱されるファイル・ディレクトリpeerDependencies: Flat Config 前提のため ESLint v9 以降を対象とするよう指定した
.npmignore:package.jsonのfilesと併せて除外するファイル・ディレクトリを定義する・ビルド後の資材だけ含まれる用に設定した