Skip to content
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

Update: false positives in function-call-argument-newline (fixes #12123) #12280

Merged
merged 2 commits into from Oct 25, 2019

Conversation

scottohara
Copy link
Contributor

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:

What changes did you make? (Give an overview)

Fixes #12123

Given two adjacent arguments (a & b), the rule logic was previously:

  1. let prevArgToken be the first token of a
  2. let currentArgToken be the first token of b
  3. compare the start line number of prevArgToken with the start line number of currentArgToken

This meant that the following examples were treated as invalid, despite the linebreaks between arguments being correct for the specified option:

/*eslint function-call-argument-newline:["error", "never"] */
fn({
 a: 1
}, b);

/*eslint function-call-argument-newline:["error", "consistent"] */
fn({
 a: 1
}, b, c);

Changed the rule logic to be:

  1. let prevArgToken be the last token of a
  2. let currentArgToken be the first token of b
  3. compare the end line number of prevArgToken with the start line number of currentArgToken

Valid & invalid tests added for each of the three options (always, never, consistent).

All new & all existing unit tests are passing.

Is there anything you'd like reviewers to focus on?

Nothing in particular

@jsf-clabot
Copy link

jsf-clabot commented Sep 18, 2019

CLA assistant check
All committers have signed the CLA.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Sep 18, 2019
@mdjermanovic
Copy link
Member

Hi @scottohara, thanks for the PR!

Just to note that #12123 isn't accepted as a bug yet. It could be the correct behavior as well, or the rule might need an additional option to further customize the behavior in these cases with multiline arguments.

The proposed solution seems logical and I believe that it solves the problem from #12123. But, it can produce more warnings in some other cases, so I'm labeling this as an enhancement for now since it has to be evaluated.

@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Sep 18, 2019
@klimashkin
Copy link

@mdjermanovic What is the evaluation process? #12123 has been closed by the bot

@mdjermanovic
Copy link
Member

It's reopened now

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 17, 2019
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in the rule LGTM and I think that the tests cover the getLastToken changes well.

Could we please also add some tests for the three loc.end changes? For example, this is an error at the moment, before this fix:

/* eslint function-call-argument-newline: ["error", "never"] */

f(`
`, a);

Online Demo Link

Also, the PR title should start with Update, because this change can produce more errors in some cases.

@mdjermanovic
Copy link
Member

I forgot this - the PR title should also contain the name of this rule

@scottohara scottohara changed the title Fix: false positives on newlines in object/array arguments Update: fix function-call-argument-newline false positives on newlines in object/array arguments Oct 18, 2019
@scottohara scottohara changed the title Update: fix function-call-argument-newline false positives on newlines in object/array arguments Update: fix false positives in function-call-argument-newline (fixes #12123) Oct 18, 2019
@scottohara scottohara changed the title Update: fix false positives in function-call-argument-newline (fixes #12123) Update: false positives in function-call-argument-newline (fixes #12123) Oct 18, 2019
@scottohara
Copy link
Contributor Author

Thanks for the review @mdjermanovic.

I've added additional tests for the multi-line template string case as requested, and updated the PR title

With a long rule name like function-call-argument-newline, it was hard to get the title under 72-chars while still including both the Update: prefix and a (fixes #xxx) issue reference. Hopefully the current title is descriptive enough.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic mdjermanovic removed the enhancement This change enhances an existing feature of ESLint label Oct 22, 2019
Copy link
Member

@platinumazure platinumazure left a 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 contributing! Sorry for the delay in getting this in.

Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@scottohara scottohara deleted the function-call-argument-newline branch November 27, 2019 02:41
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 24, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

function-call-argument-newline complains in some cases when it logically shouldn't.
6 participants