Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 0 additions & 7 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ const config = {
'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
15 changes: 2 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,17 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
node-version: 'lts/*'
- run: npm install
- run: npm run lint

eslint8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
- run: npm install
- run: npm install --save-dev eslint@8
- run: npm test

test-remote:
name: eslint-remote-tester
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
node-version: 'lts/*'
- run: npm install
- run: npm run test:remote
70 changes: 16 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ An ESLint plugin for linting ESLint plugins. Rules written in CJS, ESM, and Type

- [Installation](#installation)
- [Usage](#usage)
- [**.eslintrc.json**](#eslintrcjson)
- [`eslint.config.js` (requires eslint\>=v8.23.0)](#eslintconfigjs-requires-eslintv8230)
- [Rules](#rules)
- [Rules](#rules-1)
- [Tests](#tests)
Expand Down Expand Up @@ -42,25 +40,14 @@ Here's an example ESLint configuration that:
- Enables the `recommended` configuration
- Enables an optional/non-recommended rule

Note: you might need to set `sourceType` to `script` (most users) (use `module` for ESM/TypeScript).

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

```json
{
"extends": ["plugin:eslint-plugin/recommended"],
"rules": {
"eslint-plugin/require-meta-docs-description": "error"
}
}
```

### <a name='flat'></a>[`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0)
Note: you might need to set `sourceType` to `module` or `script` depending on your codebase.

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

export default [
eslintPlugin.configs.recommended,
{
rules: {
'eslint-plugin/require-meta-docs-description': 'error',
Expand Down Expand Up @@ -141,54 +128,29 @@ The list of recommended rules will only change in a major release of this plugin

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

Both flat and eslintrc configs are supported. For example, to enable the `recommended` preset, use:

eslint.config.js
Example of applying the `recommended` config to all files.

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

.eslintrc.json

```json
{
"extends": ["plugin:eslint-plugin/recommended"]
}
export default [eslintPlugin.configs.recommended];
```

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 = [
// eslint.config.js
import eslintPlugin from 'eslint-plugin-eslint-plugin';

export default [
{
files: ['lib/rules/*.{js,ts}'],
...eslintPlugin.configs['flat/rules-recommended'],
...eslintPlugin.configs['rules-recommended'],
},
{
files: ['tests/lib/rules/*.{js,ts}'],
...eslintPlugin.configs['flat/tests-recommended'],
...eslintPlugin.configs['tests-recommended'],
},
];
```

.eslintrc.js

```json
{
"overrides": [
{
"files": ["lib/rules/*.{js,ts}"],
"extends": ["plugin:eslint-plugin/rules-recommended"]
},
{
"files": ["tests/lib/rules/*.{js,ts}"],
"extends": ["plugin:eslint-plugin/tests-recommended"]
}
]
}
```
10 changes: 0 additions & 10 deletions configs/all-type-checked.js

This file was deleted.

11 changes: 0 additions & 11 deletions configs/all.js

This file was deleted.

11 changes: 0 additions & 11 deletions configs/recommended.js

This file was deleted.

11 changes: 0 additions & 11 deletions configs/rules-recommended.js

This file was deleted.

11 changes: 0 additions & 11 deletions configs/rules.js

This file was deleted.

11 changes: 0 additions & 11 deletions configs/tests-recommended.js

This file was deleted.

11 changes: 0 additions & 11 deletions configs/tests.js

This file was deleted.

53 changes: 39 additions & 14 deletions docs/rules/require-meta-docs-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,54 @@
}
```

```js
// eslint.config.js
import eslintPlugin from 'eslint-plugin-eslint-plugin';

export default [
{
plugins: { 'eslint-plugin': eslintPlugin },
rules: {
'eslint-plugin/require-meta-docs-url': [
'error',
{
pattern:
'https://github.com/eslint-community/eslint-plugin-eslint-plugin/blob/master/docs/rules/{{name}}.md',
},
],
},
},
];
```

If you set the `pattern` option, this rule adds `meta.docs.url` property automatically when you execute `eslint --fix` command.

## Version specific URL

If you want to enforce version-specific URLs, it's feasible easily with `.eslintrc.js` and `npm version <type>` script.
If you want to enforce version-specific URLs, it's feasible easily with `eslint.config.js` and `npm version <type>` script.
For example:

**.eslintrc.js**:
**eslint.config.js**:

```js
// const version = require("./package.json").version;

module.exports = {
plugins: ['eslint-plugin'],
rules: {
'eslint-plugin/require-meta-docs-url': [
'error',
{
pattern: `path/to/v${version}/docs/rules/{{name}}.md`,
},
],
import eslintPlugin from 'eslint-plugin-eslint-plugin';
import packageMetadata from './package.json' with { type: 'json' };

Check failure on line 130 in docs/rules/require-meta-docs-url.md

View workflow job for this annotation

GitHub Actions / lint

Can't resolve './package.json' in '/home/runner/work/eslint-plugin-eslint-plugin/eslint-plugin-eslint-plugin/docs/rules/require-meta-docs-url.md'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: 130:29 error Can't resolve './package.json' in '/home/runner/work/eslint-plugin-eslint-plugin/eslint-plugin-eslint-plugin/docs/rules/require-meta-docs-url.md' n/no-missing-import

You can disable that lint rule for this file if necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I had 'n/no-missing-imports' instead of 'n/no-missing-import' doh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now


const { version } = packageMetadata;

export default [
{
plugins: { 'eslint-plugin': eslintPlugin },
rules: {
'eslint-plugin/require-meta-docs-url': [
'error',
{
pattern: `path/to/v${version}/docs/rules/{{name}}.md`,
},
],
},
},
};
];
```

**package.json**:
Expand Down
8 changes: 5 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import markdown from 'eslint-plugin-markdown';
import pluginN from 'eslint-plugin-n';
import eslintPluginConfig from 'eslint-plugin-eslint-plugin/configs/all';
import eslintPlugin from './lib/index.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const compat = new FlatCompat({
Expand Down Expand Up @@ -46,9 +46,9 @@ export default [
{
// Apply eslint-plugin rules to our own rules/tests (but not docs).
files: ['lib/**/*.js', 'tests/**/*.js'],
plugins: eslintPluginConfig.plugins,
plugins: { 'eslint-plugin': eslintPlugin },
rules: {
...eslintPluginConfig.rules,
...eslintPlugin.configs.all.rules,
'eslint-plugin/no-meta-schema-default': 'off', // TODO: enable once https://github.com/bmish/eslint-doc-generator/issues/513 is fixed and released
'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'],
'eslint-plugin/require-meta-docs-url': [
Expand Down Expand Up @@ -77,6 +77,8 @@ export default [

'@eslint-community/eslint-comments/require-description': 'off',

'n/no-missing-imports': 'off',

'unicorn/filename-case': 'off',
},
},
Expand Down
23 changes: 3 additions & 20 deletions lib/index.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's some more context about the config names btw:

I think the current plan to just drop ESLint v8 / eslintrc now is fine.

Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,14 @@ const plugin = {
configs: {}, // assigned later
};

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

// flat configs
Object.assign(
plugin.configs,
Object.keys(configFilters).reduce((configs, configName) => {
return Object.assign(configs, {
[`flat/${configName}`]: {
name: `eslint-plugin/flat/${configName}`,
plugins: { 'eslint-plugin': plugin },
name: `${PLUGIN_NAME}/${configName}`,
plugins: { [PLUGIN_NAME]: plugin },
rules: Object.fromEntries(
Object.keys(allRules)
.filter((ruleName) => configFilters[configName](allRules[ruleName]))
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"type": "module",
"exports": {
".": "./lib/index.js",
"./configs/*": "./configs/*.js",
"./package.json": "./package.json"
},
"license": "MIT",
Expand All @@ -24,8 +23,8 @@
"update:eslint-docs": "eslint-doc-generator"
},
"files": [
"lib/",
"configs/"
"CHANGELOG.md",
"lib/"
],
"keywords": [
"eslint",
Expand Down Expand Up @@ -79,7 +78,7 @@
"vitest": "^3.2.4"
},
"peerDependencies": {
"eslint": ">=8.23.0"
"eslint": ">=9.0.0"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
Expand Down
Loading
Loading