Skip to content

feat: support eslint.config.js #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -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',
};
79 changes: 0 additions & 79 deletions .eslintrc.js

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Here's an example ESLint configuration that:
* Enables the `recommended` configuration
* Enables an optional/non-recommended rule

### <a name='eslintrc'></a>**[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)**

```json
{
"parserOptions": {
Expand All @@ -52,6 +54,21 @@ Here's an example ESLint configuration that:
}
```

### <a name='flat'></a>[`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",
},
},
];
```

## <a name='Rules'></a>Rules

<!-- begin auto-generated rules list -->
Expand Down
13 changes: 13 additions & 0 deletions configs/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @fileoverview the `all` config for `eslint.config.js`
* @author 唯然<[email protected]>
*/

'use strict';

const mod = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.all.rules,
};
13 changes: 13 additions & 0 deletions configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @fileoverview the `recommended` config for `eslint.config.js`
* @author 唯然<[email protected]>
*/

'use strict';

const mod = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.recommended.rules,
};
13 changes: 13 additions & 0 deletions configs/rules-recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @fileoverview the `rules-recommended` config for `eslint.config.js`
* @author 唯然<[email protected]>
*/

'use strict';

const mod = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['rules-recommended'].rules,
};
13 changes: 13 additions & 0 deletions configs/rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @fileoverview the `rules` config for `eslint.config.js`
* @author 唯然<[email protected]>
*/

'use strict';

const mod = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.rules.rules,
};
13 changes: 13 additions & 0 deletions configs/tests-recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @fileoverview the `tests-recommended` config for `eslint.config.js`
* @author 唯然<[email protected]>
*/

'use strict';

const mod = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['tests-recommended'].rules,
};
13 changes: 13 additions & 0 deletions configs/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @fileoverview the `tests` config for `eslint.config.js`
* @author 唯然<[email protected]>
*/

'use strict';

const mod = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.tests.rules,
};
88 changes: 88 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
},
];
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "./lib/index.js",
"exports": {
".": "./lib/index.js",
"./configs/*": "./configs/*.js",
"./package.json": "./package.json"
},
"license": "MIT",
Expand All @@ -22,7 +23,8 @@
"update:eslint-docs": "eslint-doc-generator"
},
"files": [
"lib/"
"lib/",
"configs/"
],
"keywords": [
"eslint",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down