Skip to content

Commit 0fc99af

Browse files
aladdin-addnot-an-aardvark
authored andcommitted
Update: add --fix to prefer-output-null. (#44)
1 parent cf563fb commit 0fc99af

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Name | ✔️ | 🛠 | Description
5656
[no-missing-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-missing-placeholders.md) | ✔️ | | Disallows missing placeholders in rule report messages
5757
[no-unused-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-unused-placeholders.md) | ✔️ | | Disallows unused placeholders in rule report messages
5858
[no-useless-token-range](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-useless-token-range.md) | ✔️ | 🛠 | Disallows unnecessary calls to sourceCode.getFirstToken and sourceCode.getLastToken
59-
[prefer-output-null](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-output-null.md) | | | Disallows invalid RuleTester test cases with the output the same as the code.
59+
[prefer-output-null](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-output-null.md) | | 🛠 | Disallows invalid RuleTester test cases with the output the same as the code.
6060
[prefer-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-placeholders.md) | | | Disallows template literals as report messages
6161
[report-message-format](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/report-message-format.md) | | | Enforces a consistent format for report messages
6262
[require-meta-fixable](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-fixable.md) | ✔️ | | Requires a `meta.fixable` property for fixable rules

docs/rules/prefer-output-null.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule.
4+
35
## Rule Details
46

57
The rule reports an error if it encounters a test case where the output is the same as the code.

lib/rules/prefer-output-null.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
category: 'Tests',
1919
recommended: false,
2020
},
21-
fixable: null,
21+
fixable: 'code',
2222
schema: [],
2323
},
2424

@@ -52,8 +52,9 @@ module.exports = {
5252

5353
if (output && sourceCode.getText(output.value) === sourceCode.getText(code.value)) {
5454
context.report({
55-
node: test,
55+
node: output,
5656
message,
57+
fix: fixer => fixer.replaceText(output.value, 'null'),
5758
});
5859
}
5960
});

tests/lib/rules/prefer-output-null.js

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ ruleTester.run('prefer-output-null', rule, {
5858
]
5959
});
6060
`,
61+
output: `
62+
new RuleTester().run('foo', bar, {
63+
valid: [],
64+
invalid: [
65+
{code: 'foo', output: null, errors: ['bar']},
66+
]
67+
});
68+
`,
6169
errors: [ERROR],
6270
},
6371
],

0 commit comments

Comments
 (0)