You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Improve detection of fix functions that never return a fix in fixer-return rule (#143)
Behavior changes:
1. Catch fix functions that have a return statement but never actually return a fix (i.e. fix functions that only ever return undefined or similar values that are obviously not fixes).
2. Allow fix functions to have some code paths that do not return a fix (it's allowed for a fix function to bail out / return early and avoid fixing in some situations).
I would consider these both bug fixes to reduce false positives and false negatives.
Copy file name to clipboardExpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ Then configure the rules you want to use under the rules section.
47
47
Name | ✔️ | 🛠 | Description
48
48
----- | ----- | ----- | -----
49
49
[consistent-output](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/consistent-output.md) | | | enforce consistent use of output assertions in rule tests
50
-
[fixer-return](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/fixer-return.md) | ✔️ | | require fixer function to always return a value.
50
+
[fixer-return](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/fixer-return.md) | ✔️ | | require fixer function to return a fix
51
51
[meta-property-ordering](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/meta-property-ordering.md) | | 🛠 | enforce the order of meta properties
52
52
[no-deprecated-context-methods](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-context-methods.md) | | 🛠 | disallow usage of deprecated methods on rule context objects
53
53
[no-deprecated-report-api](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-report-api.md) | ✔️ | 🛠 | disallow use of the deprecated context.report() API
Copy file name to clipboardExpand all lines: docs/rules/fixer-return.md
+20-7
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# Enforces always return from a fixer function (fixer-return)
1
+
# Require fixer function to return a fix (fixer-return)
2
2
3
3
✔️ The `"extends": "plugin:eslint-plugin/recommended"` property in a configuration file enables this rule.
4
4
5
-
In a fixable rule, missing return from a fixer function will not apply fixes.
5
+
In a [fixable](https://eslint.org/docs/developer-guide/working-with-rules#applying-fixes) rule, a fixer function is useless if it never returns anything.
6
6
7
7
## Rule Details
8
8
9
-
This rule enforces that fixer functions always return a value.
9
+
This rule enforces that a fixer function returns a fix in at least one situation.
10
10
11
11
Examples of **incorrect** code for this rule:
12
12
@@ -17,7 +17,7 @@ module.exports = {
17
17
create (context) {
18
18
context.report({
19
19
fix (fixer) {
20
-
fixer.foo();
20
+
fixer.insertTextAfter(node, 'foo');
21
21
},
22
22
});
23
23
},
@@ -33,13 +33,26 @@ module.exports = {
33
33
create (context) {
34
34
context.report({
35
35
fix (fixer) {
36
-
returnfixer.foo();
36
+
returnfixer.insertTextAfter(node, 'foo');
37
37
},
38
38
});
39
39
},
40
40
};
41
41
```
42
42
43
-
## When Not To Use It
43
+
```js
44
+
/* eslint eslint-plugin/fixer-return: error */
44
45
45
-
If you don't want to enforce always return from a fixer function, do not enable this rule.
0 commit comments