From 69ef4b2608f783b5ff971fb8173bbc4a2cb0c3a2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 24 Mar 2024 09:46:28 -0400 Subject: [PATCH] feat: support flat config --- configs.js | 21 +++++++++++++++++++++ docs/index.md | 47 +++++++++++++++++++++++++++++++++++++++++------ package.json | 5 +++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 configs.js diff --git a/configs.js b/configs.js new file mode 100644 index 0000000..1267740 --- /dev/null +++ b/configs.js @@ -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 diff --git a/docs/index.md b/docs/index.md index 90da2ee..21751ca 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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: @@ -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. -::: diff --git a/package.json b/package.json index d18132b..bacf1e8 100644 --- a/package.json +++ b/package.json @@ -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" },