Search code examples
cssstylelint

stylelint ignore rule for specific folder/file


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.


Solution

  • 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