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.

prefer-template autofix adds extra spaces inside placeholders.

See original GitHub issue

Tell us about your environment

Node version: v14.5.0 npm version: v6.14.5 Global ESLint version: v7.3.1 (Currently used)

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

parser: default (unconfigured)

Please show your full configuration:

Configuration
{
  "rules": {
    "prefer-template": "error"
  }
}

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

var foo = 'a';
var baz = 'bar' + foo;
var quz = foo + 'bar';
var quuz = 'bar'  +  foo;
eslint --fix main.js

What did you expect to happen? I expected to get the following file:

var foo = 'a';
var baz = `bar${foo}`;
var quz = `foo${bar}`;
var quuz = `bar${foo}`;

What actually happened? Please include the actual, raw output from ESLint. I got the following file:

var foo = 'a';
var baz = `bar${  foo}`;
var quz = `${foo  }bar`;
var quuz = `bar${    foo}`;

Essentially, the spaces around the concatenation operator end up inside the placeholder. For example, in quux’s definition, there are two spaces on each side of the +, and there are four spaces inside the resulting placeholder.
ESLint’s output is as follows:

/path/to/my/project/main.js
  3:11  error  Parsing error: Unexpected character '`'

✖ 1 problem (1 error, 0 warnings)

Which I find strange, since the resulting code is valid JS.

Are you willing to submit a pull request to fix this bug? Yes, if I knew where the bug would most likely be. I haven’t looking in ESLint’s codebase before.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Jul 6, 2020

You should also set "parserOptions": { "ecmaVersion": 2015 } (or higher).

1reaction
kaicataldocommented, Jul 3, 2020

Agreed that the output looks weird, but I don’t know if removing all the whitespace is necessarily more correct in this case. Each autofixer is intended to make as small a change as possible, and to enforce the style you’re expecting you can use template-curly-spacing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules - ESLint - Pluggable JavaScript Linter
Rules in ESLint are grouped by type to help you understand their purpose. Each rule has emojis denoting: ✓ Recommended. The "extends": "eslint:recommended" ......
Read more >
stylelint-scss | Yarn - Package Manager
A collection of SCSS specific linting rules for Stylelint (in a form of a plugin). ... Added: at-import-partial-extension autofix only when "never" (#608) ......
Read more >
grid-auto-rows - CSS: Cascading Style Sheets - MDN Web Docs
The grid-auto-rows CSS property specifies the size of an implicitly-created grid row track or pattern of tracks.
Read more >
eslint - UNPKG
... Update: key-spacing loc changes for extra space (refs #12334) (#13362) (Anix) ... Docs: Adds import example for object-curly-newline rule (refs #12018) ...
Read more >
Release notes - Visual Composer Help Center
New: HubSpot form compatiblity element added to the Visual Composer Hub (HubSpot ... Update: Popup builder bottom placeholders removed for cleaner user ...
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