question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected indent error inside template string after ESLint bump from 4.3.0 to 4.4.1

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.4.1
  • Node Version: 8.3.0
  • npm Version: 5.3.0

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint

Please show your full configuration:

Configuration
parser: babel-eslint

extends: airbnb

What did you do? Please include the actual source code causing the issue.

const MyComponent = styled.div`
  margin: 0;
  ${(value) => {
    noop();
    return `
      ${value}
    `;
  }}
`; // ← This line triggers an indent error

What did you expect to happen?

I expected no errors.

If the inline arrow function is transformed so the curly braces are removed, the indent error is gone:

const MyComponent = styled.div`
  ${value => `
    ${value}
  `}
`;

What actually happened? Please include the actual, raw output from ESLint.

Since I updated from ESLint 4.3.0 to 4.4.1, the last line in that template string triggers the indent rule.

   9:1  error  Expected indentation of 2 spaces but found 0  indent

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Aug 15, 2017

But can you tell me specific reason why this kind of change was necessary? I’m not sure enforcing users to change their code like this is really worth it…

The indent rule is supposed to validate your code’s indentation. Previously, it was not doing that in a large number of cases. This was causing a lot of confusion for users, because they were accidentally writing code with incorrect indentation, and expecting the indent rule to catch it. (In fact, when we rewrote the rule, indent bugs accounted for about 15% of our open issues.)

If you’d like to restore the indent behavior from 3.x, you can use the indent-legacy rule. If you’d like to ignore indentation for code like your example, you can use the MemberExpression: off option in the indent rule.

0reactions
not-an-aardvarkcommented, Aug 25, 2017

Ok, thanks for checking again. I’m going to close this since it doesn’t seem to be an issue with eslint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What should I do with "Unexpected indent" in Python?
Expected an indented block. This line of code has the same number of spaces at the start as the one before, but the...
Read more >
Unintended indent for multiline template string argument ...
I expected all of the three examples will pass. What actually happened? Please include the actual, raw output from ESLint. 31:1 error Expected ......
Read more >
@typescript-eslint/eslint-plugin | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Changelog - JavaScript Standard Style
This pre-release exists to test out the ESLint 8 related changes and discover possible backwards incompatible changes that comes with it and mitigate...
Read more >
How do i resolve the unexpected indent error in python
Unindent does not match any outer indentation level. This line of code has fewer spaces at the start than the one before, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found