Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stylelint ignore rule for specific folder/file

Tags:

css

stylelint

I looked at stylelint's docs and only saw a way to disable stylelint for running on for specific files/directories but what I really want is a way to disable specific rules) for specific files/directories. Is there a way to achieve that? I don't want to use stylelint-disable within the files.

like image 534
Yangshun Tay Avatar asked Mar 06 '20 13:03

Yangshun Tay


People also ask

How do I ignore a file in Stylelint?

You can also specify a path to your ignore patterns file (absolute or relative to process. cwd() ) using the --ignore-path (in the CLI) and ignorePath (in JS) options. Alternatively, you can add an ignoreFiles property within your configuration object.


1 Answers

In the future, you'll be able to use the overrides configuration property. In the meantime, you can work around this missing feature by using the extend configuration property and by running stylelint twice.

Create a second config that extends the more limited main config and turns on additional rules:

.extended-stylelintrc.json:

{
    extends: "./.stylelintrc.json",
    rules: {
        "unit-whitelist": ["px"]
    }
};

Or you can create a second config that extends a full main config and turns off rules:

.limited-stylelintrc.json:

{
    extends: "./.stylelintrc.json",
    rules: {
        "property-no-unknown": null
    }
};

It will require two npm tasks to run it, though:

stylelint "**/*.css"
stylelint "special/**/*.css" --config .extended-stylelintrc.js

Or it can be combined into one:

stylelint "**/*.css" && stylelint "special/**/*.css" --config .extended-stylelintrc.js
like image 125
jeddy3 Avatar answered Oct 07 '22 13:10

jeddy3