From 7675224af72b5fce908f581a555f9c5885e838fd Mon Sep 17 00:00:00 2001 From: Toastie Date: Thu, 3 Oct 2024 00:28:21 +1300 Subject: [PATCH] 2.0.2 --- configs/javascript.js | 86 ++++++++++++++++++++++++ configs/recommended.js | 145 ++--------------------------------------- configs/typescript.js | 63 ++++++++++++++++++ index.js | 17 +++-- package.json | 2 +- 5 files changed, 167 insertions(+), 146 deletions(-) create mode 100644 configs/javascript.js create mode 100644 configs/typescript.js diff --git a/configs/javascript.js b/configs/javascript.js new file mode 100644 index 0000000..09a21f7 --- /dev/null +++ b/configs/javascript.js @@ -0,0 +1,86 @@ +import { fixupPluginRules } from '@eslint/compat'; +import _import from 'eslint-plugin-import'; + +const jsRules = { + 'indent': ['warn', 'tab', { + 'SwitchCase': 1, + 'MemberExpression': 1, + 'flatTernaryExpressions': true, + 'ArrayExpression': 'first', + 'ObjectExpression': 'first', + }], + 'eol-last': ['error', 'always'], + 'semi': ['error', 'always'], + 'semi-spacing': ['error', { 'before': false, 'after': true }], + 'quotes': ['warn', 'single'], + 'comma-dangle': ['warn', 'always-multiline'], + 'comma-spacing': ['error', { 'before': false, 'after': true }], + 'array-bracket-spacing': ['error', 'never'], + 'keyword-spacing': ['error', { + 'before': true, + 'after': true, + }], + 'key-spacing': ['error', { + 'beforeColon': false, + 'afterColon': true, + }], + 'arrow-spacing': ['error', { + 'before': true, + 'after': true, + }], + 'brace-style': ['error', '1tbs', { + 'allowSingleLine': true, + }], + 'padded-blocks': ['error', 'never'], + /* TODO: If you do not use path alias, a warning will be issued. + 'no-restricted-imports': ['warn', { + 'patterns': [ + ], + }], + */ + 'eqeqeq': ['error', 'always', { 'null': 'ignore' }], + 'no-multi-spaces': ['error'], + 'no-var': ['error'], + 'prefer-arrow-callback': ['error'], + 'no-throw-literal': ['error'], + 'no-param-reassign': ['warn'], + 'no-constant-condition': ['warn'], + 'no-empty-pattern': ['warn'], + 'no-async-promise-executor': ['off'], + 'no-useless-escape': ['off'], + 'no-multiple-empty-lines': ['error', { 'max': 1 }], + 'no-control-regex': ['warn'], + 'no-empty': ['warn'], + 'no-inner-declarations': ['off'], + 'no-sparse-arrays': ['off'], + 'nonblock-statement-body-position': ['error', 'beside'], + 'object-curly-spacing': ['error', 'always'], + 'space-infix-ops': ['error'], + 'space-before-blocks': ['error', 'always'], + 'padding-line-between-statements': [ + 'error', + { 'blankLine': 'always', 'prev': 'function', 'next': '*' }, + { 'blankLine': 'always', 'prev': '*', 'next': 'function' }, + ], + 'lines-between-class-members': 'off', + 'import/no-unresolved': ['off'], + 'import/no-default-export': ['warn'], + 'import/order': ['warn', { + 'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'], + }], +}; + +export default { + plugins: { + import: fixupPluginRules(_import), + }, + settings: { + /** @see https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-1419518561 */ + 'import/parsers': { + '@typescript-eslint/parser': ['.js', '.cjs', '.mjs', '.jsx'], + }, + }, + rules: { + ...jsRules, + }, +}; diff --git a/configs/recommended.js b/configs/recommended.js index 3e7f25b..e508376 100644 --- a/configs/recommended.js +++ b/configs/recommended.js @@ -1,11 +1,10 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import typescriptEslint from '@typescript-eslint/eslint-plugin'; -import tsParser from '@typescript-eslint/parser'; -import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'; +import { fixupConfigRules } from '@eslint/compat'; import { FlatCompat } from '@eslint/eslintrc'; import js from '@eslint/js'; -import _import from 'eslint-plugin-import'; +import javascript from './javascript.js'; +import typescript from './typescript.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -15,114 +14,6 @@ const compat = new FlatCompat({ allConfig: js.configs.all, }); -const jsRules = { - 'indent': ['warn', 'tab', { - 'SwitchCase': 1, - 'MemberExpression': 1, - 'flatTernaryExpressions': true, - 'ArrayExpression': 'first', - 'ObjectExpression': 'first', - }], - 'eol-last': ['error', 'always'], - 'semi': ['error', 'always'], - 'semi-spacing': ['error', { 'before': false, 'after': true }], - 'quotes': ['warn', 'single'], - 'comma-dangle': ['warn', 'always-multiline'], - 'comma-spacing': ['error', { 'before': false, 'after': true }], - 'array-bracket-spacing': ['error', 'never'], - 'keyword-spacing': ['error', { - 'before': true, - 'after': true, - }], - 'key-spacing': ['error', { - 'beforeColon': false, - 'afterColon': true, - }], - 'arrow-spacing': ['error', { - 'before': true, - 'after': true, - }], - 'brace-style': ['error', '1tbs', { - 'allowSingleLine': true, - }], - 'padded-blocks': ['error', 'never'], - /* TODO: If you do not use path alias, a warning will be issued. - 'no-restricted-imports': ['warn', { - 'patterns': [ - ], - }], - */ - 'eqeqeq': ['error', 'always', { 'null': 'ignore' }], - 'no-multi-spaces': ['error'], - 'no-var': ['error'], - 'prefer-arrow-callback': ['error'], - 'no-throw-literal': ['error'], - 'no-param-reassign': ['warn'], - 'no-constant-condition': ['warn'], - 'no-empty-pattern': ['warn'], - 'no-async-promise-executor': ['off'], - 'no-useless-escape': ['off'], - 'no-multiple-empty-lines': ['error', { 'max': 1 }], - 'no-control-regex': ['warn'], - 'no-empty': ['warn'], - 'no-inner-declarations': ['off'], - 'no-sparse-arrays': ['off'], - 'nonblock-statement-body-position': ['error', 'beside'], - 'object-curly-spacing': ['error', 'always'], - 'space-infix-ops': ['error'], - 'space-before-blocks': ['error', 'always'], - 'padding-line-between-statements': [ - 'error', - { 'blankLine': 'always', 'prev': 'function', 'next': '*' }, - { 'blankLine': 'always', 'prev': '*', 'next': 'function' }, - ], - 'lines-between-class-members': 'off', - 'import/no-unresolved': ['off'], - 'import/no-default-export': ['warn'], - 'import/order': ['warn', { - 'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'], - }], -}; - -const tsRules = { - /* It seems that typescript-eslint does not support enforce. - '@typescript-eslint/lines-between-class-members': ['error', { - enforce: [{ - blankLine: 'always', - prev: 'method', - next: '*', - }], - }], - */ - '@typescript-eslint/func-call-spacing': ['error', 'never'], - '@typescript-eslint/no-explicit-any': ['warn'], - '@typescript-eslint/no-unused-vars': ['warn'], - '@typescript-eslint/no-unnecessary-condition': ['warn'], - '@typescript-eslint/no-var-requires': ['warn'], - '@typescript-eslint/no-inferrable-types': ['warn'], - '@typescript-eslint/no-empty-function': ['off'], - '@typescript-eslint/no-non-null-assertion': ['warn'], - '@typescript-eslint/explicit-function-return-type': ['off'], - '@typescript-eslint/no-misused-promises': ['error', { - 'checksVoidReturn': false, - }], - '@typescript-eslint/consistent-type-imports': 'off', - '@typescript-eslint/prefer-nullish-coalescing': [ - 'warn', - ], - '@typescript-eslint/naming-convention': [ - 'error', - { - 'selector': 'typeLike', - 'format': ['PascalCase'], - }, - { - 'selector': 'typeParameter', - 'format': [], - }, - ], -}; - export default [ ...fixupConfigRules(compat.extends( 'eslint:recommended', @@ -135,36 +26,10 @@ export default [ )), { files: ['**/*.js', '**/*.cjs', '**/*.mjs', '**/*.jsx'], - plugins: { - import: fixupPluginRules(_import), - }, - settings: { - /** @see https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-1419518561 */ - 'import/parsers': { - '@typescript-eslint/parser': ['.js', '.cjs', '.mjs', '.jsx'], - }, - }, - rules: { - ...jsRules, - }, + ...javascript, }, { files: ['**/*.ts', '**/*.tsx'], - plugins: { - '@typescript-eslint': fixupPluginRules(typescriptEslint), - import: fixupPluginRules(_import), - }, - languageOptions: { - parser: tsParser, - }, - settings: { - 'import/parsers': { - '@typescript-eslint/parser': ['.ts', '.tsx'], - }, - }, - rules: { - ...jsRules, - ...tsRules, - }, + ...typescript, }, ]; diff --git a/configs/typescript.js b/configs/typescript.js new file mode 100644 index 0000000..88278bf --- /dev/null +++ b/configs/typescript.js @@ -0,0 +1,63 @@ +import typescriptEslint from '@typescript-eslint/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; +import { fixupPluginRules } from '@eslint/compat'; +import _import from 'eslint-plugin-import'; +import javascript from './javascript.js'; + +const tsRules = { + /* It seems that typescript-eslint does not support enforce. + '@typescript-eslint/lines-between-class-members': ['error', { + enforce: [{ + blankLine: 'always', + prev: 'method', + next: '*', + }], + }], + */ + '@typescript-eslint/func-call-spacing': ['error', 'never'], + '@typescript-eslint/no-explicit-any': ['warn'], + '@typescript-eslint/no-unused-vars': ['warn'], + '@typescript-eslint/no-unnecessary-condition': ['warn'], + '@typescript-eslint/no-var-requires': ['warn'], + '@typescript-eslint/no-inferrable-types': ['warn'], + '@typescript-eslint/no-empty-function': ['off'], + '@typescript-eslint/no-non-null-assertion': ['warn'], + '@typescript-eslint/explicit-function-return-type': ['off'], + '@typescript-eslint/no-misused-promises': ['error', { + 'checksVoidReturn': false, + }], + '@typescript-eslint/consistent-type-imports': 'off', + '@typescript-eslint/prefer-nullish-coalescing': [ + 'warn', + ], + '@typescript-eslint/naming-convention': [ + 'error', + { + 'selector': 'typeLike', + 'format': ['PascalCase'], + }, + { + 'selector': 'typeParameter', + 'format': [], + }, + ], +}; + +export default { + plugins: { + '@typescript-eslint': fixupPluginRules(typescriptEslint), + import: fixupPluginRules(_import), + }, + languageOptions: { + parser: tsParser, + }, + settings: { + 'import/parsers': { + '@typescript-eslint/parser': ['.ts', '.tsx'], + }, + }, + rules: { + ...javascript.rules, + ...tsRules, + }, +}; diff --git a/index.js b/index.js index 2e5b29d..78fc7f4 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,22 @@ +import javascript from './configs/javascript.js'; import recommended from './configs/recommended.js'; -// import packageConfig from './package.json' with { type: 'json' }; +import typescript from './configs/typescript.js'; + +/** + * TODO: I want to import attributes, but depending on the VS Code environment, an error occurs, so I put this off for now. + * @see https://github.com/microsoft/vscode-eslint/issues/1848 + */ +import packageConfig from './package.json' assert { type: 'json' }; const plugin = { meta: { - // name: packageConfig.name, - // version: packageConfig.version, - name: '@valkyriecoms/eslint-plugin', - version: '1.0.0', + name: packageConfig.name, + version: packageConfig.version, }, configs: { + javascript, recommended, + typescript, }, }; diff --git a/package.json b/package.json index 563f9dd..469e024 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@valkyriecoms/eslint-plugin", - "version": "2.0.1", + "version": "2.0.2", "description": "An ESLint plugin designed for Valkyriecoms developers", "author": "Toastie