From 98d24857db4f431a545032b4cebf743ef0c6117f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0ilhan?= Date: Fri, 1 Jul 2022 10:42:15 +0200 Subject: [PATCH] misc: Add missing eslint rules. (#33) --- .eslintignore | 2 -- .eslintrc.js | 2 +- dangerfile.js | 2 +- package.json | 2 +- packages/eslint-config/README.md | 4 ++-- packages/eslint-config/src/esnext.ts | 1 + packages/eslint-config/src/future.ts | 1 - .../src/presets/{future.ts => esnext.ts} | 4 ++-- packages/eslint-config/src/rules/base.ts | 4 +--- .../src/rules/{future.ts => esnext.ts} | 14 ++++++++++---- packages/eslint-config/tools/check-rules/index.ts | 6 +++--- 11 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 packages/eslint-config/src/esnext.ts delete mode 100644 packages/eslint-config/src/future.ts rename packages/eslint-config/src/presets/{future.ts => esnext.ts} (60%) rename packages/eslint-config/src/rules/{future.ts => esnext.ts} (92%) diff --git a/.eslintignore b/.eslintignore index 8f0c7fe9..0040d6ea 100644 --- a/.eslintignore +++ b/.eslintignore @@ -8,8 +8,6 @@ lib/ tmp/ dist/ build/ -jest.config.js -babel.config.js webpack.config.js build*/ \.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 73249f25..36f57cb6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,6 @@ module.exports = { root: true, - extends: ['rajzik', 'rajzik/node', 'rajzik/typescript', 'rajzik/future', 'rajzik/prettier'], + extends: ['rajzik', 'rajzik/node', 'rajzik/esnext', 'rajzik/typescript', 'rajzik/prettier'], env: { node: true, }, diff --git a/dangerfile.js b/dangerfile.js index d8e684a1..16f685c3 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,4 +1,4 @@ -/* eslint-disable import/extensions, unicorn/import-index */ +/* eslint-disable import/extensions */ const { checkForInvalidLocks, checkForConventionalPrefix, diff --git a/package.json b/package.json index 9faa8534..67f23144 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "clean": "rimraf packages/*/{lib,dts,*.tsbuildinfo,node_modules}", "format-package-json": "syncpack format", "jest": "jest", - "lint": "eslint --cache --fix packages/*/{src,test}/**/*.{ts,tsx}", + "lint": "eslint --cache --fix packages/*/{src,test}/**/*.{ts,tsx} *.{js,jsx,ts,tsx}", "pack": "cross-env NODE_ENV=production packemon pack --addEngines --addExports --declaration", "postinstall": "husky install", "prepare": "yarn build && husky install", diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md index a37dc5b3..7bd4110c 100644 --- a/packages/eslint-config/README.md +++ b/packages/eslint-config/README.md @@ -20,7 +20,7 @@ module.exports = { 'rajzik', 'rajzik/node', 'rajzik/react', - 'rajzik/future', + 'rajzik/esnext', 'rajzik/typescript', 'rajzik/prettier', ], @@ -35,7 +35,7 @@ module.exports = { - Enable rules for react - node - Enable rules for node -- future +- esnext - Enable esnext support - typescript - Enable support for typescript diff --git a/packages/eslint-config/src/esnext.ts b/packages/eslint-config/src/esnext.ts new file mode 100644 index 00000000..4eaa61e7 --- /dev/null +++ b/packages/eslint-config/src/esnext.ts @@ -0,0 +1 @@ +export { default } from './presets/esnext'; diff --git a/packages/eslint-config/src/future.ts b/packages/eslint-config/src/future.ts deleted file mode 100644 index 289e35b9..00000000 --- a/packages/eslint-config/src/future.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './presets/future'; diff --git a/packages/eslint-config/src/presets/future.ts b/packages/eslint-config/src/presets/esnext.ts similarity index 60% rename from packages/eslint-config/src/presets/future.ts rename to packages/eslint-config/src/presets/esnext.ts index 716e4950..0ea5de95 100644 --- a/packages/eslint-config/src/presets/future.ts +++ b/packages/eslint-config/src/presets/esnext.ts @@ -1,9 +1,9 @@ -import futureRules from '../rules/future'; +import unicornRules from '../rules/esnext'; import type eslint from 'eslint'; const config: eslint.Linter.Config = { - rules: futureRules, + rules: unicornRules, }; export default config; diff --git a/packages/eslint-config/src/rules/base.ts b/packages/eslint-config/src/rules/base.ts index 2fc17a4c..01b0ec35 100644 --- a/packages/eslint-config/src/rules/base.ts +++ b/packages/eslint-config/src/rules/base.ts @@ -420,8 +420,7 @@ const importRules: eslint.Linter.Config['rules'] = { 'import/group-exports': 'off', // prefer named exports to be grouped together in a single export declaration 'import/max-dependencies': 'off', // limit the maximum number of dependencies a module can have 'import/no-internal-modules': 'off', // prevent importing the submodules of other modules - /* TODO [enable this when https://github.com/benmosher/eslint-plugin-import/issues/1998 is fixed]: 'import/named': 'error', // ensure named imports correspond to a named export in the remote file */ - 'import/named': 'off', // ensure named imports correspond to a named export in the remote file + 'import/named': 'error', // ensure named imports correspond to a named export in the remote file 'import/namespace': 'off', // ensure imported namespaces contain dereferenced properties as they are dereferenced 'import/newline-after-import': 'warn', // enforce a newline after import statements 'import/no-absolute-path': 'error', // forbid import of modules using absolute paths @@ -492,7 +491,6 @@ const unicornRules: eslint.Linter.Config['rules'] = { 'unicorn/escape-case': 'warn', // require escape sequences to use uppercase values 'unicorn/explicit-length-check': 'off', // enforce explicitly comparing the length property of a value 'unicorn/filename-case': 'off', // enforce a case style for filenames - 'unicorn/import-index': 'error', // enforce importing index files with . 'unicorn/import-style': 'warn', // enforce specific import styles per module 'unicorn/new-for-builtins': 'warn', // enforce the use of new for all builtins, except String, Number, Boolean, Symbol and BigInt 'unicorn/no-abusive-eslint-disable': 'error', // enforce specifying rules to disable in eslint-disable comments diff --git a/packages/eslint-config/src/rules/future.ts b/packages/eslint-config/src/rules/esnext.ts similarity index 92% rename from packages/eslint-config/src/rules/future.ts rename to packages/eslint-config/src/rules/esnext.ts index b336294e..2b63d6f9 100644 --- a/packages/eslint-config/src/rules/future.ts +++ b/packages/eslint-config/src/rules/esnext.ts @@ -1,6 +1,6 @@ import type eslint from 'eslint'; -const futureRules: eslint.Linter.Config['rules'] = { +const unicornRules: eslint.Linter.Config['rules'] = { // eslint-plugin-unicorn rules 'unicorn/no-array-for-each': 'off', // prefer for…of over Array#forEach(…) 'unicorn/no-array-method-this-argument': 'error', // disallow using the this argument in array methods @@ -42,13 +42,14 @@ const futureRules: eslint.Linter.Config['rules'] = { 'unicorn/prefer-dom-node-dataset': 'warn', // prefer using .dataset on DOM elements over .setAttribute(…) 'unicorn/prefer-dom-node-remove': 'warn', // prefer childNode.remove() over parentNode.removeChild(childNode) 'unicorn/prefer-dom-node-text-content': 'warn', // prefer .textContent over .innerText + 'unicorn/prefer-event-target': 'error', // Prefer EventTarget over EventEmitter 'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }], // prefer export…from when re-exporting 'unicorn/prefer-includes': 'warn', // prefer .includes() over .indexOf() when checking for existence or non-existence 'unicorn/prefer-json-parse-buffer': 'off', // prefer reading a JSON file as a buffer 'unicorn/prefer-keyboard-event-key': 'warn', // prefer KeyboardEvent#key over KeyboardEvent#keyCode 'unicorn/prefer-math-trunc': 'warn', // enforce the use of Math.trunc instead of bitwise operators - 'unicorn/prefer-modern-dom-apis': 'error', - 'unicorn/prefer-modern-math-apis': 'error', + 'unicorn/prefer-modern-dom-apis': 'error', // Prefer .before() over .insertBefore(), .replaceWith() over .replaceChild(), prefer one of .before(), .after(), .append() or .prepend() over insertAdjacentText() and insertAdjacentElement() + 'unicorn/prefer-modern-math-apis': 'error', // Prefer modern Math APIs over legacy patterns // FIXME [@rajzik]: This is good rule but adoption isn't great so far 'unicorn/prefer-module': 'off', // Prefer JavaScript modules (ESM) over CommonJS 'unicorn/prefer-node-protocol': 'warn', // Prefer using the `node:` protocol when importing Node.js builtin modules @@ -60,6 +61,7 @@ const futureRules: eslint.Linter.Config['rules'] = { 'unicorn/prefer-query-selector': 'off', // prefer .querySelector() over .getElementById(), .querySelectorAll() over .getElementsByClassName() and .getElementsByTagName() 'unicorn/prefer-reflect-apply': 'off', // prefer Reflect.apply() over Function#apply() 'unicorn/prefer-regexp-test': 'warn', // prefer RegExp#test() over String#match() and RegExp#exec() + 'unicorn/prefer-logical-operator-over-ternary': 'error', // Prefer using a logical operator over a ternary 'unicorn/prefer-set-has': 'warn', // prefer Set#has() over Array#includes() when checking for existence or non-existence 'unicorn/prefer-spread': 'error', // prefer the spread operator over Array.from() 'unicorn/prefer-string-replace-all': 'warn', // prefer String#replaceAll() over regex searches with the global flag @@ -81,4 +83,8 @@ const futureRules: eslint.Linter.Config['rules'] = { 'unicorn/throw-new-error': 'error', // require new when throwing an error }; -export default futureRules; +const config = { + ...unicornRules, +}; + +export default config; diff --git a/packages/eslint-config/tools/check-rules/index.ts b/packages/eslint-config/tools/check-rules/index.ts index ae991578..3ccb3fe1 100644 --- a/packages/eslint-config/tools/check-rules/index.ts +++ b/packages/eslint-config/tools/check-rules/index.ts @@ -5,7 +5,7 @@ import nodeRulesConfig from '../../src/rules/node'; import baseRulesConfig from '../../src/rules/base'; import reactRulesConfig from '../../src/rules/react'; import typescriptRulesPreset from '../../src/presets/typescript'; -import unicornPreset from '../../src/presets/future'; +import esnextPreset from '../../src/presets/esnext'; import prettierConfig from '../../src/presets/prettier'; @@ -18,7 +18,7 @@ const reactRules = Object.entries(reactRulesConfig!).map(([ruleName]) => ruleNam const typescriptRules = Object.entries(typescriptRulesPreset!.overrides![0]!.rules!).map( ([ruleName]) => ruleName, ); -const unicornRules = Object.entries(unicornPreset.rules!).map(([ruleName]) => ruleName); +const esnextRules = Object.entries(esnextPreset.rules!).map(([ruleName]) => ruleName); const usedRules = [ ...jestRules, @@ -27,7 +27,7 @@ const usedRules = [ ...baseRules, ...reactRules, ...typescriptRules, - ...unicornRules, + ...esnextRules, ].sort(); const missingRules: string[] = [];