Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable formatting for class names in html? #487

Open
csntr opened this issue May 27, 2024 · 2 comments
Open

How to enable formatting for class names in html? #487

csntr opened this issue May 27, 2024 · 2 comments
Labels
enhancement New feature or request pr welcome

Comments

@csntr
Copy link

csntr commented May 27, 2024

I almost completely covered all my formatting and linting needs but there is still 1 thing which is that classes are just not getting formatted.

class="test-sm
                  ml-2
            overflow-hidden
            white-space-nowrap text-overflow-ellipsis"

If I leave this in one line then max length complains. Essentially nothing is fixed that is inside the class, I can leave empty spaces, bad tabbing or anything there.

In my eslint config I currently have:

export default withNuxt(
  antfu(
    {
      formatters: {
        css: true,
        html: true,
      },
      lessOpinionated: true,
    },
    {
      rules: {
        'style/max-len': ['error', 80, { ignoreComments: true }],
        'vue/max-attributes-per-line': ['error', {
          singleline: {
            max: 1,
          },
          multiline: {
            max: 1,
          },
        }],
      },
    },
  ),
)

Any help would be greatly appreciated! Thank you!

@zanfee
Copy link
Contributor

zanfee commented Jun 1, 2024

Tailwind Labs is experimenting with an update for their prettier plugin that addresses the whitespace problem and removes duplicate class names: https://x.com/reinink/status/1795907080139743709?t=bsdvHa7L9oFaa52owAf8ww&s=19

Not sure if this is the right way to include this in this config as there is an UnoCSS ESLint config aswell. But might still be useful as a resource or workaround when it's ready.

@antfu
Copy link
Owner

antfu commented Jun 12, 2024

To do that properly, we would need an HTML parser in ESLint. There are a few in the community but I haven't done the research. I don't usually work on HTML files directly so there is little incentive for me to work on that any sooner. But open for proposes (ideally it would be handle in the UnoCSS plugin)

@antfu antfu added enhancement New feature or request pr welcome labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

No branches or pull requests

3 participants