Skip to content

Update: add --fix to prefer-output-null. #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Name | ✔️ | 🛠 | Description
[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
[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
[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
[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.
[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.
[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
[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
[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
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/prefer-output-null.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Disallows invalid RuleTester test cases with the output the same as the code. (prefer-output-null)

(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule.

## Rule Details

The rule reports an error if it encounters a test case where the output is the same as the code.
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/prefer-output-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
category: 'Tests',
recommended: false,
},
fixable: null,
fixable: 'code',
schema: [],
},

Expand Down Expand Up @@ -52,8 +52,9 @@ module.exports = {

if (output && sourceCode.getText(output.value) === sourceCode.getText(code.value)) {
context.report({
node: test,
node: output,
message,
fix: fixer => fixer.replaceText(output.value, 'null'),
});
}
});
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/prefer-output-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ ruleTester.run('prefer-output-null', rule, {
]
});
`,
output: `
new RuleTester().run('foo', bar, {
valid: [],
invalid: [
{code: 'foo', output: null, errors: ['bar']},
]
});
`,
errors: [ERROR],
},
],
Expand Down