Skip to content

Commit c7f8bee

Browse files
authored
Docs: add rule documentation consistency tests (#137)
Adds tests to ensure that our rule docs have notices to indicate whether they are fixable and/or in the recommended config. These notices match the format used by ESLint itself. Example: https://eslint.org/docs/rules/no-extra-semi Also adds tests for various other aspects of rule docs and that each rule has a documentation file and test file.
1 parent 15ffada commit c7f8bee

18 files changed

+173
-39
lines changed

docs/rules/fixer-return.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Enforces always return from a fixer function (fixer-return)
22

3+
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4+
35
In a fixable rule, missing return from a fixer function will not apply fixes.
46

57
## Rule Details

docs/rules/meta-property-ordering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# enforce ordering of meta properties in rule source (meta-property-ordering)
22

3-
(fixable) The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) automatically fixes problems reported by this rule.
3+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
44

55
This rule enforces that meta properties of a rule are placed in a consistent order.
66

docs/rules/no-deprecated-context-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallows usage of deprecated methods on rule context objects (no-deprecated-context-methods)
22

3-
(fixable) The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) automatically fixes problems reported by this rule.
3+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
44

55
This rule disallows the use of deprecated methods on rule `context` objects.
66

docs/rules/no-deprecated-report-api.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# disallow use of the deprecated context.report() API (no-deprecated-report-api)
22

3-
(fixable) The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) automatically fixes problems reported by this rule.
3+
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4+
5+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
46

57
ESLint has two APIs that rules can use to report problems. The [deprecated API](http://eslint.org/docs/developer-guide/working-with-rules-deprecated) accepts multiple arguments: `context.report(node, [loc], message)`. The ["new API"](http://eslint.org/docs/developer-guide/working-with-rules#contextreport) accepts a single argument: an object containing information about the reported problem. It is recommended that all rules use the new API.
68

79
## Rule Details
810

911
This rule aims to disallow use of the deprecated `context.report(node, [loc], message)` API.
1012

11-
The following patterns are considered warnings:
13+
Examples of **incorrect** code for this rule:
1214

1315
```js
1416
module.exports = {
@@ -19,7 +21,7 @@ module.exports = {
1921

2022
```
2123

22-
The following patterns are not warnings:
24+
Examples of **correct** code for this rule:
2325

2426
```js
2527
module.exports = {

docs/rules/no-identical-tests.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# Disallow identical tests (no-identical-tests)
2-
3-
(fixable) The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) automatically fixes problems reported by this rule.
4-
5-
When a rule has a lot of tests, it's sometimes difficult to tell if any tests are duplicates. This rule would warn if any test cases have the same properties.
6-
7-
## Rule Details
8-
9-
Examples of **incorrect** code for this rule:
10-
11-
```js
1+
# Disallow identical tests (no-identical-tests)
2+
3+
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4+
5+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
6+
7+
When a rule has a lot of tests, it's sometimes difficult to tell if any tests are duplicates. This rule would warn if any test cases have the same properties.
8+
9+
## Rule Details
10+
11+
Examples of **incorrect** code for this rule:
12+
13+
```js
1214
/* eslint eslint-plugin/no-identical-tests: error */
1315

1416
new RuleTester().run('foo', bar, {
@@ -17,12 +19,12 @@ new RuleTester().run('foo', bar, {
1719
{ code: 'foo' },
1820
],
1921
invalid: [],
20-
});
21-
```
22-
23-
Examples of **correct** code for this rule:
24-
25-
```js
22+
});
23+
```
24+
25+
Examples of **correct** code for this rule:
26+
27+
```js
2628
/* eslint eslint-plugin/no-identical-tests: error */
2729

2830
new RuleTester().run('foo', bar, {
@@ -31,9 +33,9 @@ new RuleTester().run('foo', bar, {
3133
{ code: 'bar' },
3234
],
3335
invalid: [],
34-
});
35-
```
36-
37-
## When Not To Use It
38-
39-
If you want to allow identical tests, do not enable this rule.
36+
});
37+
```
38+
39+
## When Not To Use It
40+
41+
If you want to allow identical tests, do not enable this rule.

docs/rules/no-missing-placeholders.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Disallow missing placeholders in rule report messages (no-missing-placeholders)
22

3+
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4+
35
Report messages in rules can have placeholders surrounded by curly brackets.
46

57
```js

docs/rules/no-unused-placeholders.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Disallow unused placeholders in rule report messages (no-unused-placeholders)
22

3+
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4+
35
This rule aims to disallow unused placeholders in rule report messages.
46

57
## Rule Details

docs/rules/no-useless-token-range.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Disallow unnecessary calls to sourceCode.getFirstToken and sourceCode.getLastToken (no-useless-token-range)
22

3+
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4+
5+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
6+
37
AST nodes always start and end with tokens. As a result, the start index of the first token in a node is the same as the start index of the node itself, and the end index of the last token in a node is the same as the end index of the node itself. Using code like `sourceCode.getFirstToken(node).range[0]` unnecessarily hurts the performance of your rule, and makes your code less readable.
48

59
## Rule Details

docs/rules/prefer-object-rule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow rule exports where the export is a function. (prefer-object-rule)
22

3-
(fixable) The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) automatically fixes problems reported by this rule.
3+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
44

55
## Rule Details
66

docs/rules/prefer-output-null.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallows invalid RuleTester test cases with the output the same as the code. (prefer-output-null)
22

3-
(fixable) The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) automatically fixes problems reported by this rule.
3+
⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#-fix) can automatically fix some of the problems reported by this rule.
44

55
Instead of repeating the test case `code`, using `output: null` is more concise and makes it easier to distinguish whether a test case provides an autofix.
66

0 commit comments

Comments
 (0)