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

.eslint-doc-generatorrc.js

Lines changed: 11 additions & 2 deletions
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
};

.eslintrc.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 0 deletions
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 -->

configs/all.js

Lines changed: 13 additions & 0 deletions
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+
};

configs/recommended.js

Lines changed: 13 additions & 0 deletions
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+
};

configs/rules-recommended.js

Lines changed: 13 additions & 0 deletions
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+
};

configs/rules.js

Lines changed: 13 additions & 0 deletions
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+
};

configs/tests-recommended.js

Lines changed: 13 additions & 0 deletions
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+
};

configs/tests.js

Lines changed: 13 additions & 0 deletions
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+
};

eslint.config.js

Lines changed: 88 additions & 0 deletions
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+
];

0 commit comments

Comments
 (0)