Skip to content

Commit 6f6b1f4

Browse files
authored
feat: support eslint.config.js (#347)
1 parent a3d8898 commit 6f6b1f4

12 files changed

+205
-82
lines changed

Diff for: .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
};

Diff for: .eslintrc.js

-79
This file was deleted.

Diff for: README.md

+17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Here's an example ESLint configuration that:
3838
* Enables the `recommended` configuration
3939
* Enables an optional/non-recommended rule
4040

41+
### <a name='eslintrc'></a>**[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)**
42+
4143
```json
4244
{
4345
"parserOptions": {
@@ -52,6 +54,21 @@ Here's an example ESLint configuration that:
5254
}
5355
```
5456

57+
### <a name='flat'></a>[`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0)
58+
59+
```js
60+
const eslintPluginRecommended = require("eslint-plugin-eslint-plugin/configs/recommended");
61+
module.exports = [
62+
eslintPluginRecommended,
63+
{
64+
languageOptions: {sourceType: "commonjs"},
65+
rules: {
66+
"eslint-plugin/require-meta-docs-description": "error",
67+
},
68+
},
69+
];
70+
```
71+
5572
## <a name='Rules'></a>Rules
5673

5774
<!-- begin auto-generated rules list -->

Diff for: configs/all.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @fileoverview the `all` config for `eslint.config.js`
3+
* @author 唯然<[email protected]>
4+
*/
5+
6+
'use strict';
7+
8+
const mod = require('../lib/index.js');
9+
10+
module.exports = {
11+
plugins: { 'eslint-plugin': mod },
12+
rules: mod.configs.all.rules,
13+
};

Diff for: configs/recommended.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @fileoverview the `recommended` config for `eslint.config.js`
3+
* @author 唯然<[email protected]>
4+
*/
5+
6+
'use strict';
7+
8+
const mod = require('../lib/index.js');
9+
10+
module.exports = {
11+
plugins: { 'eslint-plugin': mod },
12+
rules: mod.configs.recommended.rules,
13+
};

Diff for: configs/rules-recommended.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @fileoverview the `rules-recommended` config for `eslint.config.js`
3+
* @author 唯然<[email protected]>
4+
*/
5+
6+
'use strict';
7+
8+
const mod = require('../lib/index.js');
9+
10+
module.exports = {
11+
plugins: { 'eslint-plugin': mod },
12+
rules: mod.configs['rules-recommended'].rules,
13+
};

Diff for: configs/rules.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @fileoverview the `rules` config for `eslint.config.js`
3+
* @author 唯然<[email protected]>
4+
*/
5+
6+
'use strict';
7+
8+
const mod = require('../lib/index.js');
9+
10+
module.exports = {
11+
plugins: { 'eslint-plugin': mod },
12+
rules: mod.configs.rules.rules,
13+
};

Diff for: configs/tests-recommended.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @fileoverview the `tests-recommended` config for `eslint.config.js`
3+
* @author 唯然<[email protected]>
4+
*/
5+
6+
'use strict';
7+
8+
const mod = require('../lib/index.js');
9+
10+
module.exports = {
11+
plugins: { 'eslint-plugin': mod },
12+
rules: mod.configs['tests-recommended'].rules,
13+
};

Diff for: configs/tests.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @fileoverview the `tests` config for `eslint.config.js`
3+
* @author 唯然<[email protected]>
4+
*/
5+
6+
'use strict';
7+
8+
const mod = require('../lib/index.js');
9+
10+
module.exports = {
11+
plugins: { 'eslint-plugin': mod },
12+
rules: mod.configs.tests.rules,
13+
};

Diff for: eslint.config.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'use strict';
2+
3+
const js = require('@eslint/js');
4+
const { FlatCompat } = require('@eslint/eslintrc');
5+
const globals = require('globals');
6+
const markdown = require('eslint-plugin-markdown');
7+
const eslintPluginConfig = require('eslint-plugin-eslint-plugin/configs/all');
8+
9+
const compat = new FlatCompat({
10+
baseDirectory: __dirname,
11+
recommendedConfig: js.configs.recommended,
12+
});
13+
14+
module.exports = [
15+
...compat.extends(
16+
'not-an-aardvark/node',
17+
'plugin:eslint-comments/recommended',
18+
'plugin:node/recommended',
19+
'plugin:prettier/recommended',
20+
'plugin:unicorn/recommended'
21+
),
22+
{
23+
languageOptions: { sourceType: 'commonjs' },
24+
rules: {
25+
'comma-dangle': [
26+
'error',
27+
{
28+
arrays: 'always-multiline',
29+
objects: 'always-multiline',
30+
functions: 'never', // disallow trailing commas in function(es2017)
31+
},
32+
],
33+
'require-jsdoc': 'error',
34+
35+
'eslint-comments/no-unused-disable': 'error',
36+
'eslint-comments/require-description': 'error',
37+
38+
'unicorn/consistent-function-scoping': 'off',
39+
'unicorn/no-array-callback-reference': 'off',
40+
'unicorn/no-array-for-each': 'off',
41+
'unicorn/no-array-reduce': 'off',
42+
'unicorn/no-null': 'off',
43+
'unicorn/prefer-module': 'off',
44+
'unicorn/prefer-node-protocol': 'off', // TODO: enable once we drop support for Node 14.17.
45+
'unicorn/prevent-abbreviations': 'off',
46+
},
47+
},
48+
{
49+
// Apply eslint-plugin rules to our own rules/tests (but not docs).
50+
files: ['lib/**/*.js', 'tests/**/*.js'],
51+
plugins: eslintPluginConfig.plugins,
52+
rules: {
53+
...eslintPluginConfig.rules,
54+
'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'],
55+
'eslint-plugin/require-meta-docs-url': [
56+
'error',
57+
{
58+
pattern:
59+
'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/{{name}}.md',
60+
},
61+
],
62+
},
63+
},
64+
{
65+
files: ['tests/**/*.js'],
66+
languageOptions: { globals: globals.mocha },
67+
},
68+
{
69+
files: ['**/*.md'],
70+
plugins: { markdown },
71+
processor: 'markdown/markdown',
72+
},
73+
{
74+
// Markdown JS code samples in documentation:
75+
files: ['**/*.md/*.js'],
76+
plugins: { markdown },
77+
linterOptions: { noInlineConfig: true },
78+
rules: {
79+
'no-undef': 'off',
80+
'no-unused-vars': 'off',
81+
strict: 'off',
82+
83+
'eslint-comments/require-description': 'off',
84+
85+
'unicorn/filename-case': 'off',
86+
},
87+
},
88+
];

Diff for: lib/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ const allRules = Object.fromEntries(
4141
])
4242
);
4343

44+
module.exports.meta = {
45+
name: packageMetadata.name,
46+
version: packageMetadata.version,
47+
};
48+
4449
module.exports.rules = allRules;
4550

4651
module.exports.configs = Object.keys(configFilters).reduce(

Diff for: package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "./lib/index.js",
77
"exports": {
88
".": "./lib/index.js",
9+
"./configs/*": "./configs/*.js",
910
"./package.json": "./package.json"
1011
},
1112
"license": "MIT",
@@ -22,7 +23,8 @@
2223
"update:eslint-docs": "eslint-doc-generator"
2324
},
2425
"files": [
25-
"lib/"
26+
"lib/",
27+
"configs/"
2628
],
2729
"keywords": [
2830
"eslint",
@@ -50,6 +52,8 @@
5052
"devDependencies": {
5153
"@commitlint/cli": "^17.1.2",
5254
"@commitlint/config-conventional": "^17.1.0",
55+
"@eslint/eslintrc": "^2.0.2",
56+
"@eslint/js": "^8.37.0",
5357
"@release-it/conventional-changelog": "^4.3.0",
5458
"@typescript-eslint/parser": "^5.36.2",
5559
"chai": "^4.3.6",
@@ -67,6 +71,7 @@
6771
"eslint-remote-tester": "^3.0.0",
6872
"eslint-scope": "^7.1.1",
6973
"espree": "^9.4.0",
74+
"globals": "^13.20.0",
7075
"husky": "^8.0.1",
7176
"lodash": "^4.17.21",
7277
"markdownlint-cli": "^0.34.0",

0 commit comments

Comments
 (0)