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
implicit-arrow-linebreak autofixer sometimes adds extra characters #11268
implicit-arrow-linebreak autofixer sometimes adds extra characters #11268
Comments
Hi, thanks for the report. I can reproduce this issue. The |
I'll look into this. |
Hi @peanutenthusiast, just checking in to see if you've had a chance to work on this. |
@not-an-aardvark you can expect a PR by tomorrow afternoon/early evening! thank you for your patience |
another falling case:
=>
|
…11407) * add failing test case * Add specified test case from issue * Remove calculation for white spaces from formatComments and addParentheses, add condition to check for arrow expressions with block statements * Fix linting errors, ensure npm test runs without fail * Change new test case to check for prepended comment, add unIndent function to tests for implicit arrow linebreak * Add optional token type to arrow body * Add failing test case * Remove null return from autofixBesides, refactor body setting lines to use .body * Fix linting errors * Fix linting error in unIndent rule in implicit arrow linebreak test * Add another test case where nested arrow function contains block statement * Add constraint for block statement in add parentheses
Currently, the implicit-arrow-linebreak rule contains a lot of logic to determine how comments should be adjusted in code when an autofix is needed. The goal is to be able to autofix cases where there is a comment between an arrow token and the start of an arrow function body. Most other core rules simply decide not to fix cases when there is a comment interfering with the fix. This logic accounts for a large fraction of the code in the rule, and seems to require a lot of different code for many individual cases. Unfortunately, bugs keep being reported identifying problems in the rule (e.g. #11268, #11521) and it's not clear that the fixes are moving us closer to making the rule correct in general, given that there are always more cases than we can explicitly account for. To address those problems, this commit updates the implicit-arrow-linebreak rule to just skip autofixing when comments interfere, rather than trying to do an autofix anyway and find an alternate location for the comments. I'm reluctant to make this change given that a lot of time has been invested in the autofixing logic, but I think this is ultimately a better solution than trying to guess where the user wants their comments to go, and crashing/producing incorrect code if we get it wrong.
…#11522) Currently, the implicit-arrow-linebreak rule contains a lot of logic to determine how comments should be adjusted in code when an autofix is needed. The goal is to be able to autofix cases where there is a comment between an arrow token and the start of an arrow function body. Most other core rules simply decide not to fix cases when there is a comment interfering with the fix. This logic accounts for a large fraction of the code in the rule, and seems to require a lot of different code for many individual cases. Unfortunately, bugs keep being reported identifying problems in the rule (e.g. #11268, #11521) and it's not clear that the fixes are moving us closer to making the rule correct in general, given that there are always more cases than we can explicitly account for. To address those problems, this commit updates the implicit-arrow-linebreak rule to just skip autofixing when comments interfere, rather than trying to do an autofix anyway and find an alternate location for the comments. I'm reluctant to make this change given that a lot of time has been invested in the autofixing logic, but I think this is ultimately a better solution than trying to guess where the user wants their comments to go, and crashing/producing incorrect code if we get it wrong.
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint
(but i dont believe it matters)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?
Code that it "fixes" should not be invalid javascript
What actually happened? Please include the actual, raw output from ESLint.
It creates broken code
Are you willing to submit a pull request to fix this bug?
not really, wouldnt know where to start
This can get REALLY bad and is especially an issue since its part of
eslint-config-airbnb
, granted this file is crazy, but the bug ends up filling the entire file up with thousands of invalid linesThe text was updated successfully, but these errors were encountered: