no-implicit-coercion autofixer can change logic
See original GitHub issueTell us about your environment
- ESLint Version: 3.6.1
- Node Version: 6.7.0
- npm Version: 3.10.3
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
rules:
no-implicit-coercion: error
What did you do? Please include the actual source code causing the issue.
Ran eslint --fix
on:
const catNoises = ["meow", "hiss", "purr"];
if (!~catNoises.indexOf("purr")) {
console.log("no purr");
} else {
console.log("yes purr");
}
What did you expect to happen?
Expected ESLint to autofix the code to:
const catNoises = ["meow", "hiss", "purr"];
if (catNoises.indexOf("purr") === -1) {
console.log("no purr");
} else {
console.log("yes purr");
}
Or just report the problem without trying to autofix it.
What actually happened? Please include the actual, raw output from ESLint.
ESLint autofixed the code to:
const catNoises = ["meow", "hiss", "purr"];
if (!catNoises.indexOf("purr") !== -1) {
console.log("no purr");
} else {
console.log("yes purr");
}
This autofix changes the logic of the code significantly.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
no-implicit-coercion - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >demo-outil-edition - node_modules - eslint - CHANGELOG.md
dd1e9f4 Fix: revert changes to key-spacing due to regression (#12598) (Kai ... 0541eaf Fix: no-implicit-coercion invalid autofix with ...
Read more >eslint: no-implicit-coercion for if conditionals - Stack Overflow
1 Answer 1 · Can I use this for boolean expected context like [0, 1, undefined, null, 2].filter((elem: number | null | undefined)...
Read more >Blog | HHVM
All built-in attributes have IDE hover documentation. Breaking Changes. lambdas contained within an anonymous function will no longer implicitly ...
Read more >Node.js API - ESLint - Breword 文档集合
lintFiles() method will throw an error when no target files are found. ... it also runs autofixing logic, similar to the --fix flag...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@not-an-aardvark makes a good point, although his example contains a concerning lack of animal noises.
On a similar note:
Lets just not auto fix
~
. Our policy is not to auto fix unless it can be done safely, and in this case we obviously can’t. (Trying to detect methods that return numbers is a step beyond what we should be doing.)