Skip to content

Commit f90478c

Browse files
authored
docs: modernize rule doc for prefer-object-rule (eslint-community#264)
1 parent 3d97c75 commit f90478c

File tree

3 files changed

+9
-40
lines changed

3 files changed

+9
-40
lines changed

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/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
```

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)