Skip to content

Commit

Permalink
feat: support flat config (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg authored Apr 8, 2024
1 parent 6c073d4 commit a885b57
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
21 changes: 21 additions & 0 deletions configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict"

const { rules: rulesRecommended } = require("./lib/configs/recommended")
const rules = require("./lib/rules")
const { name, version } = require("./package.json")

const plugin = {
meta: { name, version },
rules,
}

module.exports = {
recommended: {
plugins: {
"@eslint-community/eslint-comments": plugin,
},
rules: rulesRecommended,
},
}

module.exports.default = module.exports
47 changes: 41 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,47 @@ npm install --save-dev eslint @eslint-community/eslint-plugin-eslint-comments

## 📖 Usage

Configure your `.eslintrc.*` file.
Configure your [`eslint.config.*` file](https://eslint.org/docs/latest/use/configure/configuration-files-new).

For example:

```js
import js from "@eslint/js"
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs"

export default [
js.configs.recommended,
comments.recommended,
]
```

If your project's ESLint config runs in CommonJS instead of ESM, use `require()`:

```js
const comments = require("@eslint-community/eslint-plugin-eslint-comments/configs")
```

Either way, you can optionally configure individual rules:

```js
// ...
[
// ...
comments.recommended,
{
"@eslint-community/eslint-comments/no-unused-disable": "error"
},
]
```

::: tip
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.
However, the `@eslint-community/eslint-comments/no-unused-disable` rule is relatively useful since it can be configured in shareable configs.
:::

### 📜 Legacy ESLint Configs

Configure your [`.eslintrc.*` file](https://eslint.org/docs/latest/use/configure/configuration-files).

For example:

Expand All @@ -48,8 +88,3 @@ For example:
}
}
```

::: tip
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.
However, the `@eslint-community/eslint-comments/no-unused-disable` rule is relatively useful since it can be configured in shareable configs.
:::
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
},
"main": "index.js",
"files": [
"configs.js",
"lib"
],
"exports": {
"./configs": "./configs.js",
".": "./index.js"
},
"peerDependencies": {
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0"
},
Expand Down

0 comments on commit a885b57

Please sign in to comment.