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.

seems to have no effect on class lists in template literals

See original GitHub issue

as an example:

<div
  className={`
    flex
    flex-col
    justify-between
    flex-1
    p-6
    bg-gradient-to-br
    bg-white
    from-white
    to-gray-200
    dark:bg-gray-800
    dark:from-gray-800
    dark:to-gray-900
    dark:text-gray-50
    ${className}
  `}
>

plugin seems to not operate on these strings, flattening them into a single line seems to not have any effect either

I have also tried randomly shuffling the class list to see if they were already sorted

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
sebastienbarrecommented, Mar 25, 2022

Hi @bradlc

I just gave this plugin a shot, and I’m seeing a similar behavior:

export const Hello = () => {
  const classNames = 'pt-2 p-4';
  return <div className="pt-2 p-4" />;
};

Notice how the second list of classes is fixed when I run prettier, but not the one in the variable:

$ ./node_modules/.bin/prettier Hello.jsx
export const Hello = () => {
  const classNames = 'pt-2 p-4';
  return <div className="p-4 pt-2" />;
};

Most of my components are build that way, here is a slightly less contrived example:

import clsx from 'clsx';

export const Hello = ({needPadding, needColors, className}) => {
  const classNames = clsx({
    'pt-2 p-4': needPadding,
    'bg-blue-700': needColors,
  }, className);
  return <div className={classNames} />;
};

In which case, again, 'pt-2 p-4' is not fixed either…

Thank you for the hard work

0reactions
quantuminformationcommented, Dec 5, 2022

I do it like this, because there will be a lot of dynamic building up of strings

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
javascript - Template literals like 'some ${string}' or "some ...
Save this question. Show activity on this post. I wanted to try using template literals and it's not working: it's displaying the literal...
Read more >
Restrict template literal interpolation expressions to strings
String literal templates only deal with strings; it seems well within the purpose of TypeScript to enforce that we can only pass them...
Read more >
Understanding Template Literals in JavaScript - DigitalOcean
With template literals, an expression can be embedded in a placeholder. A placeholder is represented by ${} , with anything within the curly ......
Read more >
8. Template literals - Exploring JS
A separate section explains how a template literal is turned into a list of arguments: the template object and the substitutions.
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