Skip to content

ESLint: HTML classname ordering #4

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

Open
HugoMendes98 opened this issue Jul 8, 2023 · 0 comments
Open

ESLint: HTML classname ordering #4

HugoMendes98 opened this issue Jul 8, 2023 · 0 comments

Comments

@HugoMendes98
Copy link
Member

Context

As described here, the order of CSS classes in the class attribute does not matter.
So, to avoid conflicts, the alphabetical order is the preferred solution.

Bad:

<div class="my-class a-class"></div>

Good:

<div class="a-class my-class"></div>

Preliminary tasks

  • Find if a rule/plugin already exists
    • If so, set and configure
  • If not, create one
    • Not necessary for Nx-NestJS-Angular only, it could be a regular ESLint plugin used by anyone

The rule

In case no existing solution is found.

Even if the main priority is the class attribute, this ordering rule could be used to others.
For instance, if a custom attribute is used:

<div class="a b" tags="colors-blue-red-white"></div>

So it is more a eslint-html-attr-ordering plugin.

Specs

An error should be returned values inside an attribute are not ordered.

The rule should allow the following configuration:

  • Case sensitive: Does the case affects the ordering
  • Direction: Order the decorators a->z or z->a
  • Allow exceptions
    • With a regex match ?
  • Fixable (at least, by default)
  • Define separator
    • With a regex match ?
    • Default:
  • Does it need some special configuration for frameworks (Angular, React, Vue, ...)

The configuration should probably by an array.
It could look like:

{
  "myRule": [
      "warn",
      [
        {
          "attribute": "src",
          "caseSensitive": false
        },
        {
          "attribute": "tags",
          "except": ["color"],
          "separator": "-",
        }
      ]
    ]
}

Note:
If tailwind is set, then the eslint-plugin-tailwindcss should probably be used.

This rule's purpose is not to replace it, but to be an alternative and aims to be able to order other fields.

@HugoMendes98 HugoMendes98 added this to NNA Jul 2, 2023
@HugoMendes98 HugoMendes98 converted this from a draft issue Jul 8, 2023
@HugoMendes98 HugoMendes98 moved this from 🔖 Ready to 🏗 In progress in NNA Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

No branches or pull requests

1 participant