GithubHelp home page GithubHelp logo

kristerkari / stylelint-z-index-value-constraint Goto Github PK

View Code? Open in Web Editor NEW
20.0 5.0 2.0 1.32 MB

Stylelint rule for setting minimum and maximum constraint value for z-index.

License: MIT License

JavaScript 100.00%
stylelint css z-index linter-plugin

stylelint-z-index-value-constraint's Introduction

stylelint-z-index-value-constraint

NPM version Build Status Downloads per month contributions welcome

Stylelint rule for setting minimum and maximum constraint value for z-index.

This is a fork of niksy/stylelint-number-z-index-constraint plugin.

Install

npm install stylelint-z-index-value-constraint --save-dev

or

yarn add stylelint-z-index-value-constraint --dev

Usage

Add this config to your .stylelintrc:

{
  "plugins": ["stylelint-z-index-value-constraint"],
  "rules": {
    "plugin/z-index-value-constraint": {
      "min": 1,
      "max": 10
    }
  }
}

Details

a {
  z-index: 10;
}
/**        โ†‘
 * This number */

From CSS Tricks article:

It's fairly common to see people number in the hundreds with z-index in web design too. The idea being that you could slip something in between later if need be, which you couldn't if you did 1, 2, 3, etc, because z-index doesn't support decimals.

This rule also handles negative values.

Options

{ min: 10 }

The following patterns are considered warnings:

a {
  z-index: 9;
}
input {
  z-index: 2;
}
a {
  z-index: -9;
}
input {
  z-index: -2;
}

The following patterns are not considered warnings:

a {
  z-index: 10;
}
input {
  z-index: 25;
}
a {
  z-index: -10;
}
input {
  z-index: -25;
}

{ max: 9999 }

The following patterns are considered warnings:

a {
  z-index: 10000;
}
input {
  z-index: 200000;
}
a {
  z-index: -10000;
}
input {
  z-index: -200000;
}

The following patterns are not considered warnings:

a {
  z-index: 9999;
}
input {
  z-index: 8000;
}
a {
  z-index: -9999;
}
input {
  z-index: -8000;
}

Optional options

ignoreValues: ["number"]

{ max: 10 }, { ignoreValues: [11, 20] }

The following patterns are considered warnings:

a {
  z-index: 12;
}
input {
  z-index: 19;
}

The following patterns are not considered warnings:

a {
  z-index: 11;
}
input {
  z-index: 20;
}

Dependencies

This plugin has only stylelint as a dependency.


License

MIT

stylelint-z-index-value-constraint's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar kristerkari avatar lewiscollard avatar nikkeyl avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

jukben b3nk3

stylelint-z-index-value-constraint's Issues

Handle secondary options with only severity level

Providing rules:

"rules": {
  "plugin/z-index-value-constraint": [{ max: 100 }, {severity: "error" }]
}

causes a TypeError. This is likely related to this check: https://github.com/kristerkari/stylelint-z-index-value-constraint/blob/master/index.js#L60

I have this working by providing these options:

"rules": {
  "plugin/z-index-value-constraint": [{ max: 100 }, { ignoreValues: [-1], severity: "error" }]
}

but it would be ideal to be able to just provide a severity level.

Example of rule is unvalid

Hi,

I wanted to let you know that the given example does not present a valid one.

{
  "plugins": ["stylelint-z-index-value-constraint"],
  "rules": [
    "plugin/z-index-value-constraint": {
      "min": 1,
      "max": 10
    }
  ]
}

(as the red color indicates it)

I can make a PR for this is you want.

Thx !

Would be lovely to have z-index use variables functionality

Would be great to have possibility to set z-index value only variables, not numeric value. That is some time helps to keep z-index variables in one place and find out what is this variable does?

Example:
// not valid
z-index: 5;

// valid
$the-best-z-index: 5;
z-index: $the-best-z-index;

Please take a look at it, thanks!

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.