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

Fix: wrong indent at tagged template in indent (fixes #12122) #12596

Merged
merged 7 commits into from Jan 17, 2020
Merged

Fix: wrong indent at tagged template in indent (fixes #12122) #12596

merged 7 commits into from Jan 17, 2020

Conversation

yeonjuan
Copy link
Member

@yeonjuan yeonjuan commented Nov 24, 2019

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)

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

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Nov 24, 2019
@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules indent Relates to the `indent` rule and removed triage An ESLint team member will look at this issue soon labels Nov 25, 2019
@yeonjuan yeonjuan changed the title Fix: check tag in tagged template literal in indent (fixes #12122) Fix: check tag in tagged template in indent (fixes #12122) Nov 28, 2019
lib/rules/indent.js Outdated Show resolved Hide resolved
lib/rules/indent.js Outdated Show resolved Hide resolved
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. Thank you!

@mysticatea
Copy link
Member

I'm not sure... but I couldn't reproduce it on v6.7.2: online demo.

@mysticatea
Copy link
Member

I could reproduce it if an interpolation exists: online demo

Therefore, I think that this bug exists around the logic of template literals rather than function calls. I'm suspecting that the indent rule doesn't set desired offsets to the tokens of TemplateElement nodes.

@yeonjuan
Copy link
Member Author

yeonjuan commented Dec 20, 2019

@mysticatea

I'm suspecting that the indent rule doesn't set desired offsets to the tokens of TemplateElement nodes.

oh yes, It's right. I think I should change the code in this pr. thanks!

@yeonjuan
Copy link
Member Author

yeonjuan commented Dec 20, 2019

@mysticatea
I changed the test cases, including expressions within template literals.
And I tried to set the desired offset to the token of TemplateElement but I couldn't because it makes another change in the bellow cases.

const a = 2,
    template = `
    multiline ${
    expression} template literal`; // Error; 

so, what about just add logic within the function which checking function call(same as current pr)?

@mysticatea
Copy link
Member

I got it. In that case, I'm OK with fixing the logic of function calls.

@yeonjuan yeonjuan changed the title Fix: check tag in tagged template in indent (fixes #12122) Fix: use tag in tagged template in indent (fixes #12122) Dec 25, 2019
@yeonjuan
Copy link
Member Author

yeonjuan commented Dec 31, 2019

plz, don't merge it. I'm sorry. It needs more checks. done.

@yeonjuan yeonjuan changed the title Fix: use tag in tagged template in indent (fixes #12122) Fix: wrong indent at tagged template in indent (fixes #12122) Jan 2, 2020
@yeonjuan
Copy link
Member Author

yeonjuan commented Jan 4, 2020

@kaicataldo
Sorry for changing the code after review. But I realized that the previous version does not work correctly. The previous version uses tag as an offset token. It could solve the bug in a tagged template indent.

tag`
   ${a}
  `(() => {
      tag`
        ${a}
        `(() => {

    });
});

But it had problems in cases if there are member expressions with a tagged template.

tag
   .member`
   ${a}
  `(() => {

}); // expected indent, but no error.

So, I changed the code to use a token before quasi as an offset token. So now, it solves the usual tagged template indent issues. You can check it in test cases.

{
code: unIndent`
foo(() => {
tagOne\`
multiline
template
literal
\${a} \${b}
\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
});
`,

code: unIndent`
foo
.bar\` template
literal \`(() => {
baz();
})
`,

I re-request a review. Sorry for wasting your efforts.

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.

Sorry for the delay. Still getting caught up on my notifications backlog from the holidays.

This mostly LGTM! Just one small comment about using a token to offset instead of the full node. Thank you for adding all these test cases 😃

lib/rules/indent.js Outdated Show resolved Hide resolved
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 for working on this!

@btmills btmills merged commit de4fa7c into eslint:master Jan 17, 2020
montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
…slint#12596)

* Fix: check tag in tagged template literal in indent (fixes eslint#12122)

* refactor, add test cases

* rename variable name, delete comment

* change test case

* change offsetToken to token before the node.callee.quasi

* refactor code, add more test cases

* use token for consistency
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 17, 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 Jul 17, 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 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

4 participants