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.

indent issue with tagged template literals

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.2.0
  • Node Version: 10.16.3
  • npm Version: 6.9.0

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

Please show your full configuration:

Configuration
{
  "env": {
    "es6": true,
    "jest/globals": true
  },
  "plugins": ["jest"],
  "rules": {
    "indent": [
      "error", 2, {
      "SwitchCase": 1,
      "VariableDeclarator": 1,
      "outerIIFEBody": 1,
      "FunctionDeclaration": {
        "parameters": 1,
        "body": 1
      },
      "FunctionExpression": {
        "parameters": 1,
        "body": 1
      },
      "CallExpression": {
        "arguments": 1
      },
      "ArrayExpression": 1,
      "ObjectExpression": 1,
      "ImportDeclaration": 1,
      "flatTernaryExpressions": false,
      "ignoredNodes": [
        "JSXElement", "JSXElement > *", "JSXAttribute", "JSXIdentifier", "JSXNamespacedName", "JSXMemberExpression", "JSXSpreadAttribute", "JSXExpressionContainer", "JSXOpeningElement", "JSXClosingElement", "JSXText", "JSXEmptyExpression", "JSXSpreadChild"
      ],
      "ignoreComments": false
    }]
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.


describe('Indentation Bug', () => {

  test.each`
    a    | b
    ${1} | ${1}
  `('$a == $b', ({ a, b }) => {
    expect(a).toBe(b); // error  Expected indentation of 2 spaces but found 4  indent
  }); // error  Expected indentation of 0 spaces but found 2  indent
});
eslint .

What did you expect to happen? I would expect the code indentation to be valid.

What actually happened? Please include the actual, raw output from ESLint. Following eslint errors are displayed:

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

I’ve created a small repo where you can easily reproduce the issue. https://github.com/msvab/eslint-tagged-literal-indent-bug

Are you willing to submit a pull request to fix this bug? I can try, but I have zero knowledge on eslint internals.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
bochapcommented, Oct 2, 2019

It might take some time to get familiar with inner workings Eslint but I am interested in taking this up.

1reaction
DotCoyotecommented, Nov 21, 2019

It’s still closed though 😉 I’d really like to get this fixed too, as I have to disable the indent rule on test-files otherwise…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore the indentation in a template literal, with the ESLint ...
I know that ternary expressions, like used in this code, is a ConditionalExpression node, and it seems like a template literal node exists,...
Read more >
Multiline template strings that don't break indentation
Solution 1: Ignore all space and tab characters following a newline until the first non-space or tab character. The problem with this is...
Read more >
Prettify your JavaScript strings - Adam Coster
There is another common problem with strings in code: indentation in multiline strings. Template literals allow us to put breaks in our ...
Read more >
Triple-backtick template literal with indentation support - TC39
Effectively, every tagged template literal function needs to build in dedent behaviour, or be ok with ugly code, or ugly outputs. Is it...
Read more >
keywords:dedent - npm search
An ES6 string tag that strips indentation from multi-line strings ... ES2015 tagged template string for removing indent from strings.
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