Skip to content

Commit fc10130

Browse files
committed
Merge branch 'main' into recommended-v5
* main: docs: modernize rule doc for `no-identical-tests` (eslint-community#265) docs: modernize rule doc for `require-meta-schema` (eslint-community#266) docs: modernize rule doc for `prefer-object-rule` (eslint-community#264) docs: modernize rule doc for `consistent-output` (eslint-community#263) chore: run version-specific CI jobs on Node 18 (eslint-community#260)
2 parents 83fa414 + d6d79aa commit fc10130

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

.github/workflows/main.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/checkout@v3
3434
- uses: actions/setup-node@v3
3535
with:
36-
node-version: "16.x"
36+
node-version: "18.x"
3737
- run: npm install
3838
- run: npm run lint
3939

@@ -43,18 +43,18 @@ jobs:
4343
- uses: actions/checkout@v3
4444
- uses: actions/setup-node@v3
4545
with:
46-
node-version: "16.x"
46+
node-version: "18.x"
4747
- run: npm install
4848
- run: npm install --save-dev eslint@6
4949
- run: npm test
50-
50+
5151
eslint7:
5252
runs-on: ubuntu-latest
5353
steps:
5454
- uses: actions/checkout@v3
5555
- uses: actions/setup-node@v3
5656
with:
57-
node-version: "16.x"
57+
node-version: "18.x"
5858
- run: npm install
5959
- run: npm install --save-dev eslint@7
6060
- run: npm test

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Name | ✔️ | 🛠 | 💡 | Description
7474
[no-unused-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-unused-placeholders.md) | ✔️ | | | disallow unused placeholders in rule report messages
7575
[no-useless-token-range](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-useless-token-range.md) | ✔️ | 🛠 | | disallow unnecessary calls to `sourceCode.getFirstToken()` and `sourceCode.getLastToken()`
7676
[prefer-message-ids](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-message-ids.md) | ✔️ | | | require using `messageId` instead of `message` to report rule violations
77-
[prefer-object-rule](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-object-rule.md) | ✔️ | 🛠 | | disallow rule exports where the export is a function
77+
[prefer-object-rule](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-object-rule.md) | ✔️ | 🛠 | | disallow function-style rules
7878
[prefer-output-null](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-output-null.md) | ✔️ | 🛠 | | disallow invalid RuleTester test cases where the `output` matches the `code`
7979
[prefer-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-placeholders.md) | | | | require using placeholders for dynamic report messages
8080
[prefer-replace-text](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-replace-text.md) | | | | require using `replaceText()` instead of `replaceTextRange()`

docs/rules/consistent-output.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Enforce consistent use of `output` assertions in rule tests (consistent-output)
22

3-
When writing tests for fixable rules, it's a best practice to use the `output` property on each test case to assert what autofixed code is produced, or to assert that no autofix is produced using `output: null`.
3+
When writing tests for fixable rules, the `output` property on each test case can be used to assert what autofixed code is produced, or to assert that no autofix is produced using `output: null`.
44

55
Prior to ESLint 7, it was easy to forget to assert the autofix output of a particular test case, resulting in incomplete test coverage and a greater chance of unexpected behavior / bugs.
66

7-
[As of ESLint 7](https://eslint.org/docs/user-guide/migrating-to-7.0.0#additional-validation-added-to-the-ruletester-class), test cases that trigger an autofix are required to provide the `output` property.
7+
[As of ESLint 7](https://eslint.org/docs/user-guide/migrating-to-7.0.0#additional-validation-added-to-the-ruletester-class), test cases that trigger an autofix are required by ESLint to provide the `output` property. Thus, it's now acceptable and more concise to omit this property when there's no autofix.
88

99
## Rule Details
1010

@@ -69,6 +69,8 @@ This rule takes an optional string enum option with one of the following values:
6969

7070
If you're not writing fixable rules, or you want to write test cases without output assertions, do not enable this rule.
7171

72+
As mentioned in the introduction, the need for this rule is reduced as of ESLint v7.
73+
7274
## Further Reading
7375

7476
* [`RuleTester` documentation](http://eslint.org/docs/developer-guide/working-with-plugins#testing)

docs/rules/no-identical-tests.md

+26-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@
44

55
⚒️ 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.
66

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.
7+
Duplicate test cases can cause confusion, can be hard to detect manually in a long file, and serve no purpose.
8+
9+
As of [ESLint v9](https://github.com/eslint/rfcs/tree/main/designs/2021-stricter-rule-test-validation#disallow-identical-test-cases), ESLint attempts to detect and disallow duplicate tests.
810

911
## Rule Details
1012

13+
This rule detects duplicate test cases.
14+
1115
Examples of **incorrect** code for this rule:
1216

1317
```js
1418
/* eslint eslint-plugin/no-identical-tests: error */
1519

1620
new RuleTester().run('foo', bar, {
17-
valid: [{ code: 'foo' }, { code: 'foo' }],
18-
invalid: [],
21+
valid: [
22+
'foo',
23+
'foo', // duplicate of previous
24+
],
25+
invalid: [
26+
{
27+
code: 'bar',
28+
errors: [{ messageId: 'my-message', type: 'CallExpression' }],
29+
},
30+
{
31+
code: 'bar',
32+
errors: [{ messageId: 'my-message', type: 'CallExpression' }],
33+
}, // duplicate of previous
34+
],
1935
});
2036
```
2137

@@ -25,11 +41,12 @@ Examples of **correct** code for this rule:
2541
/* eslint eslint-plugin/no-identical-tests: error */
2642

2743
new RuleTester().run('foo', bar, {
28-
valid: [{ code: 'foo' }, { code: 'bar' }],
29-
invalid: [],
44+
valid: ['foo', 'bar'],
45+
invalid: [
46+
{
47+
code: 'baz',
48+
errors: [{ messageId: 'my-message', type: 'CallExpression' }],
49+
},
50+
],
3051
});
3152
```
32-
33-
## When Not To Use It
34-
35-
If you want to allow identical tests, do not enable this rule.

docs/rules/prefer-object-rule.md

+7-38
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
# Disallow rule exports where the export is a function (prefer-object-rule)
1+
# Disallow function-style rules (prefer-object-rule)
22

33
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
44

55
⚒️ 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.
66

7+
Prior to ESLint v9, ESLint supported both [function-style](https://eslint.org/docs/developer-guide/working-with-rules-deprecated) and [object-style](https://eslint.org/docs/developer-guide/working-with-rules) rules. However, function-style rules have been deprecated since 2016, and do not support newer features like autofixing and suggestions.
8+
9+
As of [ESLint v9](https://github.com/eslint/rfcs/tree/main/designs/2021-schema-object-rules#motivation-for-requiring-object-style-rules), ESLint supports only object-style rules.
10+
711
## Rule Details
812

9-
The rule reports an error if it encounters a rule that's defined using the [deprecated style](https://eslint.org/docs/developer-guide/working-with-rules-deprecated) of just a `create` function instead of the newer [object style](https://eslint.org/docs/developer-guide/working-with-rules).
13+
The rule reports an error if it encounters a rule that's defined using the deprecated function-style format.
1014

1115
Examples of **incorrect** code for this rule:
1216

1317
```js
1418
/* eslint eslint-plugin/prefer-object-rule: error */
1519

16-
module.exports = function (context) {
17-
return {
18-
Program() {
19-
context.report();
20-
},
21-
};
22-
};
23-
2420
module.exports = function create(context) {
2521
return {
2622
Program() {
2723
context.report();
2824
},
2925
};
3026
};
31-
32-
module.exports = (context) => {
33-
return {
34-
Program() {
35-
context.report();
36-
},
37-
};
38-
};
3927
```
4028

4129
Examples of **correct** code for this rule:
@@ -44,6 +32,7 @@ Examples of **correct** code for this rule:
4432
/* eslint eslint-plugin/prefer-object-rule: error */
4533

4634
module.exports = {
35+
meta: { /* ... */ },
4736
create(context) {
4837
return {
4938
Program() {
@@ -52,24 +41,4 @@ module.exports = {
5241
};
5342
},
5443
};
55-
56-
module.exports = {
57-
create(context) {
58-
return {
59-
Program() {
60-
context.report();
61-
},
62-
};
63-
},
64-
};
65-
66-
module.exports = {
67-
create: (context) => {
68-
return {
69-
Program() {
70-
context.report();
71-
},
72-
};
73-
},
74-
};
7544
```

docs/rules/require-meta-schema.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
💡 Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
66

7-
Defining a schema for each rule allows eslint to validate that configuration options are passed correctly. Even when there are no options for a rule, a schema should still be defined (as an empty array) so that eslint can validate that no data is mistakenly passed to the rule.
7+
Defining a schema for each rule allows eslint to validate that configuration options are passed correctly. Even when there are no options for a rule, a schema can still be defined as an empty array to validate that no data is mistakenly passed to the rule.
8+
9+
As of [ESLint v9](https://github.com/eslint/rfcs/tree/main/designs/2021-schema-object-rules#motivation-for-requiring-schemas), ESLint will validate that options are not provided to a rule when a schema is omitted.
810

911
## Rule Details
1012

@@ -75,6 +77,10 @@ This rule takes an optional object containing:
7577

7678
* `boolean``requireSchemaPropertyWhenOptionless` — Whether the rule should require the `meta.schema` property to be specified (with `schema: []`) for rules that have no options. Defaults to `true`.
7779

80+
## When Not To Use It
81+
82+
As mentioned in the introduction, the need for this rule is reduced as of ESLint v9.
83+
7884
## Further Reading
7985

8086
* [working-with-rules#options-schemas](https://eslint.org/docs/developer-guide/working-with-rules#options-schemas)

lib/rules/prefer-object-rule.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
meta: {
1616
type: 'suggestion',
1717
docs: {
18-
description: 'disallow rule exports where the export is a function',
18+
description: 'disallow function-style rules',
1919
category: 'Rules',
2020
recommended: true,
2121
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/prefer-object-rule.md',

0 commit comments

Comments
 (0)