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.

Extra spaces in html tagged templates

See original GitHub issue

Prettier 1.19.1 Playground link

--parser babel

Input:

const label = html`<span>${text}</span>`;

Output:

const label = html`
  <span>${text}</span>
`;

Expected behavior:

Adding whitespace inside the tagged template literal affects the output. To avoid the spaces around my components, the only way right now is to add ignore comments.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
saschanazcommented, Dec 11, 2019

That doesn’t even need an option then! Sounds good to me 👍

1reaction
DiogoDoretocommented, Dec 11, 2019

@saschanaz I’d vote to keep it simple: if the user tries to have it as one-liner and the line is not too long, avoid adding the line breaks. Otherwise leave the default formatting behavior.

This will create an incentive to the user to simplify their content, possibly extracting it into simple variables that would be easier to read.

It then will behave in a similar way as this example:

// the line below is left as-is
const obj = [{ test: true }];

// the code below will be reformatted with line breaks
// input:
const obj = [{ 
  test: true }];
// output:
const obj = [
  {
    test: true
  }
];

What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Easy Ways to Insert Spaces in HTML - HubSpot Blog
The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as   or...
Read more >
21 Using template literals and tagged templates - Exploring JS
Before we dig into the two features template literal and tagged template, let's first examine the multiple meanings of the term template.
Read more >
How to create string with multiple spaces in JavaScript
With template literals, you can use multiple spaces or multi-line strings and string ... You can use the <pre> tag with innerHTML.
Read more >
Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >
Handling whitespace in ES6 template literals - 2ality
A tag function like common-tag's stripIndent can help: ... Additionally, leading and trailing whitespace is trimmed.
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