Skip to content
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

Fix: Remove autofixer for no-unsafe-negation #12157

Merged
merged 1 commit into from Sep 13, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions lib/rules/no-unsafe-negation.js
Expand Up @@ -51,7 +51,7 @@ module.exports = {
},

schema: [],
fixable: "code",
fixable: null,
messages: {
unexpected: "Unexpected negating the left operand of '{{operator}}' operator."
}
Expand All @@ -70,15 +70,7 @@ module.exports = {
node,
loc: node.left.loc,
messageId: "unexpected",
data: { operator: node.operator },

fix(fixer) {
const negationToken = sourceCode.getFirstToken(node.left);
const fixRange = [negationToken.range[1], node.range[1]];
const text = sourceCode.text.slice(fixRange[0], fixRange[1]);

return fixer.replaceTextRange(fixRange, `(${text})`);
}
data: { operator: node.operator }
});
}
}
Expand Down
6 changes: 0 additions & 6 deletions tests/lib/rules/no-unsafe-negation.js
Expand Up @@ -34,32 +34,26 @@ ruleTester.run("no-unsafe-negation", rule, {
invalid: [
{
code: "!a in b",
output: "!(a in b)",
errors: [unexpectedInError]
},
{
code: "(!a in b)",
output: "(!(a in b))",
errors: [unexpectedInError]
},
{
code: "!(a) in b",
output: "!((a) in b)",
errors: [unexpectedInError]
},
{
code: "!a instanceof b",
output: "!(a instanceof b)",
errors: [unexpectedInstanceofError]
},
{
code: "(!a instanceof b)",
output: "(!(a instanceof b))",
errors: [unexpectedInstanceofError]
},
{
code: "!(a) instanceof b",
output: "!((a) instanceof b)",
errors: [unexpectedInstanceofError]
}
]
Expand Down