GithubHelp home page GithubHelp logo

filipekiss / stylelint-color-format Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 2.0 32 KB

Stylelint plugin to convert HEX colors to either RGB or HSL

License: MIT License

JavaScript 100.00%
stylelint stylelint-plugin npm npm-package linter-plugin css sass scss code-quality

stylelint-color-format's Introduction

stylelint-color-format

CircleCI TravisCI Status XO code style code style: prettier NPM version

A Stylelint plugin to convert HEX colors to either RGB or HSL formats.

Installation

npm install --save-dev stylelint-color-format

Configuration

In your Stylelint Configuration, add the following to the plugins array. (Make sure the plugins array comes before your rules block):

{
  "plugins": ["stylelint-color-format"]
}

And then, in the rules:

{
  "rules": {
    "color-format/format": {
      "format": "rgb"
    }
  }
}

Usage

The rule itself works much like the default color-no-hex rule. It will report if a HEX color format (#333, #CA4FBD and even #FFFFFFAB) is found, it will error out since the format is not what we want. If you pass the --fix option, however, the color format will be converted to either rgb or hsl, according to your configuration

Configuration

The color-format/format rule accepts an object with a single format key.

rgb | rgba

This will convert any HEX colors to RGB. If the HEX color has a transparency, the RGBA format will be used.

hsl | hsla

This will convert any HEX colors to HSL. If the HEX color has a transparency, the HSLA format will be used.

LICENSE - MIT

stylelint-color-format's People

Contributors

dependabot[bot] avatar filipekiss avatar jm3 avatar remcohaszing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stylelint-color-format's Issues

Update peer dependency comatibility

Currently it is not compatible with stylelint 12+

npm WARN [email protected] requires a peer of stylelint@^8.0.0 || ^9.0.0 but none is installed. You must install peer dependencies yourself.

A new release to npm will also be necessary

Change other format than hex

By setting the rule as below, I thought all colors would be formatted to hsl, but it turns out only hex errors are reported and fixed.

'color-format/format': {
      format: 'hsl',
},

Maybe we can have an option to also format the other color type (in this case, format rgb to hsl too)? I thought of something like:

'color-format/format': {
      format: 'hsl',
      types: 'all' | 'hex',
},

Unable to parse stylelint configuration: Undefined rule color-format/format

With the instructions and config verbatim from the README:

npm install --save-dev stylelint stylelint-color-format
+ [email protected]
+ [email protected]
added 147 packages from 122 contributors, updated 1 package and audited 12749 packages in 5.202s
found 0 vulnerabilities

project .stylelintrc:

{ "rules": {
    "color-format/format": { "format": "rgb" }
  },
  {
    "plugins": ["stylelint-color-format"]
 }
}

Atom returns:
Unable to parse stylelint configuration: Undefined rule color-format/format
Unable to parse stylelint configuration- Undefined rule color-format format

Typo in README ?

hsl | hsla

This will convert any HEX colors to HSL. If the HEX color has a transparency, the RGBA format will be used.

RGBA HSLA

Feature: Support shorthand notations

--fix can't handle colors in shorthand notations, e.g.:

  border: 6px solid #8ddbe3;
Error: Unable to parse color from string: 6px solid #8ddbe3

Feature: Support rounding?

After running stylelint --fix the diff looks like this:

-@tag-color: #33b4c0;
+@tag-color: hsl(185.10000000000002, 58%, 47.6%);

It may be the correct H value but what about an option to round the values to n decimal points?

Custom message

Please, add the ability to provide custom error message or if it's already implemented, add docs. I tried the following but unsuccessfully:

"color-format/format": {
  "format": "hsl",
  "message": "Consider using HSL."
}
"color-format/format": [{
  "format": "hsl",
  "message": "Consider using HSL."
}]
"color-format/format": {
  "format": "hsl",
  "message": "Consider using HSL."
}
"color-format/format": [
  "hsl",
  {
    "message": "Consider using HSL."
  }
]

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.