From e8b47bf733cd657c18d6531a3423dee7762a8a7e Mon Sep 17 00:00:00 2001 From: Refringe Date: Tue, 7 May 2024 14:26:54 -0400 Subject: [PATCH] ESLint Configuration Format & Import Sorting The built-in ESLint import settings will lint the imports, but not fix them, as that's concidered stylistic. The ESLint Stylistic package doesn't currently support sorting. We have to use the ESLint Import plugin to force import sorting. This Import plugin doesn't yet support the new ESLint flat-configuration file format so we've had to convert back to the old no-flat format. --- project/.eslintrc.json | 113 ++++++++++++++++++++++++++++++++++ project/Server.code-workspace | 2 +- project/eslint.config.mjs | 81 ------------------------ project/package.json | 2 + 4 files changed, 116 insertions(+), 82 deletions(-) create mode 100644 project/.eslintrc.json delete mode 100644 project/eslint.config.mjs diff --git a/project/.eslintrc.json b/project/.eslintrc.json new file mode 100644 index 00000000..2923eff8 --- /dev/null +++ b/project/.eslintrc.json @@ -0,0 +1,113 @@ +{ + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:@stylistic/recommended-extends", + "plugin:import/recommended", + "plugin:import/typescript" + ], + "plugins": [ + "@typescript-eslint", + "@stylistic", + "import" + ], + "settings": { + "import/resolver": { + "typescript": { + "project": "tsconfig.json" + }, + "node": { + "extensions": [".ts", ".mjs"] + } + } + }, + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-dynamic-delete": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-var-requires": "error", + "@typescript-eslint/explicit-module-boundary-types": ["error", { + "allowArgumentsExplicitlyTypedAsAny": true + }], + "@typescript-eslint/naming-convention": ["error", { + "selector": "default", + "format": ["camelCase"], + "leadingUnderscore": "allow" + }, { + "selector": "typeLike", + "format": ["PascalCase"] + }, { + "selector": "objectLiteralProperty", + "format": ["PascalCase", "camelCase", "snake_case"], + "leadingUnderscore": "allow" + }, { + "selector": "typeProperty", + "format": ["PascalCase", "camelCase"], + "leadingUnderscore": "allow" + }, { + "selector": "enumMember", + "format": ["UPPER_CASE"] + }, { + "selector": "property", + "modifiers": ["readonly", "static"], + "format": ["UPPER_CASE"] + }], + "@stylistic/indent": ["error", 4, { "MemberExpression": 1, "SwitchCase": 1 }], + "@stylistic/brace-style": ["error", "allman", { "allowSingleLine": false }], + "@stylistic/semi": ["error", "always"], + "@stylistic/quotes": ["error", "double", { "avoidEscape": true }], + "@stylistic/linebreak-style": ["error", "unix"], + "@stylistic/max-len": ["error", { + "code": 120, + "tabWidth": 4, + "ignoreComments": true, + "ignoreTrailingComments": true, + "ignoreUrls": true, + "ignoreStrings": true, + "ignoreTemplateLiterals": true, + "ignoreRegExpLiterals": true + }], + "@stylistic/multiline-ternary": ["error", "always-multiline"], + "@stylistic/no-extra-parens": ["error", "all"], + "@stylistic/new-parens": "error", + "@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 3 }], + "@stylistic/no-extra-semi": "error", + "@stylistic/no-floating-decimal": "error", + "@stylistic/no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }], + "@stylistic/switch-colon-spacing": "error", + "@stylistic/type-annotation-spacing": "error", + "@stylistic/type-generic-spacing": ["error"], + "@stylistic/type-named-tuple-spacing": ["error"], + "@stylistic/wrap-regex": "error", + "@stylistic/yield-star-spacing": ["error", "both"], + "import/order": ["error", { + "groups": ["builtin", "external", "internal", "parent", "sibling", "index"], + "pathGroups": [ + { + "pattern": "tsyringe", + "group": "builtin", + "position": "before" + } + ], + "newlines-between": "never", + "alphabetize": { + "order": "asc", + "caseInsensitive": true + } + }] + }, + "overrides": [ + { + "files": ["src/di/**/*.ts"], + "rules": { + "@typescript-eslint/no-extraneous-class": "off" + } + }, + { + "files": ["src/loaders/**/*.ts"], + "rules": { + "@typescript-eslint/no-var-requires": "off" + } + } + ] +} diff --git a/project/Server.code-workspace b/project/Server.code-workspace index 40e7e4f7..a47cd254 100644 --- a/project/Server.code-workspace +++ b/project/Server.code-workspace @@ -12,6 +12,6 @@ "source.fixAll.eslint": "explicit" }, "eslint.debug": true, - "eslint.experimental.useFlatConfig": true + "eslint.experimental.useFlatConfig": false } } diff --git a/project/eslint.config.mjs b/project/eslint.config.mjs deleted file mode 100644 index 537b7024..00000000 --- a/project/eslint.config.mjs +++ /dev/null @@ -1,81 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import tseslint from 'typescript-eslint'; -import stylistic from '@stylistic/eslint-plugin' - -export default tseslint.config( - ...tseslint.configs.strict, - ...tseslint.configs.stylistic, - { - plugins: { - '@stylistic': stylistic - }, - rules: { - "@typescript-eslint/no-explicit-any": 'off', - "@typescript-eslint/no-dynamic-delete": 'off', - "@typescript-eslint/no-unused-vars": 'off', - "@typescript-eslint/no-empty-interface": 'off', - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/explicit-module-boundary-types": ["error", { - "allowArgumentsExplicitlyTypedAsAny": true - }], - "@typescript-eslint/naming-convention": ["error", { - "selector": "default", - "format": ["camelCase"], - "leadingUnderscore": "allow" - }, { - "selector": "typeLike", - "format": ["PascalCase"] - }, { - "selector": "objectLiteralProperty", - "format": ["PascalCase", "camelCase", "snake_case"], - "leadingUnderscore": "allow" - }, { - "selector": "typeProperty", - "format": ["PascalCase", "camelCase"], - "leadingUnderscore": "allow" - }, { - "selector": "enumMember", - "format": ["UPPER_CASE"] - }, { - "selector": "property", - "modifiers": ["readonly", "static"], - "format": ["UPPER_CASE"] - }], - "@stylistic/indent": ["error", 4, { "MemberExpression": 1, "SwitchCase": 1 }], - "@stylistic/brace-style": ["error", "allman", { "allowSingleLine": false }], - "@stylistic/linebreak-style": ["error", "unix"], - "@stylistic/max-len": ["error", { - "code": 120, - "tabWidth": 4, - "ignoreComments": true, - "ignoreTrailingComments": true, - "ignoreUrls": true, - "ignoreStrings": true, - "ignoreTemplateLiterals": true, - "ignoreRegExpLiterals": true - }], - "@stylistic/multiline-ternary": ["error", "always-multiline"], - "@stylistic/new-parens": "error", - "@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 3 }], - "@stylistic/no-extra-semi": "error", - "@stylistic/no-floating-decimal": "error", - "@stylistic/no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }], - "@stylistic/switch-colon-spacing": "error", - "@stylistic/type-annotation-spacing": "error", - "@stylistic/type-generic-spacing": ["error"], - "@stylistic/type-named-tuple-spacing": ["error"], - "@stylistic/wrap-regex": "error", - "@stylistic/yield-star-spacing": ["error", "both"], - } - }, { - "files": ["src/di/**/*.ts"], - "rules": { - "@typescript-eslint/no-extraneous-class": 'off', - } - }, { - "files": ["src/loaders/**/*.ts"], - "rules": { - "@typescript-eslint/no-var-requires": "off" - } - } -); diff --git a/project/package.json b/project/package.json index a633029e..ac482b37 100644 --- a/project/package.json +++ b/project/package.json @@ -67,6 +67,8 @@ "@yao-pkg/pkg-fetch": "3.5.9", "cross-env": "~7.0", "eslint": "~8.57", + "eslint-import-resolver-typescript": "~3.6", + "eslint-plugin-import": "~2.29", "fs-extra": "~11.2", "gulp": "~4.0", "gulp-decompress": "~3.0",