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: Improve report location newline-per-chained-call (refs #12334) #13116

Merged
merged 2 commits into from Apr 4, 2020

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

What is the purpose of this pull request? (put an "X" next to an item)

[X] Other, please explain:

refs #12334

Change reported location in the newline-per-chained-call rule.

This shouldn't produce any new warnings because it doesn't change the start line.

What changes did you make? (Give an overview)

Changed location to the full location of . or [, instead of start location of the property node.

Before:

image

After:

image

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

This looks like a big visual change. I chose this among many alternatives because it matches the place where the fixer inserts newline, and it's a common place to insert the newline manually (either on the left or on the right side). Also, the message starts with ./[

@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Mar 29, 2020
Copy link
Member

@kaicataldo kaicataldo 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!

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Since we want to draw attention to the property, not just the dot, what do people think about specifying the location to start with the dot and end at the end of the property? (To me underlining only the dot looks strange, but happy to go along with consensus.)

@kaicataldo
Copy link
Member

I think @nzakas’s suggestion makes sense, particularly since that’s what the error message reports. 👍

@mdjermanovic mdjermanovic added the needs bikeshedding Minor details about this change need to be discussed label Apr 2, 2020
@mdjermanovic
Copy link
Member Author

Agreed, it would be great if we could think of something better than the dot.

I found some possible problems with other solutions, which would also apply to underlining the dot and the property together.

Error message Expected line break before '.foo'. is technically incorrect, because this rule expects a newline anywhere before the property (between the object and the property nodes), not necessarily before the dot. User can insert the newline after the dot:

/*eslint newline-per-chained-call: error*/

// lint-free
a.b().c().
    foo();

So it might be more correct to start underlining from the property node, like it already works in the actual version?

Also, this rule targets computed properties as well. These property nodes can be multiline, e.g.:

/*eslint newline-per-chained-call: error*/

// Expected line break before `[f({`
a().b()[f({
 prop: 1 
})]();

Should we, in this case, underline the whole property or maybe just the first token? Or perhaps only part of the property that is on the same line with the object, similar to how the error message works in the actual version (function getPropertyText).

@nzakas
Copy link
Member

nzakas commented Apr 3, 2020

I think including the dot is fine as I’d expect we would include the opening bracket for computed properties. While the dot case message might not be 100%, I think it’s close enough and it seems most people like the break before the dot.

For long computed properties, I’d prefer to see the whole property underlined but only the first part in the actual error message.

@mdjermanovic
Copy link
Member Author

I think including the dot is fine as I’d expect we would include the opening bracket for computed properties. While the dot case message might not be 100%, I think it’s close enough and it seems most people like the break before the dot.

For long computed properties, I’d prefer to see the whole property underlined but only the first part in the actual error message.

This should be done now.

Some examples:

image

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM

@kaicataldo kaicataldo merged commit a784dac into master Apr 4, 2020
@kaicataldo kaicataldo deleted the newlineperchainedcall-loc branch April 4, 2020 03:54
@kaicataldo
Copy link
Member

Thanks for contributing!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Oct 2, 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 Oct 2, 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 enhancement This change enhances an existing feature of ESLint needs bikeshedding Minor details about this change need to be discussed rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants