Sort tailwind classes for each elements className list by a given order-config

Overview

GitHub package.json version GitHub GitHub repo size

eslint-plugin-tailwind-classname-order

This eslint plugin automatically orders the tailwind classes included in the className tags from each element by the provided default order list.

Features

  • Order tailwind classes by given config
  • Recognize predefined classes
  • Recognize negative valued class names
  • Recognize states like hover,active,peer etc.
  • Recognize stacked states properly.
  • Recognize mediaquerys

Roadmap

  1. Remove the 'img' slug restriction for bg-images and be more flexible with custom defined values in general, by reading the projects tailwind.config.js.
  2. Include className objects that are not string typed instead of jsut ignoring them.
  3. Make custom ordering for the user more accessible and easier.

Currently supported tailwind classes

For the latest version the following tailwind classes are supported by the order plugin. Classes that are not yet included, will be treated as predefined custom classes. Classes are categorized as seen in the tailwind documentation here






It's mentionable that in the current version it's necessary, that when setting an image as background, which is predefined in the tailwind config, that the name of the image needs to include 'img' in its name, so that the plugin is able to identity it as such.

# will be detected as bg-img element
bg-MY-img-BACKGROUND

# won't be detected as bg-img and instead be treated as bg-color
bg-MY-BACKGROUND

Explicitly unsupported classes

Some classes in tailwind have counterparts with the same name and since interpreting arbitrary values is not supported on the current version, they won't be detected properly. There are two major differences:

  1. The plugin doesn't support arbitrary values in any way for the certain class. Even when they're predefined in the tw config file, they won't be interpreted properly.
  2. The plugin can't interpret arbitrary values when they're added inline, but the plugin will be able to detect the proper class, when the value is predefined in the config.
    This Problem will presumably be fixed with a future version.
  • Font Family (inline)
  • Text Color (inline)
  • Text Decoration Color (inline)
  • Background Size (arbitrary generally)
  • Background Position (arbitrary generally)
  • Stroke Color (inline)
  • Border Color (inline)
  • Outline Color (inline)
  • Ring Color (inline)
  • Ring Offset Color (inline)
  • Box Shadow Color (inline)

Default order config

  • predefined class

#browser behavior

  • box-sizing

#object reference - High priority because it refers to neighboring content

  • peer
  • group

#object identity, positioning (where)

  • position
  • (position) top, right, bottom, left
  • visibility
  • z-index

#object identity, sizing (how)

  • (flex) flex width
  • (flex) basis
  • container
  • width
  • width-min
  • width-max
  • height
  • height-min
  • height-max
  • aspect-ratio

#object identity, core identity (what)

  • display

#flex identity, core flex identity (what flex)

  • (flex) direction (row/col)
  • (flex) wrap

#grid identity, core grid identity (what grid)

  • (grid) grid-cols (grid-template-columns)
  • (grid) grid-column
  • (grid) grid-rows (grid-template-rows)
  • (grid) grid-row
  • (grid) grid-flow
  • (grid) auto-cols
  • (grid) auto-rows
  • (grid) justify items
  • (grid) justify self
  • (grid) align content

#flex/grid identity, core flex/grid identity (what flex/grid)

  • (flex / grid) justify-content
  • (flex / grid) align-items
  • (flex / grid) align self
  • (flex / grid) gap (x, y)

#object identity, environmental behaviour

  • place items
  • place content
  • place self
  • padding-x
  • padding-y
  • padding (top, right, bottom, left)
  • margin-x
  • margin-y
  • margin (top, right, bottom, left)
  • space between (x, y)
  • float
  • clear
  • isolation

#object identity modification

  • transform (x, y, rotate, scale, skew)
  • transform origin

#content behaviour

  • object fit
  • object position
  • overflow
  • overscroll
  • order
  • break-before
  • break-after
  • break-inside
  • box decoration break

#styling - content / text related

  • whitespace

#text styling

  • font-family
  • font-size
  • font smoothing
  • font-weight
  • font-style
  • font-variant-numeric
  • tracking (letter spacing)
  • leading (line-height)
  • list style type
  • list style position
  • text alignment
  • text-color
  • text-transform
  • text-overflow
  • text-decoration
  • text-decoration-color
  • text-decoration-style
  • text-decoration-thickness
  • text-underline-offset
  • text-indent
  • word break
  • vertical align
  • pseudo-class content

#body behaviour

  • opacity

#body styling

  • background (url, repeat, pos, size)
  • background-attachment
  • background-clip
  • background-color
  • background-origin
  • gradient color stops
  • mix-blend-mode
  • background blend mode
  • (svg) fill
  • (svg) stroke color
  • (svg) stroke width
  • border (style, width, radius)
  • border-color
  • divide (x, y)
  • divide color
  • divide-style
  • outline-width
  • outline-style
  • outline-offset
  • ring width
  • ring color
  • ring offset width
  • ring offset color
  • box-shadow
  • box-shadow-color

#table styling

  • border-collapse
  • border-spacing
  • table-layout

#filters

  • blur
  • brightness
  • contrast
  • drop-shadow
  • grayscale
  • hue-rotate
  • invert
  • saturate
  • sepia
  • backdrop blur
  • backdrop brightness
  • backdrop contrast
  • backdrop grayscale
  • backdrop hue rotate
  • backdrop invert
  • backdrop opacity
  • backdrop saturate
  • backdrop sepia

