Search code examples
regexstylelint

Regex for stylelint rule


I'm using stylelint and I need a regex expression for it's max-nesting-depth rule to ignore selectors which begin with both &: and @media

https://stylelint.io/user-guide/rules/max-nesting-depth/

So far I've tried the below without sucess:

"max-nesting-depth": [3, {
  "ignore": ["/^&:/", "/^@media/"]
}]

Solution

  • The "ignore" secondary option of the max-nesting-depth rule only accepts the "blockless-at-rules" keyword.

    Instead, use the "ignoreAtRules" secondary option to ignore media queries:

    "max-nesting-depth": [3, {
      "ignoreAtRules": ["media"]
    }]
    

    It is not currently possible to ignore nested rules. However, there is an open issue to add this feature. The issue is labelled as "beginner friendly", and would be a good first pull request if you'd like to contribute to stylelint.