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.

Unintended indent for multiline template string argument combined with another multiline argument

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.3.0
  • Node Version: 8.1.3
  • npm Version: 5.0.3

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

I tried both default and babel-eslint. They’re giving me same result.

Please show your full configuration:

Configuration

{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": [
        "eslint:recommended"
    ],
    "rules": {
        "indent": ["error", 4]
    }
}

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


const f = (first, second) => {
    return second;
};

// works for multiline template strings
f(`
    multiline
    template
    string
`, `
    multiline
    template
    string
`);

// works for multiline objects
f({
    foo: 'foo',
    bar: 'bar',
}, {
    foo: 'foo',
    bar: 'bar',
});

// doesn't work for multiline template string and multiline object
f(`
    multiline
    template
    string
`, {
    foo: 'foo',
    bar: 'bar',
});


What did you expect to happen?

I expected all of the three examples will pass.

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

  31:1  error  Expected indentation of 8 spaces but found 4  indent
  32:1  error  Expected indentation of 8 spaces but found 4  indent
  33:1  error  Expected indentation of 4 spaces but found 0  indent

I believe the eslint fix is incorrect

 const f = (first, second) => {
     return second;
 };
 
 // works for multiline template strings
 f(`
     multiline
     template
     string
 `, `
     multiline
     template
     string
 `);

 // works for multiline objects
 f({
     foo: 'foo',
     bar: 'bar',
 }, {
     foo: 'foo',
     bar: 'bar',
 });

 // doesn't work for multiline template string and multiline object
 f(`
     multiline
     template
     string
 `, {
-    foo: 'foo',
-    bar: 'bar',
-});
+        foo: 'foo',
+        bar: 'bar',
+    });

Could you please confirm this is an unintended behaviour? Thank you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Dec 26, 2017

@not-an-aardvark Where are we at on this issue?

1reaction
not-an-aardvarkcommented, Aug 2, 2017

We actually have a test asserting the current behavior, so I think this is working as intended. I don’t recall if there was a specific reason why I added that test, though. I think I agree that your proposed behavior makes more sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper indentation for multiline strings? - python
Docstrings are treated specially: any indent of the first line is removed; the smallest common indent taken over all other non-blank lines is...
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 >
Strings and Templates - Configuration Language | Terraform
String literals and template sequences interpolate values and manipulate text. Learn about both quoted and heredoc string syntax.
Read more >
String.dedent details - ECMAScript Proposals
Problem. The current syntax forces users to choose between strange-looking unindented template literals, template literals containing unwanted indentation, or ...
Read more >
Google JavaScript Style Guide
To save space, you may wrap as close to 80 as possible, or put each argument on its own line to enhance readability....
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