diff --git a/.eslint-doc-generatorrc.js b/.eslint-doc-generatorrc.js
index 8cd4b5ff..5c4ef3b6 100644
--- a/.eslint-doc-generatorrc.js
+++ b/.eslint-doc-generatorrc.js
@@ -1,7 +1,16 @@
+'use strict';
+
/** @type {import('eslint-doc-generator').GenerateOptions} */
module.exports = {
- ignoreConfig: ['all', 'rules', 'rules-recommended', 'tests', 'tests-recommended'],
+ ignoreConfig: [
+ 'all',
+ 'rules',
+ 'rules-recommended',
+ 'tests',
+ 'tests-recommended',
+ ],
ruleDocSectionInclude: ['Rule Details'],
ruleListSplit: 'meta.docs.category',
- urlConfigs: 'https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets',
+ urlConfigs:
+ 'https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets',
};
diff --git a/.eslintrc.js b/.eslintrc.js
deleted file mode 100644
index 4ff2ad29..00000000
--- a/.eslintrc.js
+++ /dev/null
@@ -1,79 +0,0 @@
-'use strict';
-
-module.exports = {
- root: true,
- parserOptions: {
- ecmaVersion: 2021,
- sourceType: 'script',
- },
- extends: [
- 'not-an-aardvark/node',
- 'plugin:eslint-comments/recommended',
- 'plugin:node/recommended',
- 'plugin:prettier/recommended',
- 'plugin:unicorn/recommended',
- ],
- rules: {
- 'comma-dangle': [
- 'error',
- {
- arrays: 'always-multiline',
- objects: 'always-multiline',
- functions: 'never', // disallow trailing commas in function(es2017)
- },
- ],
- 'require-jsdoc': 'error',
-
- 'eslint-comments/no-unused-disable': 'error',
- 'eslint-comments/require-description': 'error',
-
- 'unicorn/consistent-function-scoping': 'off',
- 'unicorn/no-array-callback-reference': 'off',
- 'unicorn/no-array-for-each': 'off',
- 'unicorn/no-array-reduce': 'off',
- 'unicorn/no-null': 'off',
- 'unicorn/prefer-module': 'off',
- 'unicorn/prefer-node-protocol': 'off', // TODO: enable once we drop support for Node 14.17.
- 'unicorn/prevent-abbreviations': 'off',
- },
- overrides: [
- {
- // Apply eslint-plugin rules to our own rules/tests (but not docs).
- files: ['lib/**/*.js', 'tests/**/*.js'],
- extends: ['plugin:eslint-plugin/all'],
- rules: {
- 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'],
- 'eslint-plugin/require-meta-docs-url': [
- 'error',
- {
- pattern:
- 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/{{name}}.md',
- },
- ],
- },
- },
- {
- files: ['tests/**/*.js'],
- env: { mocha: true },
- },
- {
- files: ['**/*.md'],
- processor: 'markdown/markdown',
- },
- {
- // Markdown JS code samples in documentation:
- files: ['**/*.md/*.js'],
- plugins: ['markdown'],
- noInlineConfig: true,
- rules: {
- 'no-undef': 'off',
- 'no-unused-vars': 'off',
- strict: 'off',
-
- 'eslint-comments/require-description': 'off',
-
- 'unicorn/filename-case': 'off',
- },
- },
- ],
-};
diff --git a/README.md b/README.md
index 575a5190..9e240627 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,8 @@ Here's an example ESLint configuration that:
* Enables the `recommended` configuration
* Enables an optional/non-recommended rule
+### **[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)**
+
```json
{
"parserOptions": {
@@ -52,6 +54,21 @@ Here's an example ESLint configuration that:
}
```
+### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0)
+
+```js
+const eslintPluginRecommended = require("eslint-plugin-eslint-plugin/configs/recommended");
+module.exports = [
+ eslintPluginRecommended,
+ {
+ languageOptions: {sourceType: "commonjs"},
+ rules: {
+ "eslint-plugin/require-meta-docs-description": "error",
+ },
+ },
+];
+```
+
## Rules
diff --git a/configs/all.js b/configs/all.js
new file mode 100644
index 00000000..131aeea1
--- /dev/null
+++ b/configs/all.js
@@ -0,0 +1,13 @@
+/**
+ * @fileoverview the `all` config for `eslint.config.js`
+ * @author 唯然
+ */
+
+'use strict';
+
+const mod = require('../lib/index.js');
+
+module.exports = {
+ plugins: { 'eslint-plugin': mod },
+ rules: mod.configs.all.rules,
+};
diff --git a/configs/recommended.js b/configs/recommended.js
new file mode 100644
index 00000000..977b4e24
--- /dev/null
+++ b/configs/recommended.js
@@ -0,0 +1,13 @@
+/**
+ * @fileoverview the `recommended` config for `eslint.config.js`
+ * @author 唯然
+ */
+
+'use strict';
+
+const mod = require('../lib/index.js');
+
+module.exports = {
+ plugins: { 'eslint-plugin': mod },
+ rules: mod.configs.recommended.rules,
+};
diff --git a/configs/rules-recommended.js b/configs/rules-recommended.js
new file mode 100644
index 00000000..dd784e45
--- /dev/null
+++ b/configs/rules-recommended.js
@@ -0,0 +1,13 @@
+/**
+ * @fileoverview the `rules-recommended` config for `eslint.config.js`
+ * @author 唯然
+ */
+
+'use strict';
+
+const mod = require('../lib/index.js');
+
+module.exports = {
+ plugins: { 'eslint-plugin': mod },
+ rules: mod.configs['rules-recommended'].rules,
+};
diff --git a/configs/rules.js b/configs/rules.js
new file mode 100644
index 00000000..1a4f8a90
--- /dev/null
+++ b/configs/rules.js
@@ -0,0 +1,13 @@
+/**
+ * @fileoverview the `rules` config for `eslint.config.js`
+ * @author 唯然
+ */
+
+'use strict';
+
+const mod = require('../lib/index.js');
+
+module.exports = {
+ plugins: { 'eslint-plugin': mod },
+ rules: mod.configs.rules.rules,
+};
diff --git a/configs/tests-recommended.js b/configs/tests-recommended.js
new file mode 100644
index 00000000..41c50540
--- /dev/null
+++ b/configs/tests-recommended.js
@@ -0,0 +1,13 @@
+/**
+ * @fileoverview the `tests-recommended` config for `eslint.config.js`
+ * @author 唯然
+ */
+
+'use strict';
+
+const mod = require('../lib/index.js');
+
+module.exports = {
+ plugins: { 'eslint-plugin': mod },
+ rules: mod.configs['tests-recommended'].rules,
+};
diff --git a/configs/tests.js b/configs/tests.js
new file mode 100644
index 00000000..53ea6c87
--- /dev/null
+++ b/configs/tests.js
@@ -0,0 +1,13 @@
+/**
+ * @fileoverview the `tests` config for `eslint.config.js`
+ * @author 唯然
+ */
+
+'use strict';
+
+const mod = require('../lib/index.js');
+
+module.exports = {
+ plugins: { 'eslint-plugin': mod },
+ rules: mod.configs.tests.rules,
+};
diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 00000000..94bebc30
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,88 @@
+'use strict';
+
+const js = require('@eslint/js');
+const { FlatCompat } = require('@eslint/eslintrc');
+const globals = require('globals');
+const markdown = require('eslint-plugin-markdown');
+const eslintPluginConfig = require('eslint-plugin-eslint-plugin/configs/all');
+
+const compat = new FlatCompat({
+ baseDirectory: __dirname,
+ recommendedConfig: js.configs.recommended,
+});
+
+module.exports = [
+ ...compat.extends(
+ 'not-an-aardvark/node',
+ 'plugin:eslint-comments/recommended',
+ 'plugin:node/recommended',
+ 'plugin:prettier/recommended',
+ 'plugin:unicorn/recommended'
+ ),
+ {
+ languageOptions: { sourceType: 'commonjs' },
+ rules: {
+ 'comma-dangle': [
+ 'error',
+ {
+ arrays: 'always-multiline',
+ objects: 'always-multiline',
+ functions: 'never', // disallow trailing commas in function(es2017)
+ },
+ ],
+ 'require-jsdoc': 'error',
+
+ 'eslint-comments/no-unused-disable': 'error',
+ 'eslint-comments/require-description': 'error',
+
+ 'unicorn/consistent-function-scoping': 'off',
+ 'unicorn/no-array-callback-reference': 'off',
+ 'unicorn/no-array-for-each': 'off',
+ 'unicorn/no-array-reduce': 'off',
+ 'unicorn/no-null': 'off',
+ 'unicorn/prefer-module': 'off',
+ 'unicorn/prefer-node-protocol': 'off', // TODO: enable once we drop support for Node 14.17.
+ 'unicorn/prevent-abbreviations': 'off',
+ },
+ },
+ {
+ // Apply eslint-plugin rules to our own rules/tests (but not docs).
+ files: ['lib/**/*.js', 'tests/**/*.js'],
+ plugins: eslintPluginConfig.plugins,
+ rules: {
+ ...eslintPluginConfig.rules,
+ 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'],
+ 'eslint-plugin/require-meta-docs-url': [
+ 'error',
+ {
+ pattern:
+ 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/{{name}}.md',
+ },
+ ],
+ },
+ },
+ {
+ files: ['tests/**/*.js'],
+ languageOptions: { globals: globals.mocha },
+ },
+ {
+ files: ['**/*.md'],
+ plugins: { markdown },
+ processor: 'markdown/markdown',
+ },
+ {
+ // Markdown JS code samples in documentation:
+ files: ['**/*.md/*.js'],
+ plugins: { markdown },
+ linterOptions: { noInlineConfig: true },
+ rules: {
+ 'no-undef': 'off',
+ 'no-unused-vars': 'off',
+ strict: 'off',
+
+ 'eslint-comments/require-description': 'off',
+
+ 'unicorn/filename-case': 'off',
+ },
+ },
+];
diff --git a/lib/index.js b/lib/index.js
index baab06b4..4ff4ef76 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -41,6 +41,11 @@ const allRules = Object.fromEntries(
])
);
+module.exports.meta = {
+ name: packageMetadata.name,
+ version: packageMetadata.version,
+};
+
module.exports.rules = allRules;
module.exports.configs = Object.keys(configFilters).reduce(
diff --git a/package.json b/package.json
index 7905b5dc..06d72eeb 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"main": "./lib/index.js",
"exports": {
".": "./lib/index.js",
+ "./configs/*": "./configs/*.js",
"./package.json": "./package.json"
},
"license": "MIT",
@@ -22,7 +23,8 @@
"update:eslint-docs": "eslint-doc-generator"
},
"files": [
- "lib/"
+ "lib/",
+ "configs/"
],
"keywords": [
"eslint",
@@ -50,6 +52,8 @@
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
+ "@eslint/eslintrc": "^2.0.2",
+ "@eslint/js": "^8.37.0",
"@release-it/conventional-changelog": "^4.3.0",
"@typescript-eslint/parser": "^5.36.2",
"chai": "^4.3.6",
@@ -67,6 +71,7 @@
"eslint-remote-tester": "^3.0.0",
"eslint-scope": "^7.1.1",
"espree": "^9.4.0",
+ "globals": "^13.20.0",
"husky": "^8.0.1",
"lodash": "^4.17.21",
"markdownlint-cli": "^0.34.0",