Skip to content

Commit 4d24935

Browse files
committed
chore: migrate to eslint.config.js
1 parent fd1c227 commit 4d24935

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

.eslint-doc-generatorrc.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
'use strict';
2+
13
/** @type {import('eslint-doc-generator').GenerateOptions} */
24
module.exports = {
3-
ignoreConfig: ['all', 'rules', 'rules-recommended', 'tests', 'tests-recommended'],
5+
ignoreConfig: [
6+
'all',
7+
'rules',
8+
'rules-recommended',
9+
'tests',
10+
'tests-recommended',
11+
],
412
ruleDocSectionInclude: ['Rule Details'],
513
ruleListSplit: 'meta.docs.category',
6-
urlConfigs: 'https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets',
14+
urlConfigs:
15+
'https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets',
716
};

eslint.config.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict';
2+
3+
/*
4+
* IMPORTANT!
5+
*
6+
* Any changes made to this file must also be made to .eslintrc.js.
7+
*
8+
* Internally, ESLint is using the eslint.config.js file to lint itself.
9+
* The .eslintrc.js file is needed too, because:
10+
*
11+
* 1. There are tests that expect .eslintrc.js to be present to actually run.
12+
* 2. ESLint VS Code extension expects eslintrc config files to be
13+
* present to work correctly.
14+
*
15+
* Once we no longer need to support both eslintrc and flat config, we will
16+
* remove .eslintrc.js.
17+
*/
18+
const js = require('@eslint/js');
19+
const { FlatCompat } = require('@eslint/eslintrc');
20+
const globals = require('globals');
21+
const markdown = require('eslint-plugin-markdown');
22+
const eslintPlugin = require('eslint-plugin-eslint-plugin');
23+
24+
const compat = new FlatCompat({
25+
baseDirectory: __dirname,
26+
recommendedConfig: js.configs.recommended,
27+
});
28+
29+
module.exports = [
30+
...compat.extends(
31+
'not-an-aardvark/node',
32+
'plugin:eslint-comments/recommended',
33+
'plugin:node/recommended',
34+
'plugin:prettier/recommended',
35+
'plugin:unicorn/recommended'
36+
),
37+
{
38+
languageOptions: { sourceType: 'commonjs' },
39+
rules: {
40+
'comma-dangle': [
41+
'error',
42+
{
43+
arrays: 'always-multiline',
44+
objects: 'always-multiline',
45+
functions: 'never', // disallow trailing commas in function(es2017)
46+
},
47+
],
48+
'require-jsdoc': 'error',
49+
50+
'eslint-comments/no-unused-disable': 'error',
51+
'eslint-comments/require-description': 'error',
52+
53+
'unicorn/consistent-function-scoping': 'off',
54+
'unicorn/no-array-callback-reference': 'off',
55+
'unicorn/no-array-for-each': 'off',
56+
'unicorn/no-array-reduce': 'off',
57+
'unicorn/no-null': 'off',
58+
'unicorn/prefer-module': 'off',
59+
'unicorn/prefer-node-protocol': 'off', // TODO: enable once we drop support for Node 14.17.
60+
'unicorn/prevent-abbreviations': 'off',
61+
},
62+
},
63+
{
64+
// Apply eslint-plugin rules to our own rules/tests (but not docs).
65+
files: ['lib/**/*.js', 'tests/**/*.js'],
66+
plugins: { 'eslint-plugin': eslintPlugin },
67+
...eslintPlugin.configs.recommended,
68+
rules: {
69+
'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'],
70+
'eslint-plugin/require-meta-docs-url': [
71+
'error',
72+
{
73+
pattern:
74+
'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/{{name}}.md',
75+
},
76+
],
77+
},
78+
},
79+
{
80+
files: ['tests/**/*.js'],
81+
languageOptions: { globals: globals.mocha },
82+
},
83+
{
84+
files: ['**/*.md'],
85+
processor: 'markdown/markdown',
86+
},
87+
{
88+
// Markdown JS code samples in documentation:
89+
files: ['**/*.md/*.js'],
90+
plugins: { markdown },
91+
linterOptions: { noInlineConfig: true },
92+
rules: {
93+
'no-undef': 'off',
94+
'no-unused-vars': 'off',
95+
strict: 'off',
96+
97+
'eslint-comments/require-description': 'off',
98+
99+
'unicorn/filename-case': 'off',
100+
},
101+
},
102+
];

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports.configs = Object.keys(configFilters).reduce(
4747
(configs, configName) => {
4848
return Object.assign(configs, {
4949
[configName]: {
50-
plugins: ['eslint-plugin'],
50+
// plugins: ['eslint-plugin'],
5151
rules: Object.fromEntries(
5252
Object.keys(allRules)
5353
.filter((ruleName) => configFilters[configName](allRules[ruleName]))

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"devDependencies": {
5151
"@commitlint/cli": "^17.1.2",
5252
"@commitlint/config-conventional": "^17.1.0",
53+
"@eslint/eslintrc": "^2.0.2",
54+
"@eslint/js": "^8.37.0",
5355
"@release-it/conventional-changelog": "^4.3.0",
5456
"@typescript-eslint/parser": "^5.36.2",
5557
"chai": "^4.3.6",
@@ -67,6 +69,7 @@
6769
"eslint-remote-tester": "^3.0.0",
6870
"eslint-scope": "^7.1.1",
6971
"espree": "^9.4.0",
72+
"globals": "^13.20.0",
7073
"husky": "^8.0.1",
7174
"lodash": "^4.17.21",
7275
"markdownlint-cli": "^0.33.0",

0 commit comments

Comments
 (0)