Giter Site home page Giter Site logo

blooper05 / eslint-plugin-tailwindcss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from francoismassart/eslint-plugin-tailwindcss

0.0 1.0 0.0 860 KB

ESLint plugin for Tailwind CSS usage

Home Page: https://www.npmjs.com/package/eslint-plugin-tailwindcss

License: MIT License

JavaScript 100.00%

eslint-plugin-tailwindcss's Introduction

eslint-plugin-tailwindcss

npm (scoped) npm bundle size (scoped)

eslint-plugin-tailwindcss logo

Rules enforcing best practices and consistency using Tailwind CSS v2.1.2

๐ŸŽ‰ Since v1.5.0, the plugin will parse the tailwind.config.js file and use the correct values based on your own settings.

๐Ÿ‘ Most of the new JIT mode features are also supported.

detected-errors

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-tailwindcss:

$ npm i eslint-plugin-tailwindcss --save-dev

eslint-plugin-tailwindcss on npm

Usage

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

{
  "plugins": ["tailwindcss"]
}

Configure the rules you want to use under the rules section.

{
  "rules": {
    "tailwindcss/classnames-order": "warn",
    "tailwindcss/no-custom-classname": "warn",
    "tailwindcss/no-contradicting-classname": "error"
  }
}

Learn more about Configuring Rules in ESLint.

Optional shared settings

Most rules shares the same settings, instead of duplicating some options...

You should also specify settings that will be shared across all the plugin rules. More about eslint shared settings.

All these settings have nice default values that are explained in each rules' documentation. I'm listing them in the code below just to show them.

{
  "settings": {
    "tailwindcss": {
      // These are the default values but feel free to customize
      "callees": ["classnames", "clsx", "ctl"],
      "config": "tailwind.config.js",
      "groups": defaultGroups, // imported from groups.js
      "prependCustom": false,
      "removeDuplicates": true,
      "whitelist": []
    }
  }
}

The plugin will look for each setting value in this order and stop looking as soon as it finds the settings:

  1. In the rule option argument (rule level)
  2. In the shared settings (plugin level)
  3. Default value of the requested setting (plugin level)...

Supported Rules

Learn more about each supported rules by reading their documentation:

  • classnames-order: order classnames by target properties then by variants ([size:][theme:][state:])
  • no-custom-classname: only allow classnames from Tailwind CSS and the values from the whitelist option
  • no-contradicting-classname: e.g. avoid p-2 p-3, different Tailwind CSS classnames (pt-2 & pt-3) but targeting the same property several times for the same variant.

Upcoming Rules

  • no-redundant-variant: e.g. avoid mx-5 sm:mx-5, no need to redefine mx in sm: variant as it uses the same value (5)

Alternatives

I wrote this plugin after searching for existing tools which perform the same task but didn't satisfied my needs:

Contributing

You are welcome to contribute to this project by reporting issues, feature requests or even opening Pull Requests.

Learn more about contributing to ESLint-plugin-TailwindCSS.

eslint-plugin-tailwindcss's People

Contributors

francoismassart avatar adamlindqvist avatar zweimach avatar natancieplinski avatar ntkoopman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.