npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-sort-attribute-content

v0.3.0

Published

An ESLint plugin to sort decorators

Downloads

486

Readme

eslint-plugin-sort-attribute-content

CI npm version Code coverage

An ESLint plugin to sort attribute content in HTML

If you are using Tailwind and only want to lint the classnames, then the eslint-plugin-tailwindcss is probably a better choice.

Installation

First, eslint must be installed:

npm i --save-dev eslint

Then, eslint-plugin-sort-attribute-content can be installed:

npm i --save-dev eslint-plugin-sort-attribute-content

Usage

A parser must be set to use this plugin:

{
  "parser": "@html-eslint/parser"
}

Go to the parsers section to display the list of available parsers.

The plugin can then be activated by adding sort-attribute-content to the plugins property:

{
  "plugins": ["sort-attribute-content"]
}

The rule can be defined as follows:

{
  "rules": {
    "sort-attribute-content/sort-attribute-content": ["error", { "attributes": "class" }]
  }
}

All this configuration can be done on a override section: https://eslint.org/docs/latest/use/configure/configuration-files#how-do-overrides-work

Parsers

The plugin can be used with multiple parsers.

HTML

A regular HTML parser can be used for any HTML files.
The parser @html-eslint/parser should be installed first:

npm i -D @html-eslint/parser

Then set in the configuration file:

{
  "parser": "@html-eslint/parser"
}

Angular

This plugin can be used with the Angular framework.
The parser @angular-eslint/template-parser should be installed first:

npm i -D @angular-eslint/template-parser

Then set in the configuration file:

{
  "parser": "@angular-eslint/template-parser"
}

Note:
It only works for text attributes.

<div class="a b c" [title]="'d e f'"></div>
            ^^^^^

React

This plugin can be used with the React library.
ESLint must first be configured to read React.

How to configure?

Once enabled, it will work on jsx and tsx files.

Do not forget to set the typescript parser for tsx files.

Install:

npm i -D @typescript-eslint/parser

Then set in the configuration file:

{
  "parser": "@typescript-eslint/parser"
}

It might be useful to enable the rule only on these files:

{
  "overrides": [
    {
      "files": ["*.jsx", "*.tsx"],
      "rules": {
        "sort-attribute-content/sort-attribute-content": ["error", { "attributes": "className" }]
      }
    }
  ]
}

Note:
It only works for literal text attributes.

return <div className="a b c" title={title} />
                       ^^^^^

Rules

🔧 Automatically fixable by the --fix CLI option.

| Name | 🔧 | | :------------------------------------------------------------- | :- | | sort-attribute-content | 🔧 |

Releases

See information about breaking changes and release notes here.