#transitions & animation

  • transition (property, duration, timing function, delay)
  • animate

#interactivity

  • accent-color
  • appearance
  • cursor
  • caret-color
  • pointer events
  • resize
  • scroll behavior
  • scroll padding (x, y)
  • scroll margin (x, y)
  • scroll snap align
  • scroll snap stop
  • scroll snap type
  • touch action
  • user select
  • will-change

#accesiblility

  • screen readers

#state management

States are priority wise in the same order as they are presented on the tailwind docs (states), excluding the @media type prefixes.

#media queries

This plugin supports the default breakpoint prefixes as listed on the tailwind docs for responsive design.
Furthermore more custom prefixes are also already added. The orderConfig.json file can of course be altered to include even more custom breakpoint prefixes.

  • xs
  • sm
  • md
  • 2md
  • lg
  • 2lg
  • xl
  • 2xl
  • 3xl

Installation

You'll first need to install ESLint:

With npm

# via npm
npm install eslint --save-dev

# via yarn
yarn add -D eslint

Next, install eslint-plugin-tailwind-classname-order:

# via npm
npm install @aacn_org/eslint-plugin-tailwind-classname-order --save-dev

# via yarn
yarn add -D @aacn_org/eslint-plugin-tailwind-classname-order

Usage

Add tailwind-classname-order to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "@aacn_org/tailwind-classname-order"
    ]
}

Then configure the rules you want to use under the rules section.
This includes the path to the rule file and its severity
More about eslints severity can be found here

{
    "rules": {
        "@aacn_org/tailwind-classname-order/order": 2
    }
}
You might also like...

An npm package with Tailwind CSS utility classes for creating responsive grid columns without media queries using auto fit.

Grid Auto Fit for Tailwind CSS A plugin that helps you create a responsive grid layout in Tailwind CSS without using media queries. It uses the auto-f

Dec 28, 2022

Given a list of items, only render what's visible on the screen while allowing scrolling the whole list.

Solid Windowed Given a list of items, only render what's visible on the screen while allowing scrolling the whole list. A Solid component. See https:/

Dec 21, 2022

The awesomebooks project is a simple list, but separated into 3 parts and given a retro feel. The main page is where we can add books, and on another page we can see the list, and remove items. There is also a "contact-us" page.

Awesome Books This is the restructured version of the famous awesome-books project! Here you can find JavaScript broken into modules, using import-exp

Nov 15, 2022

This project is a To-do list app which users can store and edit their Todo Tasks. Users can also change the order of their todo

Project This project is about a todo app bundling using webpack Additional description about the project and its features. Built With HTML CSS Javascr

Jun 17, 2022

Sort tsconfig.json compilerOptions

sort-compiler-options Sort tsconfig.json compilerOptions in the same order as the TSConfig Reference (Support v4.5.5 or less) Install npm i sort-compi

Oct 19, 2022

Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks)

Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks)

eleventy-plugin-directory-output Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks). Sample output from eleven

Oct 27, 2022

A small CLI to sort any specified json files alphabetically

This is a small CLI to sort any specified json files alphabetically. This was created to sort localization files, but maybe you will find another use case.

Mar 20, 2022

⛲ Sort import declarations into a pleasing and readable cascade.

⛲ eslint-plugin-cascading-imports This plugin allows to automatically enforce a visual "cascading" order for import declarations. Imports in each bloc

Jan 20, 2022

Sort imports by path - VS Code extension

Import sort by absolute path The sorting algorithm will group each item in the array and sort (alphabetically) its children that starts with the path

Feb 2, 2022
Releases(v0.2.7)
Owner
aacn
AACN Software- und Systementwicklung GmbH
aacn
🤖 Tailwind CSS assistant helps you to edit classes (includes JIT & ignores purge), toggle breakpoint classes on an element and view current breakpoint

Tailwind CSS Assistant See it in action on this example website ?? ✅ Small JavaScript package that helps you work with Tailwind CSS by... Showing you

Mark Mead 30 Dec 28, 2022
Add the `className` to all JSX elements in your project

Babel Plugin Transform JSX Classes This babel plugin adds the className in each JSX element. Before After function FancyComponent () { return (

Xinhe 13 Jul 15, 2022
BookStore is a website that allows a given user to view a list of books, to add a new book and remove a given book.

Project Name : BookStore CMS BookStore is a website that allows a given user to view a list of books, to add a new book and remove a given book. In or

Chris Siku 10 Aug 22, 2022
Create a deep copy of a set of matched elements with the dynamic state of all form elements copied to the cloned elements.

jq-deepest-copy FUNCTION: Create a deep copy of a set of matched elements while preserving the dynamic state of any matched form elements. Example Use

Michael Coughlin 5 Oct 28, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
🪢 A really tiny library that generates classname strings.

cnz (“classnamez”) The smallest classnames-compatible package yet (I think). This is an extremely simple javascript utility for conditionally joining

Riley Shaw 6 Dec 15, 2022
A lightweight extension to automatically detect and provide verbose warnings for embedded iframe elements in order to protect against Browser-In-The-Browser (BITB) attacks.

Enhanced iFrame Protection - Browser Extension Enhanced iFrame Protection (EIP) is a lightweight extension to automatically detect and provide verbose

odacavo 16 Dec 24, 2022
Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Khalid Abuhakmeh 5 Feb 16, 2022