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: fix indent behavior on template literal arguments (fixes #9061) #9820

Merged
merged 1 commit into from Jan 10, 2018

Conversation

not-an-aardvark
Copy link
Member

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

[x] Bug fix (#9061)

What changes did you make? (Give an overview)

This updates the indent rule to handle multiline template arguments correctly to fix the issue described in #9061.

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

Nothing in particular

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint indent Relates to the `indent` rule rule Relates to ESLint's core rules labels Jan 7, 2018
@@ -442,6 +442,7 @@ class OffsetStorage {
const offset = (
offsetInfo.from &&
offsetInfo.from.loc.start.line === token.loc.start.line &&
!/^\s*?\n/.test(token.value) &&
Copy link
Member Author

Choose a reason for hiding this comment

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

This addition was necessary due to JSX behavior. When parsing code like this:

<a>
    <b>
    </b>
</a>

There is a hidden JSXText (or Literal) token between <a> and <b>, containing a newline followed by whitespace. The indent rule had previously been relying on the old template literal behavior to ensure that the <b> tag would get indented properly.

In other words, the indent rule would previously indent the above code in effectively the same manner as the below code:

a(`
    `, { // (this object is like the `b` tag)
    }, `
`);

However, by fixing this bug it would no longer possible to treat the two pieces of code in the same way anymore. The fix is to modify the token collapsing behavior (which checks whether two tokens are on the same line) to consider two tokens to be on separate lines if the second token starts with a newline character.

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 enhancement This change enhances an existing feature of ESLint indent Relates to the `indent` rule rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants