Skip to content

Commit a885b57

Browse files
feat: support flat config (#200)
1 parent 6c073d4 commit a885b57

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

configs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict"
2+
3+
const { rules: rulesRecommended } = require("./lib/configs/recommended")
4+
const rules = require("./lib/rules")
5+
const { name, version } = require("./package.json")
6+
7+
const plugin = {
8+
meta: { name, version },
9+
rules,
10+
}
11+
12+
module.exports = {
13+
recommended: {
14+
plugins: {
15+
"@eslint-community/eslint-comments": plugin,
16+
},
17+
rules: rulesRecommended,
18+
},
19+
}
20+
21+
module.exports.default = module.exports

docs/index.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,47 @@ npm install --save-dev eslint @eslint-community/eslint-plugin-eslint-comments
3232

3333
## 📖 Usage
3434

35-
Configure your `.eslintrc.*` file.
35+
Configure your [`eslint.config.*` file](https://eslint.org/docs/latest/use/configure/configuration-files-new).
36+
37+
For example:
38+
39+
```js
40+
import js from "@eslint/js"
41+
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs"
42+
43+
export default [
44+
js.configs.recommended,
45+
comments.recommended,
46+
]
47+
```
48+
49+
If your project's ESLint config runs in CommonJS instead of ESM, use `require()`:
50+
51+
```js
52+
const comments = require("@eslint-community/eslint-plugin-eslint-comments/configs")
53+
```
54+
55+
Either way, you can optionally configure individual rules:
56+
57+
```js
58+
// ...
59+
[
60+
// ...
61+
comments.recommended,
62+
{
63+
"@eslint-community/eslint-comments/no-unused-disable": "error"
64+
},
65+
]
66+
```
67+
68+
::: tip
69+
The [`@eslint-community/eslint-comments/no-unused-disable`](./rules/no-unused-disable.html) rule has the same effect as [--report-unused-disable-directives](https://eslint.org/docs/user-guide/command-line-interface#--report-unused-disable-directives) option.
70+
However, the `@eslint-community/eslint-comments/no-unused-disable` rule is relatively useful since it can be configured in shareable configs.
71+
:::
72+
73+
### 📜 Legacy ESLint Configs
74+
75+
Configure your [`.eslintrc.*` file](https://eslint.org/docs/latest/use/configure/configuration-files).
3676

3777
For example:
3878

@@ -48,8 +88,3 @@ For example:
4888
}
4989
}
5090
```
51-
52-
::: tip
53-
The [`@eslint-community/eslint-comments/no-unused-disable`](./rules/no-unused-disable.html) rule has the same effect as [--report-unused-disable-directives](https://eslint.org/docs/user-guide/command-line-interface#--report-unused-disable-directives) option.
54-
However, the `@eslint-community/eslint-comments/no-unused-disable` rule is relatively useful since it can be configured in shareable configs.
55-
:::

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
},
88
"main": "index.js",
99
"files": [
10+
"configs.js",
1011
"lib"
1112
],
13+
"exports": {
14+
"./configs": "./configs.js",
15+
".": "./index.js"
16+
},
1217
"peerDependencies": {
1318
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0"
1419
},

0 commit comments

Comments
 (0)