-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: implicit-arrow-linebreak adds extra characters (fixes #11268) #11407
Conversation
…heses, add condition to check for arrow expressions with block statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I have a few questions.
…ction to tests for implicit arrow linebreak
Thanks for continuing to work on this! I'm probably missing something given that the tests are passing, but could you clarify which part of the change prevents the extra closing parentheses from being added? I would have guessed the change happens due to one fewer loop iteration on line 111, but it seems like that only applies to nodes containing nested arrow functions, which isn't the case for the example from #11268. |
@not-an-aardvark This line in the code prevents extra closing parentheses from being added by navigating to the body of the arrow function, and this line prevents the appending of extra parentheses. |
Both of those lines are in the |
@not-an-aardvark Thanks for clarifying! Given the example code from #11268 start()
.then(() =>
/* If I put a comment here, eslint --fix breaks badly */
process && typeof process.send === 'function' && process.send('ready')
)
.catch(err => {
/* catch seems to be needed here */
console.log('Error: ', err)
}) when
And the output for this test case hello(response =>
// comment
response, param => param) becomes // comment
hello(response => response, param => param) Prior to this PR, The JSDoc for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ x ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
Fixes 11268
What changes did you make? (Give an overview)
The original auto-fix calculated white spaces into formatting comments and parentheses, which was the cause for extra characters.
The cause for extra parentheses was due to this line, which searched for arrow functions that followed the evaluated arrow function within the source code.
This PR removes the calculation of white spaces, and more accurately finds nested arrow functions within the evaluated node.
Is there anything you'd like reviewers to focus on?
Please provide/suggest any other test cases if necessary.