Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ESLint new config system #1886

Merged
merged 35 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c55bd34
feat: support new config system
jjangga0214 Sep 10, 2022
27459a7
Update index.mjs
sindresorhus Sep 10, 2022
612da7d
Update recommended.mjs
sindresorhus Sep 10, 2022
580fa29
refactor: rm dup
jjangga0214 Sep 10, 2022
33f11c8
style: format
jjangga0214 Sep 11, 2022
dfd5159
feat: add languageOptions and files to the new config
jjangga0214 Sep 11, 2022
0084e5e
style: format
jjangga0214 Sep 11, 2022
ff1cacf
refactor: import dup
jjangga0214 Sep 13, 2022
8dff114
docs: guide the new config system
jjangga0214 Sep 13, 2022
5f4d2a0
docs: align a word
jjangga0214 Sep 13, 2022
9c9afff
fix: path to configs-legacy
jjangga0214 Sep 14, 2022
c7c4a94
docs: globals -> languageOptions.globals
jjangga0214 Sep 15, 2022
30a8bc0
Update readme.md
sindresorhus Sep 20, 2022
6a1659b
Update readme.md
sindresorhus Sep 20, 2022
dce48df
docs: fix style
jjangga0214 Sep 21, 2022
8d87f54
Merge branch 'main' into feat/new-config-system
jjangga0214 Sep 21, 2022
34a3ecc
Merge branch 'main' into feat/new-config-system
fisker Dec 20, 2023
4f92045
Switch back to commonjs
fisker Dec 20, 2023
6689394
Fix file name
fisker Dec 20, 2023
24093f2
Fix config
fisker Dec 20, 2023
c8180d4
Add test
fisker Dec 20, 2023
37b3aa1
Fix
fisker Dec 20, 2023
d35eb36
Update readme.md
fisker Dec 20, 2023
165e34d
Fix anchor
fisker Dec 20, 2023
3e46955
Fix linting
fisker Dec 20, 2023
0942d71
Linting
fisker Dec 20, 2023
4b3b487
Fix example
fisker Dec 20, 2023
b099569
Remove useless dependency
fisker Dec 20, 2023
3809656
Fix anchor
fisker Dec 20, 2023
8985321
Use auto generated anchor
fisker Dec 20, 2023
151b3fd
Move to `flat/*`
fisker Dec 20, 2023
dce3053
Fix create-rule.mjs
fisker Dec 20, 2023
2161a47
Open editor
fisker Dec 20, 2023
9452c7f
Update .eslint-doc-generatorrc.js
fisker Dec 20, 2023
3895cc7
Update package.json
sindresorhus Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
ignoreConfig: ['all'],
ignoreConfig: ['all', 'flat/all', 'flat/recommended'],
ignoreDeprecatedRules: true,
ruleDocTitleFormat: 'desc',
ruleListColumns: [
Expand Down
11 changes: 4 additions & 7 deletions configs/all.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';
const {rules, ...baseConfigs} = require('./recommended.js');
const recommended = require('./recommended.js');

module.exports = {
...baseConfigs,
rules: Object.fromEntries(Object.entries(rules).map(
([ruleId, severity]) => [ruleId, ruleId.startsWith('unicorn/') ? 'error' : severity],
)),
};
module.exports = Object.fromEntries(Object.entries(recommended).map(
([ruleId, severity]) => [ruleId, ruleId.startsWith('unicorn/') ? 'error' : severity],
));
20 changes: 20 additions & 0 deletions configs/flat-config-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const eslintrc = require('@eslint/eslintrc');
const legacyConfigBase = require('./legacy-config-base.js');

const {
parserOptions: {
ecmaVersion,
sourceType,
},
} = legacyConfigBase;

const {globals} = eslintrc.Legacy.environments.get('es2024');

module.exports = {
languageOptions: {
ecmaVersion,
sourceType,
globals,
},
};
10 changes: 10 additions & 0 deletions configs/legacy-config-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
module.exports = {
env: {
es2024: true,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
};
240 changes: 114 additions & 126 deletions configs/recommended.js
Original file line number Diff line number Diff line change
@@ -1,129 +1,117 @@
'use strict';
module.exports = {
env: {
es2024: true,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'unicorn',
],
rules: {
'unicorn/better-regex': 'error',
'unicorn/catch-error-name': 'error',
'unicorn/consistent-destructuring': 'error',
'unicorn/consistent-function-scoping': 'error',
'unicorn/custom-error-definition': 'off',
'unicorn/empty-brace-spaces': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/expiring-todo-comments': 'error',
'unicorn/explicit-length-check': 'error',
'unicorn/filename-case': 'error',
'unicorn/import-style': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/no-abusive-eslint-disable': 'error',
'unicorn/no-array-callback-reference': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-push-push': 'error',
'unicorn/no-array-reduce': 'error',
'unicorn/no-await-expression-member': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-document-cookie': 'error',
'unicorn/no-empty-file': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-keyword-prefix': 'off',
'unicorn/no-lonely-if': 'error',
'no-negated-condition': 'off',
'unicorn/no-negated-condition': 'error',
'no-nested-ternary': 'off',
'unicorn/no-nested-ternary': 'error',
'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-null': 'error',
'unicorn/no-object-as-default-parameter': 'error',
'unicorn/no-process-exit': 'error',
'unicorn/no-static-only-class': 'error',
'unicorn/no-thenable': 'error',
'unicorn/no-this-assignment': 'error',
'unicorn/no-typeof-undefined': 'error',
'unicorn/no-unnecessary-await': 'error',
'unicorn/no-unnecessary-polyfills': 'error',
'unicorn/no-unreadable-array-destructuring': 'error',
'unicorn/no-unreadable-iife': 'error',
'unicorn/no-unused-properties': 'off',
'unicorn/no-useless-fallback-in-spread': 'error',
'unicorn/no-useless-length-check': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-useless-spread': 'error',
'unicorn/no-useless-switch-case': 'error',
'unicorn/no-useless-undefined': 'error',
'unicorn/no-zero-fractions': 'error',
'unicorn/number-literal-case': 'error',
'unicorn/numeric-separators-style': 'error',
'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-event-target': 'error',
'unicorn/prefer-export-from': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-json-parse-buffer': 'off',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-logical-operator-over-ternary': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
'unicorn/prefer-module': 'error',
'unicorn/prefer-native-coercion-functions': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-object-from-entries': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
'unicorn/prefer-query-selector': 'error',
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-set-has': 'error',
'unicorn/prefer-set-size': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-switch': 'error',
'unicorn/prefer-ternary': 'error',
'unicorn/prefer-top-level-await': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/prevent-abbreviations': 'error',
'unicorn/relative-url-style': 'error',
'unicorn/require-array-join-separator': 'error',
'unicorn/require-number-to-fixed-digits-argument': 'error',
// Turned off because we can't distinguish `widow.postMessage` and `{Worker,MessagePort,Client,BroadcastChannel}#postMessage()`
// See #1396
'unicorn/require-post-message-target-origin': 'off',
'unicorn/string-content': 'off',
'unicorn/switch-case-braces': 'error',
'unicorn/template-indent': 'error',
'unicorn/text-encoding-identifier-case': 'error',
'unicorn/throw-new-error': 'error',
},
'unicorn/better-regex': 'error',
'unicorn/catch-error-name': 'error',
'unicorn/consistent-destructuring': 'error',
'unicorn/consistent-function-scoping': 'error',
'unicorn/custom-error-definition': 'off',
'unicorn/empty-brace-spaces': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/expiring-todo-comments': 'error',
'unicorn/explicit-length-check': 'error',
'unicorn/filename-case': 'error',
'unicorn/import-style': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/no-abusive-eslint-disable': 'error',
'unicorn/no-array-callback-reference': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-push-push': 'error',
'unicorn/no-array-reduce': 'error',
'unicorn/no-await-expression-member': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-document-cookie': 'error',
'unicorn/no-empty-file': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-keyword-prefix': 'off',
'unicorn/no-lonely-if': 'error',
'no-negated-condition': 'off',
'unicorn/no-negated-condition': 'error',
'no-nested-ternary': 'off',
'unicorn/no-nested-ternary': 'error',
'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-null': 'error',
'unicorn/no-object-as-default-parameter': 'error',
'unicorn/no-process-exit': 'error',
'unicorn/no-static-only-class': 'error',
'unicorn/no-thenable': 'error',
'unicorn/no-this-assignment': 'error',
'unicorn/no-typeof-undefined': 'error',
'unicorn/no-unnecessary-await': 'error',
'unicorn/no-unnecessary-polyfills': 'error',
'unicorn/no-unreadable-array-destructuring': 'error',
'unicorn/no-unreadable-iife': 'error',
'unicorn/no-unused-properties': 'off',
'unicorn/no-useless-fallback-in-spread': 'error',
'unicorn/no-useless-length-check': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-useless-spread': 'error',
'unicorn/no-useless-switch-case': 'error',
'unicorn/no-useless-undefined': 'error',
'unicorn/no-zero-fractions': 'error',
'unicorn/number-literal-case': 'error',
'unicorn/numeric-separators-style': 'error',
'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-event-target': 'error',
'unicorn/prefer-export-from': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-json-parse-buffer': 'off',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-logical-operator-over-ternary': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
'unicorn/prefer-module': 'error',
'unicorn/prefer-native-coercion-functions': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-object-from-entries': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
'unicorn/prefer-query-selector': 'error',
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-set-has': 'error',
'unicorn/prefer-set-size': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-switch': 'error',
'unicorn/prefer-ternary': 'error',
'unicorn/prefer-top-level-await': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/prevent-abbreviations': 'error',
'unicorn/relative-url-style': 'error',
'unicorn/require-array-join-separator': 'error',
'unicorn/require-number-to-fixed-digits-argument': 'error',
// Turned off because we can't distinguish `widow.postMessage` and `{Worker,MessagePort,Client,BroadcastChannel}#postMessage()`
// See #1396
'unicorn/require-post-message-target-origin': 'off',
'unicorn/string-content': 'off',
'unicorn/switch-case-braces': 'error',
'unicorn/template-indent': 'error',
'unicorn/text-encoding-identifier-case': 'error',
'unicorn/throw-new-error': 'error',
};
27 changes: 20 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';
const createDeprecatedRules = require('./rules/utils/create-deprecated-rules.js');
const {loadRules} = require('./rules/utils/rule.js');
const recommendedConfig = require('./configs/recommended.js');
const allRulesEnabledConfig = require('./configs/all.js');
const legacyConfigBase = require('./configs/legacy-config-base.js');
const flatConfigBase = require('./configs/flat-config-base.js');
const recommendedRules = require('./configs/recommended.js');
const allRules = require('./configs/all.js');
const {name, version} = require('./package.json');

const deprecatedRules = createDeprecatedRules({
Expand All @@ -26,7 +28,13 @@ const deprecatedRules = createDeprecatedRules({
'regex-shorthand': 'unicorn/better-regex',
});

module.exports = {
const createConfig = (rules, isLegacyConfig = false) => ({
...(isLegacyConfig ? legacyConfigBase : flatConfigBase),
plugins: isLegacyConfig ? ['unicorn'] : {unicorn},
rules,
});

const unicorn = {
meta: {
name,
version,
Expand All @@ -35,8 +43,13 @@ module.exports = {
...loadRules(),
...deprecatedRules,
},
configs: {
recommended: recommendedConfig,
all: allRulesEnabledConfig,
},
};

const configs = {
recommended: createConfig(recommendedRules, /* isLegacyConfig */ true),
all: createConfig(allRules, /* isLegacyConfig */ true),
'flat/recommended': createConfig(recommendedRules),
'flat/all': createConfig(allRules),
};

module.exports = {...unicorn, configs};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"main": "index.js",
"engines": {
"node": ">=16"
},
Expand All @@ -18,12 +19,12 @@
"fix": "run-p --continue-on-error fix:*",
"fix:eslint-docs": "eslint-doc-generator",
"fix:js": "npm run lint:js -- --fix",
"fix:md": "npm run lint:md -- --fix",
"fix:markdown": "npm run lint:markdown -- --fix",
"integration": "node ./test/integration/test.mjs",
"lint": "run-p --continue-on-error lint:*",
"lint:eslint-docs": "npm run fix:eslint-docs -- --check",
"lint:js": "xo",
"lint:md": "markdownlint \"**/*.md\"",
"lint:markdown": "markdownlint \"**/*.md\"",
"lint:package-json": "npmPkgJsonLint .",
"run-rules-on-codebase": "node ./test/run-rules-on-codebase/lint.mjs",
"bundle-lodash": "echo \"export {defaultsDeep, camelCase, kebabCase, snakeCase, upperFirst, lowerFirst} from 'lodash-es';\" | npx esbuild --bundle --outfile=rules/utils/lodash.js --format=cjs",
Expand All @@ -49,6 +50,7 @@
"dependencies": {
"@babel/helper-validator-identifier": "^7.22.20",
"@eslint-community/eslint-utils": "^4.4.0",
"@eslint/eslintrc": "^2.1.4",
"ci-info": "^4.0.0",
"clean-regexp": "^1.0.0",
"core-js-compat": "^3.34.0",
Expand Down
Loading