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 range bug with no-extra-boolean-cast #11324
Fix range bug with no-extra-boolean-cast #11324
Comments
Does the source file have a byte-order-mark at the start? Fix ranges from ESLint don't include a BOM when calculating positions, so if you're piping results from ESLint into an external tool to apply fixes, you might need to remove the BOM from the source text yourself before passing it to the external tool. |
I don't have a byte order mark and other offsets work fine for me. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Reopening as this slipped through the cracks. We at least need to try to reproduce this before closing. |
Source: "var bar = 1;\nvar foo = !!bar ? 'true' : 'false';\n" Error: {
"ruleId": "no-extra-boolean-cast",
"severity": 2,
"message": "Redundant double negation.",
"line": 2,
"column": 12,
"nodeType": "UnaryExpression",
"messageId": "unexpectedNegation",
"endLine": 2,
"endColumn": 16,
"fix": { "range": [23, 28], "text": "bar" }
} I think that:
For comparison, this is {
"ruleId": "no-implicit-coercion",
"severity": 2,
"message": "use `Boolean(bar)` instead.",
"line": 2,
"column": 11,
"nodeType": "UnaryExpression",
"endLine": 2,
"endColumn": 16,
"fix": { "range": [23, 28], "text": "Boolean(bar)" }
} |
@mdjermanovic Nice work. I think we can accept this issue based on that investigation. ...This raises an interesting thought. Should the autofix logic allow a fix range outside of the range of the reported node? |
I'll fix this soon.
Could be very interesting to test this, perhaps it would find similar bugs in other rules. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
The information about the location of the fix appears to be off. Running
--fix
applies the fix correctly but the response from the JSON output is off (which means that other external tools cannot apply the fix).I would expect the location information to be something like:
Looking at AST Explorer seems to have the right location information.
https://astexplorer.net/#/gist/b5517bff697af4446176699497517e36/8f1a35f7594886e63d855960a1649120071963d4
What actually happened? Please include the actual, raw output from ESLint.
Are you willing to submit a pull request to fix this bug? With help potentially. I'm unfamiliar with how rules output the position information.
The text was updated successfully, but these errors were encountered: