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.

Tag function (lit-html) breaks arrow function in multiple lines

See original GitHub issue

I have an oneliner arrow func smaller than printWidth that keeps being breaked in various lines just because of a html lit-html call inside of it.

Prettier 1.16.1 Playground link

Input:

    const result = this.myProp.map(i => html`<li>${this.myMethod(i)}</li>`)

Output:

    const result = this.myProp.map(
      i =>
        html`
          <li>${this.myMethod(i)}</li>
        `
    )

Expected behavior:

    const result = this.myProp.map(i => html`<li>${this.myMethod(i)}</li>`)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
thorn0commented, May 6, 2020
1reaction
jridgewellcommented, Mar 7, 2019

Hitting this as part of AMP HTML’s transition to prettier. Formatting of embedded languages in JS files should be disable-able at a minimum.

This should be given a much higher priority, as this formatting changes the runtime evaluation of the code. This probably means it should be disabled by default.

function html(strings) {
  console.assert(
    strings.join("") === "<div></div>",
    "this will throw because of prettier!"
  );
}

html`<div></div>`;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrow function expressions - JavaScript - MDN Web Docs
The braces can only be omitted if the function directly returns an expression. If the body has additional lines of processing, the braces...
Read more >
Single-Line to Multi-Line ES6 Fat Arrow Function?
I'm learning ES6 fat arrow functions.
Read more >
13. Arrow functions
1. Arrow functions bind very loosely; 13.5. · 2. No line break after arrow function parameters; 13.5. · 3. You can't use statements...
Read more >
ES6 Arrow Functions Cheatsheet | SamanthaMing.com
We have several ways of writing our arrow functions. This is because arrow functions can have either "implied return" or "explicit return" keyword....
Read more >
Keyboard Shortcuts
Select all text, Ctrl + A, Cmd + A. Copy text, Ctrl + C, Cmd + C ... Go to the right or...
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