noExcessiveNestedBlocks (CSS)
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/noExcessiveNestedBlocks - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
max-nesting-depth
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noExcessiveNestedBlocks": "error" } } }}Description
Section titled “Description”Enforce a maximum depth that blocks can be nested.
Deeply nested styles are difficult to read and follow. Every level of nesting also makes
the resulting selector longer, which makes the styles harder to override. This rule reports
{} blocks nested beyond the configured limit.
The block of a rule or at-rule written at the top level of the file isn’t nested, so it
doesn’t count as a level. Wrapping styles in a top-level at-rule, such as @media or
@layer, doesn’t add a level either. Every other block adds one level.
Only the outermost block exceeding the limit is reported: blocks nested inside it aren’t reported again.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”.a { .b { .c { .d { .e { .f { color: red; } } } } }}code-block.css:6:21 lint/nursery/noExcessiveNestedBlocks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This block is nested too deeply.
4 │ .d {
5 │ .e {
> 6 │ .f {
│ ^^
7 │ color: red;
8 │ }
ℹ Blocks nested 5 levels deep are hard to read and produce long selectors that are hard to override. The configured maximum is 4.
ℹ Move the nested styles closer to the top level, or use a single class name instead of a chain of nested selectors.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
.a { .b { .c { .d { .e { color: red; } } } }}
@media (width >= 600px) { .a { .b { .c { .d { .e { color: red; } } } } }}Options
Section titled “Options”Default: 4
The maximum block nesting depth allowed.
{ "linter": { "rules": { "nursery": { "noExcessiveNestedBlocks": { "level": "on", "options": { "max": 1 } } } } }}Invalid
Section titled “Invalid”.a { .b { .c { color: red; } }}code-block.css:3:9 lint/nursery/noExcessiveNestedBlocks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This block is nested too deeply.
1 │ .a {
2 │ .b {
> 3 │ .c {
│ ^^
4 │ color: red;
5 │ }
ℹ Blocks nested 2 levels deep are hard to read and produce long selectors that are hard to override. The configured maximum is 1.
ℹ Move the nested styles closer to the top level, or use a single class name instead of a chain of nested selectors.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
.a { .b { color: red; }}ignoreAtRules
Section titled “ignoreAtRules”Default: []
A list of at-rule names, without the leading @. The blocks of these at-rules don’t count
as a level and are never reported. Names are matched regardless of letter case.
{ "linter": { "rules": { "nursery": { "noExcessiveNestedBlocks": { "level": "on", "options": { "max": 1, "ignoreAtRules": [ "media" ] } } } } }}.a { @media print { .b { color: red; } }}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.