-
-
Notifications
You must be signed in to change notification settings - Fork 986
Add rule-nesting-at-rule-required-list
#8680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ybiquitous
merged 23 commits into
stylelint:main
from
sw1tch3roo:feature/declaration-block-nesting-at-rule-required-list
Aug 12, 2025
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e649efa
add `declaration-block-nesting-at-rule-required-list`
sw1tch3roo d51f557
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo 3c04e94
fix the type in index.d.ts
sw1tch3roo 3fe8df7
Refactor rule to check entire rules instead of individual declarations
sw1tch3roo 016b16e
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo cbade06
changes after review: change code style, delete unnecessary tests, up…
sw1tch3roo 52c7654
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo e048d14
suggestions from code review
sw1tch3roo 18b7ec7
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo 2bdb301
build cjs file
sw1tch3roo db6523f
use typeGuards utils
sw1tch3roo 892693a
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo d90f473
enhance the expected messages
sw1tch3roo fb24ded
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo e79ff39
change the examples in README.md
sw1tch3roo 9f765c3
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo fa64d61
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo dd2a7ff
fix expected message type in `d.ts` declaration
sw1tch3roo 554ecd6
reuse the type of args
sw1tch3roo 5dca318
change expected message type in `d.ts`
sw1tch3roo c0c5591
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo f4000e8
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo 6260d46
Merge branch 'main' into feature/declaration-block-nesting-at-rule-re…
sw1tch3roo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "stylelint": minor | ||
| --- | ||
|
|
||
| Added: `rule-nesting-at-rule-required-list` rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # rule-nesting-at-rule-required-list | ||
|
|
||
| Require rules to be nested in specific at-rules. | ||
|
|
||
| <!-- prettier-ignore --> | ||
| ```css | ||
| a { color: red; } | ||
| /** ↑ | ||
| * This rule */ | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| ### `Array<string | RegExp>` | ||
|
|
||
| Given: | ||
|
|
||
| ```json | ||
| { | ||
| "rule-nesting-at-rule-required-list": ["layer"] | ||
sw1tch3roo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
|
|
||
| The following patterns are considered problems: | ||
|
|
||
| <!-- prettier-ignore --> | ||
| ```css | ||
| a { color: red; } | ||
| ``` | ||
|
|
||
| <!-- prettier-ignore --> | ||
| ```css | ||
| @media all { | ||
| a { color: red; } | ||
| } | ||
| ``` | ||
|
|
||
| <!-- prettier-ignore --> | ||
| ```css | ||
| a { | ||
| @layer { | ||
| color: red; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The following patterns are _not_ considered problems: | ||
|
|
||
| <!-- prettier-ignore --> | ||
| ```css | ||
| @layer { | ||
| a { color: red; } | ||
| } | ||
| ``` | ||
|
|
||
sw1tch3roo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <!-- prettier-ignore --> | ||
| ```css | ||
| @font-face { | ||
| font-family: "foo"; | ||
| } | ||
| ``` | ||
151 changes: 151 additions & 0 deletions
151
lib/rules/rule-nesting-at-rule-required-list/__tests__/index.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import rule from '../index.mjs'; | ||
| const { messages, ruleName } = rule; | ||
|
|
||
| testRule({ | ||
| ruleName, | ||
| config: ['layer', '/^s/'], | ||
|
|
||
| accept: [ | ||
| { | ||
| code: '@layer { a { color: red; } }', | ||
| description: 'rule within @layer at-rule', | ||
| }, | ||
| { | ||
| code: '@supports (color: red) { a { color: red; } }', | ||
| description: 'rule within @supports at-rule (matches regex)', | ||
| }, | ||
| { | ||
| code: '@scope (a) { a { color: red; } }', | ||
| description: 'rule within @scope at-rule (matches regex)', | ||
| }, | ||
| { | ||
| code: '@media all {}', | ||
| description: 'empty at-rule', | ||
| }, | ||
| { | ||
| code: '@layer { @media all { a { color: red; } } }', | ||
| description: 'rule within nested required at-rule', | ||
| }, | ||
| { | ||
| code: '@font-face { font-family: "foo"; }', | ||
| description: 'at-rule descriptor', | ||
| }, | ||
| ], | ||
|
|
||
| reject: [ | ||
| { | ||
| code: 'a { color: red; }', | ||
| description: 'rule without required at-rule', | ||
| message: messages.expected('layer, /^s/'), | ||
| line: 1, | ||
| column: 1, | ||
| endLine: 1, | ||
| endColumn: 18, | ||
| }, | ||
| { | ||
| code: '@media all { a { color: red; } }', | ||
| description: 'rule within non-required at-rule', | ||
| message: messages.expected('layer, /^s/'), | ||
| line: 1, | ||
| column: 14, | ||
| endLine: 1, | ||
| endColumn: 31, | ||
| }, | ||
| { | ||
| code: 'a { @layer { color: red; } }', | ||
| description: 'rule with nested declarations rule', | ||
| message: messages.expected('layer, /^s/'), | ||
| line: 1, | ||
| column: 1, | ||
| endLine: 1, | ||
| endColumn: 29, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| testRule({ | ||
sw1tch3roo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ruleName, | ||
| config: ['layer'], | ||
|
|
||
| accept: [ | ||
| { | ||
| code: '@layer { a { color: red; } }', | ||
| description: 'rule within @layer at-rule', | ||
| }, | ||
| { | ||
| code: '@font-face { font-family: "foo"; }', | ||
| description: 'at-rule descriptor', | ||
| }, | ||
| ], | ||
|
|
||
| reject: [ | ||
| { | ||
| code: 'a { color: red; }', | ||
| description: 'rule without required at-rule', | ||
| message: messages.expected('layer'), | ||
| line: 1, | ||
| column: 1, | ||
| endLine: 1, | ||
| endColumn: 18, | ||
| }, | ||
| { | ||
| code: '@supports (color: red) { a { color: red; } }', | ||
| description: 'rule within non-required at-rule', | ||
| message: messages.expected('layer'), | ||
| line: 1, | ||
| column: 26, | ||
| endLine: 1, | ||
| endColumn: 43, | ||
| }, | ||
| { | ||
| code: 'a { @layer { color: red; } }', | ||
| description: 'rule with nested declarations rule', | ||
| message: messages.expected('layer'), | ||
| line: 1, | ||
| column: 1, | ||
| endLine: 1, | ||
| endColumn: 29, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| testRule({ | ||
sw1tch3roo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ruleName, | ||
| config: ['/^s/'], | ||
|
|
||
| accept: [ | ||
| { | ||
| code: '@supports (color: red) { a { color: red; } }', | ||
| description: 'rule within @supports at-rule (matches regex)', | ||
| }, | ||
| { | ||
| code: '@scope (a) { a { color: red; } }', | ||
| description: 'rule within @scope at-rule (matches regex)', | ||
| }, | ||
| { | ||
| code: '@font-face { font-family: "foo"; }', | ||
| description: 'at-rule descriptor', | ||
| }, | ||
| ], | ||
|
|
||
| reject: [ | ||
| { | ||
| code: 'a { color: red; }', | ||
| description: 'rule without required at-rule', | ||
| message: messages.expected('/^s/'), | ||
| line: 1, | ||
| column: 1, | ||
| endLine: 1, | ||
| endColumn: 18, | ||
| }, | ||
| { | ||
| code: '@layer { a { color: red; } }', | ||
| description: 'rule within non-matching at-rule', | ||
| message: messages.expected('/^s/'), | ||
| line: 1, | ||
| column: 10, | ||
| endLine: 1, | ||
| endColumn: 27, | ||
| }, | ||
| ], | ||
| }); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.