Skip to content
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

feat: re-export flat configs "flat/*" #453

Merged
merged 4 commits into from
Apr 1, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslint-doc-generatorrc.js
Expand Up @@ -11,6 +11,13 @@ module.exports = {
'rules-recommended',
'tests',
'tests-recommended',
'flat/recommended',
'flat/all',
'flat/all-type-checked',
'flat/rules',
'flat/rules-recommended',
'flat/tests',
'flat/tests-recommended',
],
postprocess: async (content, path) =>
prettier.format(content, {
Expand Down
37 changes: 30 additions & 7 deletions README.md
Expand Up @@ -47,9 +47,6 @@ Here's an example ESLint configuration that:

```json
{
"parserOptions": {
"sourceType": "script"
},
"extends": ["plugin:eslint-plugin/recommended"],
"rules": {
"eslint-plugin/require-meta-docs-description": "error"
Expand All @@ -60,11 +57,10 @@ 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');
const eslintPlugin = require('eslint-plugin-eslint-plugin');
module.exports = [
eslintPluginRecommended,
eslintPlugin.configs['flat/recommended'],
{
languageOptions: { sourceType: 'commonjs' },
rules: {
'eslint-plugin/require-meta-docs-description': 'error',
},
Expand Down Expand Up @@ -139,7 +135,16 @@ The list of recommended rules will only change in a major release of this plugin

### <a name='Presetusage'></a>Preset usage

Presets are enabled by adding a line to the `extends` list in your config file. For example, to enable the `recommended` preset, use:
Both flat and eslintrc configs are supported. For example, to enable the `recommended` preset, use:

eslint.config.js

```js
const eslintPlugin = require('eslint-plugin-eslint-plugin');
module.exports = [eslintPlugin.configs['flat/recommended']];
```

.eslintrc.json

```json
{
Expand All @@ -149,6 +154,24 @@ Presets are enabled by adding a line to the `extends` list in your config file.

Or to apply linting only to the appropriate rule or test files:

eslint.config.js

```js
const eslintPlugin = require('eslint-plugin-eslint-plugin');
module.exports = [
{
files: ['lib/rules/*.{js,ts}'],
...eslintPlugin.configs['flat/rules-recommended'],
},
{
files: ['tests/lib/rules/*.{js,ts}'],
...eslintPlugin.configs['flat/tests-recommended'],
},
];
```

.eslintrc.js

```json
{
"overrides": [
Expand Down
12 changes: 7 additions & 5 deletions configs/all-type-checked.js
@@ -1,8 +1,10 @@
/**
* @deprecated use 'flat/all-type-checked' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['all-type-checked'].rules,
};
module.exports = plugin.configs['flat/all-type-checked'];
8 changes: 3 additions & 5 deletions configs/all.js
@@ -1,13 +1,11 @@
/**
* @fileoverview the `all` config for `eslint.config.js`
* @deprecated use 'flat/all' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.all.rules,
};
module.exports = plugin.configs['flat/all'];
8 changes: 3 additions & 5 deletions configs/recommended.js
@@ -1,13 +1,11 @@
/**
* @fileoverview the `recommended` config for `eslint.config.js`
* @deprecated use 'flat/recommended' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.recommended.rules,
};
module.exports = plugin.configs['flat/recommended'];
8 changes: 3 additions & 5 deletions configs/rules-recommended.js
@@ -1,13 +1,11 @@
/**
* @fileoverview the `rules-recommended` config for `eslint.config.js`
* @deprecated use 'flat/rules-recommended' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['rules-recommended'].rules,
};
module.exports = plugin.configs['flat/rules-recommended'];
8 changes: 3 additions & 5 deletions configs/rules.js
@@ -1,13 +1,11 @@
/**
* @fileoverview the `rules` config for `eslint.config.js`
* @deprecated use 'flat/rules' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.rules.rules,
};
module.exports = plugin.configs['flat/rules'];
8 changes: 3 additions & 5 deletions configs/tests-recommended.js
@@ -1,13 +1,11 @@
/**
* @fileoverview the `tests-recommended` config for `eslint.config.js`
* @deprecated use 'flat/tests-recommended' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['tests-recommended'].rules,
};
module.exports = plugin.configs['flat/tests-recommended'];
8 changes: 3 additions & 5 deletions configs/tests.js
@@ -1,13 +1,11 @@
/**
* @fileoverview the `tests` config for `eslint.config.js`
* @deprecated use 'flat/tests' instead
* @author 唯然<[email protected]>
*/

'use strict';

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

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.tests.rules,
};
module.exports = plugin.configs['flat/tests'];
40 changes: 31 additions & 9 deletions lib/index.js
Expand Up @@ -42,15 +42,19 @@ const allRules = Object.fromEntries(
])
);

module.exports.meta = {
name: packageMetadata.name,
version: packageMetadata.version,
const plugin = {
meta: {
name: packageMetadata.name,
version: packageMetadata.version,
},
rules: allRules,
configs: {}, // assigned later
};

module.exports.rules = allRules;

module.exports.configs = Object.keys(configFilters).reduce(
(configs, configName) => {
// eslintrc configs
Object.assign(
plugin.configs,
Object.keys(configFilters).reduce((configs, configName) => {
return Object.assign(configs, {
[configName]: {
plugins: ['eslint-plugin'],
Expand All @@ -61,6 +65,24 @@ module.exports.configs = Object.keys(configFilters).reduce(
),
},
});
},
{}
}, {})
);

// flat configs
Object.assign(
plugin.configs,
Object.keys(configFilters).reduce((configs, configName) => {
return Object.assign(configs, {
[`flat/${configName}`]: {
plugins: { 'eslint-plugin': plugin },
rules: Object.fromEntries(
Object.keys(allRules)
.filter((ruleName) => configFilters[configName](allRules[ruleName]))
.map((ruleName) => [`${PLUGIN_NAME}/${ruleName}`, 'error'])
),
},
});
}, {})
);

module.exports = plugin;
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -53,15 +53,15 @@
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@eslint/eslintrc": "^2.0.2",
"@eslint/js": "^8.37.0",
"@eslint/js": "^8.57.0",
"@release-it/conventional-changelog": "^4.3.0",
"@types/eslint": "^8.56.2",
"@types/eslint": "^8.56.6",
"@types/estree": "^1.0.5",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"chai": "^4.3.6",
"dirty-chai": "^2.0.1",
"eslint": "^8.23.0",
"eslint": "^8.57.0",
"eslint-config-not-an-aardvark": "^2.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-doc-generator": "^1.7.0",
Expand All @@ -78,13 +78,13 @@
"husky": "^8.0.1",
"lodash": "^4.17.21",
"markdownlint-cli": "^0.39.0",
"mocha": "^10.0.0",
"npm-package-json-lint": "^7.0.0",
"npm-run-all2": "^5.0.0",
"mocha": "^10.4.0",
"npm-package-json-lint": "^7.1.0",
"npm-run-all2": "^6.1.2",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"release-it": "^14.14.3",
"typescript": "^5.1.3"
"typescript": "^5.4.3"
},
"peerDependencies": {
"eslint": ">=7.0.0"
Expand Down