Skip to content

Commit ee4fe89

Browse files
ZamiellJosh-CenaJoshuaKGoldberg
authored
docs: better rules table (filter rules by extension, etc.) (#7666)
* docs: sort rules by extension * docs: make sorting columns smaller * fix: prettier * fix: metadata on 1 line * fix: sort description at bottom * fix: remove buttons * Update README.md * Update packages/eslint-plugin/docs/rules/README.md Co-authored-by: Joshua Chen <sidachen2003@gmail.com> * Update packages/website/src/components/RulesTable/index.tsx Co-authored-by: Joshua Chen <sidachen2003@gmail.com> * fix: sort --> filter * fix: sort --> filter * Update packages/eslint-plugin/docs/rules/README.md Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com> * feat: adding tip * feat: config emoji * feat: shorten filtering docs * yarn format * Added explicit Extension Rules heading * class-methods-use-this isn't actually in eslint:recommended * no-unused-vars actually --------- Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
1 parent 4c8edcf commit ee4fe89

File tree

9 files changed

+233
-115
lines changed

9 files changed

+233
-115
lines changed

packages/eslint-plugin/docs/rules/README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,55 @@ pagination_prev: null
66
slug: /
77
---
88

9-
`@typescript-eslint/eslint-plugin` includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code.
10-
See [Configs](/linting/configs) for how to enable recommended rules using configs.
9+
`@typescript-eslint/eslint-plugin` includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code. All of our rules are listed below.
1110

12-
## Supported Rules
11+
:::tip
12+
Instead of enabling rules one by one, we recommend using one of [our pre-defined configs](/linting/configs) to enable a large set of recommended rules.
13+
:::
14+
15+
## Rules
16+
17+
The rules are listed in alphabetical order. You can optionally filter them based on these categories:
1318

1419
import RulesTable from "@site/src/components/RulesTable";
1520

16-
<RulesTable ruleset="supported-rules" />
21+
<RulesTable />
22+
23+
## Filtering
24+
25+
### Config Group (⚙️)
26+
27+
"Config Group" refers to the [pre-defined config](/linting/configs) that includes the rule. Extending from a configuration preset allow for enabling a large set of recommended rules all at once.
28+
29+
### Metadata
30+
31+
- `🔧 fixable` refers to whether the rule contains an [ESLint `--fix` auto-fixer](https://eslint.org/docs/latest/use/command-line-interface#--fix).
32+
- `💡 has suggestions` refers to whether the rule contains an ESLint suggestion fixer.
33+
- Sometimes, it is not safe to automatically fix the code with an auto-fixer. But in these cases, we often have a good guess of what the correct fix should be, and we can provide it as a suggestion to the developer.
34+
- `💭 requires type information` refers to whether the rule requires [typed linting](/linting/typed-linting).
35+
- `🧱 extension rule` means that the rule is an extension of an [core ESLint rule](https://eslint.org/docs/latest/rules) (see [Extension Rules](#extension-rules)).
36+
- `📐 formatting rule` means that the rule has to do with formatting.
37+
- We [strongly recommend against using ESLint for formatting](/linting/troubleshooting/formatting).
38+
- Soon, formatting rules will be moved to the [ESLint stylistic plugin](https://eslint.style).
39+
- `💀 deprecated rule` means that the rule should no longer be used and will be removed from the plugin in a future version.
1740

1841
## Extension Rules
1942

20-
In some cases, ESLint provides a rule itself, but it doesn't support TypeScript syntax; either it crashes, or it ignores the syntax, or it falsely reports against it.
21-
In these cases, we create what we call an extension rule; a rule within our plugin that has the same functionality, but also supports TypeScript.
43+
Some core ESLint rules do not support TypeScript syntax: either they crash, ignore the syntax, or falsely report against it.
44+
In these cases, we create what we call an "extension rule": a rule within our plugin that has the same functionality, but also supports TypeScript.
45+
46+
Extension rules generally completely replace the base rule from ESLint core.
47+
If the base rule is enabled in a config you extend from, you'll need to disable the base rule:
48+
49+
```js
50+
module.exports = {
51+
extends: ['eslint:recommended'],
52+
rules: {
53+
// Note: you must disable the base rule as it can report incorrect errors
54+
'no-unused-vars': 'off',
55+
'@typescript-eslint/no-unused-vars': 'error',
56+
},
57+
};
58+
```
2259

23-
<RulesTable ruleset="extension-rules" />
60+
[Search for `🧱 extension rule`s](?=extension#rules) in this page to see all extension rules.

packages/eslint-plugin/docs/rules/camelcase.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This rule has been deprecated in favour of the [`naming-convention`](./naming-co
55
:::
66

77
<!--
8-
This doc file has been left on purpose because `camelcase` is a core ESLint rule.
9-
This exists to help direct people to the replacement rule.
8+
This doc file has been left on purpose because `camelcase` is a core ESLint
9+
rule. This exists to help direct people to the replacement rule.
10+
11+
Note that there is no actual way to get to this page in the normal navigation,
12+
so end-users will only be able to get to this page from the search bar.
1013
-->

packages/eslint-plugin/docs/rules/no-duplicate-imports.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This rule has been deprecated in favour of the [`import/no-duplicates`](https://
55
:::
66

77
<!--
8-
This doc file has been left on purpose because `import/no-duplicates` is commonly requested.
9-
This exists to help direct people to the replacement rule.
8+
This doc file has been left on purpose because `import/no-duplicates` is
9+
commonly requested. This exists to help direct people to the replacement rule.
10+
11+
Note that there is no actual way to get to this page in the normal navigation,
12+
so end-users will only be able to get to this page from the search bar.
1013
-->

packages/eslint-plugin/tests/docs.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe('Validating rule docs', () => {
4242
const ignoredFiles = new Set([
4343
'README.md',
4444
'TEMPLATE.md',
45-
// these rule docs were left behind on purpose for legacy reasons
45+
// These rule docs were left behind on purpose for legacy reasons. See the
46+
// comments in the files for more information.
4647
'camelcase.md',
4748
'no-duplicate-imports.md',
4849
]);

packages/eslint-plugin/tools/generate-breaking-changes.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async function main(): Promise<void> {
141141
recommended === 'recommended' ? '🟩' : '',
142142
recommended === 'strict' ? '🔵' : '',
143143
recommended === 'stylistic' ? '🔸' : '',
144-
meta.type === 'layout' ? 'layout 💩' : '(todo)',
144+
meta.type === 'layout' ? 'layout 📐' : '(todo)',
145145
];
146146
}),
147147
]),
Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const globby = require('globby');
2-
const path = require('path');
3-
41
const plugin = require('@typescript-eslint/eslint-plugin');
52

63
const rules = Object.entries(plugin.rules).map(([name, rule]) => {
@@ -10,43 +7,6 @@ const rules = Object.entries(plugin.rules).map(([name, rule]) => {
107
};
118
});
129

13-
const deprecatedRules = new Set(rules.filter(rule => rule.meta.deprecated));
14-
15-
const formattingRules = new Set(
16-
rules.filter(rule => !rule.meta.deprecated && rule.meta.type === 'layout'),
17-
);
18-
19-
const extensionRules = new Set(
20-
rules.filter(
21-
rule => rule.meta.docs?.extendsBaseRule && !formattingRules.has(rule),
22-
),
23-
);
24-
25-
const typescriptRules = rules.filter(
26-
rule =>
27-
!rule.meta.deprecated &&
28-
!extensionRules.has(rule) &&
29-
!deprecatedRules.has(rule) &&
30-
!formattingRules.has(rule),
31-
);
32-
33-
const paths = globby
34-
.sync('*.md', {
35-
cwd: path.join(__dirname, '../../eslint-plugin/docs/rules'),
36-
})
37-
.map(item => {
38-
return {
39-
name: path.basename(item, '.md'),
40-
};
41-
})
42-
.filter(item => {
43-
return (
44-
item.name !== 'README' &&
45-
item.name !== 'TEMPLATE' &&
46-
!rules.some(a => a.name === item.name)
47-
);
48-
});
49-
5010
function createCategory(label, rules, additionalItems = []) {
5111
return {
5212
items: [
@@ -68,17 +28,8 @@ module.exports = {
6828
someSidebar: [
6929
'README',
7030
{
71-
...createCategory('TypeScript Rules', Array.from(typescriptRules)),
72-
collapsed: false,
73-
},
74-
{
75-
...createCategory('Extension Rules', Array.from(extensionRules)),
31+
...createCategory('Rules', rules),
7632
collapsed: false,
7733
},
78-
createCategory('Formatting Rules', Array.from(formattingRules)),
79-
createCategory('Deprecated Rules', [
80-
...Array.from(deprecatedRules),
81-
...paths,
82-
]),
8334
],
8435
};

0 commit comments

Comments
 (0)