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: Account for comments in implicit-arrow-linebreak #10545
Conversation
…ow and expression body in implicit-arrow-linebreak
Hmm... It seems like this fix is improving current behavior, but I'm not 100% sure this is the best way. In the last example you showed, the only reasonable way to fix it based on your approach would be to move all of the comments above the line: // hi
// there
(foo) =>bar => braz; However, chances are, if there's a chaining like that, comments describe what each step of the chain is doing, and if you move them above, it would be unclear. I think best way to fix that would be to change line comments into inline comments. (foo) => /* hi */ bar => /* there */ braz; But that might not work and might possibly change the meaning of the code. So I'm not sure what would be the best way to do that. |
I think the best solution would be to just not do an autofix if a line comment is found in that location. We have a similar behavior with if (foo) // comment
{
} |
I'd expect: (foo) =>
// hi
bar =>
// there
braz; to become: (foo) => (
// hi
bar => (
// there
braz
)
); |
@ljharb @not-an-aardvark @ilyavolodin Thanks for all of your input. It seems like prepending the arrow functions with parentheses clarifies the intent of the comments. I will go ahead and implement this change. |
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.
Looks good 👍 thanks for fixing this bug!
@sharmilajesupaul Thanks for the review and comments! Still working on the above test case as well as when:
Should be finished by tomorrow or early Wednesday. |
@peanutenthusiast instead of trying to find the parent and placing the comment before it. What if you got the line number from the node range and placed the comment on the line before that with a prepended Also, does this account for cases where you are in an object, or a method chain, or array? eg: const foo = {
id: 'bar'
prop: (foo1) =>
// comment
'returning this string',
}
[ foo =>
// comment
'bar'
]
"foo".split('').map((char) =>
// comment
`-${char}-`
)) can you add test cases for those? ^ |
@sharmilajesupaul will need to account for the aforementioned test cases as well. thanks! |
@sharmilajesupaul Would the expected output for the method chain test case be
or (probably nicer on the eyes)
? |
@peanutenthusiast The paren linebreak is handled by There might be cases where you do want the paren on it's own line: "foo".split('').map(
(char) =>
`-${char}-`,
) I think that might be out of the scope of this PR. |
this seems like it needs a fresh rebase |
@ljharb agreed and working on it. |
…function bodies, pass cases
…expression, pass test cases, create helper for formatting comments
…w expression and parens
…-arrow-linebreak, begin implementation for condition
…nutenthusiast/eslint into fix-implicit-arrow-linebreak
hey @peanutenthusiast! is this ready for another review? |
Yes!
…On Tue, Dec 4, 2018 at 5:13 PM Sharmila Jesupaul ***@***.***> wrote:
hey @peanutenthusiast <https://github.com/peanutenthusiast>! is this
ready for another review?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10545 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/Aa-ISTkZKKdXwI4v_Ay3_rbsHsKqe_e7ks5u1x2vgaJpZM4U9zaM>
.
|
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.
Small change request for readability, otherwise looking good!
@peanutenthusiast Sorry we lost track of this! @platinumazure have your changes been addressed? @ilyavolodin @not-an-aardvark thoughts on moving this forward? |
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.
Looks good to me, I'm okay to merge when the team accepts.
Should this be marked as a bug rather than an enhancement? Fixers generally shouldn't be deleting comments. |
This PR is labeled as "enhancement" but the commit summary says "Fix". Is this a bug fix or an enhancement? |
I'm going to re-label it as a bug -- I think the original labelling was a mistake. |
Thanks for contributing @peanutenthusiast and for your saintly patience as we processed this! |
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:
Implicit-arrow-linebreak
does not take comments into consideration when the option for the rule isbeside
.When the rule evaluates the expression:
The outcome is:
The proposed fix is:
What changes did you make? (Give an overview)
tests/lib/rules/implicit-arrow-linebreak
Is there anything you'd like reviewers to focus on?
outcome
with the test case of? This one was a doozy.
@sharmilajesupaul