3 Limit the allowed nesting depth.
6 a { & > b { top: 0; } }
11 This rule works by checking rules' and at-rules' actual "nesting depth" against your specified max. Here's how nesting depths works:
15 & b { /* nesting depth 1 */
16 & .foo { /* nesting depth 2 */
17 @media print { /* nesting depth 3 */
18 & .baz { /* nesting depth 4 */
27 Note that **root-level at-rules will *not* be included in the nesting depth calculation**, because most users would take for granted that root-level at-rules are "free" (because necessary). So both of the following `.foo` rules have a nesting depth of 2, and will therefore pass if your `max` is less than or equal to 2:
36 @media print { /* ignored */
45 This rule integrates into stylelint's core the functionality of the (now deprecated) plugin [`stylelint-statement-max-nesting-depth`](https://github.com/davidtheclark/stylelint-statement-max-nesting-depth).
49 `int`: Maximum nesting depth allowed.
51 For example, with `2`:
53 The following patterns are considered violations:
67 @media print { /* 1 */
75 The following patterns are *not* considered violations:
84 a .foo__foo .bar .baz {}
97 ## Optional secondary options
99 ### `ignore: ["blockless-at-rules"]`
101 Ignore at-rules that only wrap other rules, and do not themselves have declaration blocks.
103 For example, with `1`:
105 The following patterns are considered violations:
107 As the at-rules have a declarations blocks.
112 @media (min-width: 500px) { color: pink; } /* 2 */
120 .foo { color: pink; } /* 2 */
125 The following patterns are *not* considered violations:
127 As all of the following `.foo` rules would have a nesting depth of just 1.
131 .foo { color: pink; } /* 1 */
136 @media print { /* ignored regardless of options */
138 .foo { color: pink; } /* 1 */
145 @media print { /* ignored because it's an at-rule without a declaration block of its own */
146 .foo { color: pink; } /* 1 */
151 ### `ignoreAtRules: ["/regex/", "string"]`
153 Ignore the specified at-rules.
155 For example, with `1` and given:
161 The following patterns are *not* considered violations:
165 @media print { /* 1 */
167 c { top: 0; } /* 3 */
176 @media print { /* 2 */
177 c { top: 0; } /* 3 */
185 @my-at-rule print { /* 1 */
187 c { top: 0; } /* 3 */
195 @my-other-at-rule print { /* 1 */
197 c { top: 0; } /* 3 */
203 The following patterns are considered violations:
207 @import print { /* 1 */
208 b { top: 0; } /* 2 */
215 @not-my-at-rule print { /* 1 */
216 b { top: 0; } /* 2 */