From 9c9fd08f05dff5878d681bf687d0087afe102ce3 Mon Sep 17 00:00:00 2001 From: Patrick Taylor Date: Fri, 2 Aug 2024 16:25:10 +0100 Subject: [PATCH] =?UTF-8?q?Configured=20`eslint-plugin-n`=20=F0=9F=A4=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO | 14 ++++--- config/eslint/build-flat-config.ts | 2 + config/eslint/build-legacy-config.ts | 2 + config/eslint/constants.ts | 12 +++--- config/eslint/plugins.ts | 2 + config/eslint/rules/index.ts | 2 + config/eslint/rules/n.ts | 42 +++++++++++++++++++ package.json | 2 + yarn.lock | 63 ++++++++++++++++++++++++++-- 9 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 config/eslint/rules/n.ts diff --git a/TODO b/TODO index 6599a11..f4c400b 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,8 @@ # TODO -## ESLint Plugins +## ESLint Rules -- [ ] [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) +- [ ] [eslint](https://github.com/eslint/eslint/tree/main) - [x] [eslint-plugin-eslint-comments](https://github.com/mysticatea/eslint-plugin-eslint-comments) - [ ] [eslint-plugin-graphql](https://github.com/apollographql/eslint-plugin-graphql) - [ ] [eslint-plugin-i18next](https://github.com/edvardchen/eslint-plugin-i18next) @@ -10,9 +10,8 @@ - [x] [eslint-plugin-inclusive-language](https://github.com/muenzpraeger/eslint-plugin-inclusive-language) - [x] [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) - [x] [eslint-plugin-jest-formatting](https://github.com/dangreenisrael/eslint-plugin-jest-formatting) -- [ ] [eslint-plugin-json](https://github.com/azeemba/eslint-plugin-json) - [ ] [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y) -- [ ] [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node) +- [x] [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) - [x] [eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise) - [ ] [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) - [ ] [eslint-plugin-security](https://github.com/eslint-community/eslint-plugin-security) @@ -23,7 +22,12 @@ - [ ] [eslint-stylistic](https://github.com/eslint-stylistic/eslint-stylistic) - [ ] [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) -## Stylelint Plugins +### Other interesting plugins + +- [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) +- [eslint-plugin-json](https://github.com/azeemba/eslint-plugin-json) + +## Stylelint Rules - [ ] stylelint-config-property-sort-order-smacss - [ ] stylelint-config-standard-scss diff --git a/config/eslint/build-flat-config.ts b/config/eslint/build-flat-config.ts index 4304ba5..2a3fdde 100644 --- a/config/eslint/build-flat-config.ts +++ b/config/eslint/build-flat-config.ts @@ -6,6 +6,7 @@ const buildFlatConfig = () => ([{ plugins: { 'eslint-comments': Plugins.EslintComments, 'inclusive-language': Plugins.InclusiveLanguage, + 'n': Plugins.N, 'promise': Plugins.Promise, 'sort-destructure-keys': Plugins.SortDestructureKeys, 'sort-exports': Plugins.SortExports, @@ -13,6 +14,7 @@ const buildFlatConfig = () => ([{ rules: { ...Rules.ESLintComments, ...Rules.InclusiveLanguage, + ...Rules.N, ...Rules.Promise, ...Rules.SortDestructureKeys, ...Rules.SortExports, diff --git a/config/eslint/build-legacy-config.ts b/config/eslint/build-legacy-config.ts index 82b794d..b8cc27d 100644 --- a/config/eslint/build-legacy-config.ts +++ b/config/eslint/build-legacy-config.ts @@ -8,6 +8,7 @@ const buildLegacyConfig = () => ({ plugins: [ 'eslint-comments', 'inclusive-language', + 'n', 'promise', 'sort-destructure-keys', 'sort-exports', @@ -15,6 +16,7 @@ const buildLegacyConfig = () => ({ rules: { ...Rules.ESLintComments, ...Rules.InclusiveLanguage, + ...Rules.N, ...Rules.Promise, ...Rules.SortDestructureKeys, ...Rules.SortExports, diff --git a/config/eslint/constants.ts b/config/eslint/constants.ts index 9477531..964fb96 100644 --- a/config/eslint/constants.ts +++ b/config/eslint/constants.ts @@ -1,13 +1,13 @@ const FILE_PATHS = { TESTS: [ - '*.spec.*', - '*.test.*', + '**/*.spec.*', + '**/*.test.*', ], TESTS_TYPESCRIPT: [ - '*.spec.ts', - '*.spec.tsx', - '*.test.ts', - '*.test.tsx', + '**/*.spec.ts', + '**/*.spec.tsx', + '**/*.test.ts', + '**/*.test.tsx', ] } diff --git a/config/eslint/plugins.ts b/config/eslint/plugins.ts index 5d1093a..80fca93 100644 --- a/config/eslint/plugins.ts +++ b/config/eslint/plugins.ts @@ -5,6 +5,7 @@ import InclusiveLanguage from 'eslint-plugin-inclusive-language' import Jest from 'eslint-plugin-jest' import JestFormatting from 'eslint-plugin-jest-formatting' import Promise from 'eslint-plugin-promise' +import N from 'eslint-plugin-n' import SortDestructureKeys from 'eslint-plugin-sort-destructure-keys' import SortExports from 'eslint-plugin-sort-exports' @@ -13,6 +14,7 @@ const Plugins = { InclusiveLanguage, Jest, JestFormatting, + N, Promise, SortDestructureKeys, SortExports, diff --git a/config/eslint/rules/index.ts b/config/eslint/rules/index.ts index 19135d5..adf9867 100644 --- a/config/eslint/rules/index.ts +++ b/config/eslint/rules/index.ts @@ -2,6 +2,7 @@ import ESLintComments from './eslint-comments' import InclusiveLanguage from './inclusive-language' import { Jest, JestTypescript } from './jest' import JestFormatting from './jest-formatting' +import N from './n' import Promise from './promise' import SortDestructureKeys from './sort-destructure-keys' import SortExports from './sort-exports' @@ -12,6 +13,7 @@ const Rules = { Jest, JestFormatting, JestTypescript, + N, Promise, SortDestructureKeys, SortExports, diff --git a/config/eslint/rules/n.ts b/config/eslint/rules/n.ts new file mode 100644 index 0000000..56d99e4 --- /dev/null +++ b/config/eslint/rules/n.ts @@ -0,0 +1,42 @@ +// https://github.com/eslint-community/eslint-plugin-n + +export default { + 'callback-return': 1, + 'exports-style': 0, + 'file-extension-in-import': 0, + 'global-require': 0, + 'handle-callback-err': 0, + 'hashbang': 2, + 'no-callback-literal': 0, + 'no-deprecated-api': 2, + 'no-exports-assign': 2, + 'no-extraneous-import': 0, + 'no-extraneous-require': 0, + 'no-missing-import': 0, + 'no-missing-require': 0, + 'no-mixed-requires': [2, { allowCall: true, grouping: true }], + 'no-new-require': 2, + 'no-path-concat': 2, + 'no-process-env': 0, + 'no-process-exit': 0, // TODO: Revisit this rule + 'no-restricted-import': 0, + 'no-restricted-require': 0, + 'no-sync': 0, + 'no-unpublished-bin': 2, + 'no-unpublished-import': 0, + 'no-unpublished-require': 0, + 'no-unsupported-features/es-builtins': 2, + 'no-unsupported-features/es-syntax': 2, + 'no-unsupported-features/node-builtins': 2, + 'prefer-global/buffer': 2, + 'prefer-global/console': 2, + 'prefer-global/process': 2, + 'prefer-global/text-decoder': 2, + 'prefer-global/text-encoder': 2, + 'prefer-global/url': 2, + 'prefer-global/url-search-params': 2, + 'prefer-node-protocol': 2, + 'prefer-promises/dns': 2, + 'prefer-promises/fs': 2, + 'process-exit-as-throw': 0, +} diff --git a/package.json b/package.json index 3b7f91a..73add78 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "eslint-plugin-inclusive-language": "2.2.1", "eslint-plugin-jest": "28.6.0", "eslint-plugin-jest-formatting": "3.1.0", + "eslint-plugin-n": "17.10.1", "eslint-plugin-promise": "6.4.0", "eslint-plugin-sort-destructure-keys": "2.0.0", "eslint-plugin-sort-exports": "0.9.1", @@ -69,6 +70,7 @@ "eslint-plugin-inclusive-language", "eslint-plugin-jest", "eslint-plugin-jest-formatting", + "eslint-plugin-n", "eslint-plugin-promise", "eslint-plugin-sort-destructure-keys", "eslint-plugin-sort-exports", diff --git a/yarn.lock b/yarn.lock index fc943d4..6cbf1ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1173,7 +1173,7 @@ resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz#acad351d582d157bb145535db2a6ff53dd514b5c" integrity sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw== -"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": +"@eslint-community/eslint-utils@^4.1.2", "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" integrity sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA== @@ -2427,6 +2427,14 @@ emoji-regex@^9.2.2: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72" integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg== +enhanced-resolve@^5.17.0: + version "5.17.1" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz#67bfbbcc2f81d511be77d686a90267ef7f898a15" + integrity sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg== + dependencies: + graceful-fs "^4.2.4" + tapable "^2.2.0" + entities@^4.4.0: version "4.5.0" resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48" @@ -2498,6 +2506,22 @@ escape-string-regexp@^4.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== +eslint-compat-utils@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/eslint-compat-utils/-/eslint-compat-utils-0.5.1.tgz#7fc92b776d185a70c4070d03fd26fde3d59652e4" + integrity sha512-3z3vFexKIEnjHE3zCMRo6fn/e44U7T1khUjg+Hp0ZQMCigh28rALD0nPFBcGZuiLC5rLZa2ubQHDRln09JfU2Q== + dependencies: + semver "^7.5.4" + +eslint-plugin-es-x@^7.5.0: + version "7.8.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-es-x/-/eslint-plugin-es-x-7.8.0.tgz#a207aa08da37a7923f2a9599e6d3eb73f3f92b74" + integrity sha512-7Ds8+wAAoV3T+LAKeu39Y5BzXCrGKrcISfgKEqTS4BDN8SFEDQd0S43jiQ8vIa3wUKD07qitZdfzlenSi8/0qQ== + dependencies: + "@eslint-community/eslint-utils" "^4.1.2" + "@eslint-community/regexpp" "^4.11.0" + eslint-compat-utils "^0.5.1" + eslint-plugin-eslint-comments@3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-comments/-/eslint-plugin-eslint-comments-3.2.0.tgz#9e1cd7b4413526abb313933071d7aba05ca12ffa" @@ -2525,6 +2549,20 @@ eslint-plugin-jest@28.6.0: dependencies: "@typescript-eslint/utils" "^6.0.0 || ^7.0.0" +eslint-plugin-n@17.10.1: + version "17.10.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-n/-/eslint-plugin-n-17.10.1.tgz#da2a3fd1a41c9d901bbc06b8c4d4d5916e012913" + integrity sha512-hm/q37W6efDptJXdwirsm6A257iY6ZNtpoSG0wEzFzjJ3AhL7OhEIhdSR2e4OdYfHO5EDeqlCfFrjf9q208IPw== + dependencies: + "@eslint-community/eslint-utils" "^4.4.0" + enhanced-resolve "^5.17.0" + eslint-plugin-es-x "^7.5.0" + get-tsconfig "^4.7.0" + globals "^15.8.0" + ignore "^5.2.4" + minimatch "^9.0.5" + semver "^7.5.3" + eslint-plugin-promise@6.4.0: version "6.4.0" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-6.4.0.tgz#54926d53c79541efe9cea6ac1d823a58bbed1106" @@ -2831,6 +2869,13 @@ get-stream@^6.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== +get-tsconfig@^4.7.0: + version "4.7.6" + resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.7.6.tgz#118fd5b7b9bae234cc7705a00cd771d7eb65d62a" + integrity sha512-ZAqrLlu18NbDdRaHq+AKXzAmqIUPswPWKUchfytdAjiRFnCe5ojG2bstg6mRiZabkKfCoL/e98pbBELIV/YCeA== + dependencies: + resolve-pkg-maps "^1.0.0" + get-tsconfig@^4.7.5: version "4.7.5" resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.7.5.tgz#5e012498579e9a6947511ed0cd403272c7acbbaf" @@ -2901,6 +2946,11 @@ globals@^14.0.0: resolved "https://registry.yarnpkg.com/globals/-/globals-14.0.0.tgz#898d7413c29babcf6bafe56fcadded858ada724e" integrity sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ== +globals@^15.8.0: + version "15.9.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-15.9.0.tgz#e9de01771091ffbc37db5714dab484f9f69ff399" + integrity sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA== + globby@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" @@ -2918,7 +2968,7 @@ globjoin@^0.1.4: resolved "https://registry.yarnpkg.com/globjoin/-/globjoin-0.1.4.tgz#2f4494ac8919e3767c5cbb691e9f463324285d43" integrity sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg== -graceful-fs@^4.2.9: +graceful-fs@^4.2.4, graceful-fs@^4.2.9: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -2965,7 +3015,7 @@ humps@^2.0.1: resolved "https://registry.yarnpkg.com/humps/-/humps-2.0.1.tgz#dd02ea6081bd0568dc5d073184463957ba9ef9aa" integrity sha512-E0eIbrFWUhwfXJmsbdjRQFQPrl5pTEoKlz163j1mTqqUnU9PgR4AgB8AIITzuB3vLBdxZXyZ9TDIrwB2OASz4g== -ignore@^5.0.5, ignore@^5.2.0, ignore@^5.3.1: +ignore@^5.0.5, ignore@^5.2.0, ignore@^5.2.4, ignore@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef" integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw== @@ -3843,7 +3893,7 @@ minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" -minimatch@^9.0.3: +minimatch@^9.0.3, minimatch@^9.0.5: version "9.0.5" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5" integrity sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow== @@ -4567,6 +4617,11 @@ table@^6.8.2: string-width "^4.2.3" strip-ansi "^6.0.1" +tapable@^2.2.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" + integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== + terser@^5.0.0: version "5.31.1" resolved "https://registry.yarnpkg.com/terser/-/terser-5.31.1.tgz#735de3c987dd671e95190e6b98cfe2f07f3cf0d4"