Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-flowers-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": minor
---

Added: `ignore: ["after-custom-property"]` to `custom-property-empty-line-before`
26 changes: 26 additions & 0 deletions lib/rules/custom-property-empty-line-before/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,32 @@ a {
}
```

#### `"after-custom-property"`

Ignore custom properties that follow another custom property.

Given:

```json
{
"custom-property-empty-line-before": [
"always",
{ "ignore": ["after-custom-property"] }
]
}
```

The following patterns are _not_ considered problems:

<!-- prettier-ignore -->
```css
a {

--foo: pink;
--bar: red;
}
```

#### `"first-nested"`

Ignore custom properties that are nested and the first child of their parent node.
Expand Down
113 changes: 113 additions & 0 deletions lib/rules/custom-property-empty-line-before/__tests__/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,119 @@ testRule({
],
});

testRule({
ruleName,
config: ['always', { ignore: ['after-custom-property'] }],
fix: true,
computeEditInfo: true,

accept: [
{
code: 'a {\n\n --custom-prop: value; --custom-prop2: value;\n}',
},
{
code: 'a {\r\n\r\n --custom-prop: value; --custom-prop2: value;\r\n}',
},
{
code: 'a {\n\n --custom-prop: value;\n --custom-prop2: value;\n}',
},
{
code: 'a {\n\n --custom-prop: value; /* comment */\n --custom-prop2: value;\n}',
description: 'shared-line comment accepted',
},
{
code: 'a {\r\n\r\n --custom-prop: value;\r\n --custom-prop2: value;\r\n}',
},
{
code: 'a {\n\n --custom-prop: value;\n\n --custom-prop2: value;\n}',
},
{
code: 'a {\r\n\r\n --custom-prop: value;\r\n\r\n --custom-prop2: value;\r\n}',
},
],

reject: [
{
code: 'a{\n @extends .class;\n --custom-prop: value;\n}',
fixed: 'a{\n @extends .class;\n\n --custom-prop: value;\n}',
fix: {
range: [20, 21],
text: '\n\n',
},
message: messages.expected,
line: 3,
column: 2,
},
{
code: 'a{\r\n @extends .class;\r\n --custom-prop: value;\r\n}',
fixed: 'a{\r\n @extends .class;\r\n\r\n --custom-prop: value;\r\n}',
fix: {
range: [22, 23],
text: '\n\r\n',
},
message: messages.expected,
line: 3,
column: 2,
},
{
code: 'a{\n @include mixin;\n --custom-prop: value;\n}',
fixed: 'a{\n @include mixin;\n\n --custom-prop: value;\n}',
fix: {
range: [19, 20],
text: '\n\n',
},
message: messages.expected,
line: 3,
column: 2,
},
{
code: 'a{\r\n @include mixin;\r\n --custom-prop: value;\r\n}',
fixed: 'a{\r\n @include mixin;\r\n\r\n --custom-prop: value;\r\n}',
fix: {
range: [21, 22],
text: '\n\r\n',
},
message: messages.expected,
line: 3,
column: 2,
},
{
code: 'a {\n --custom-prop: value;\n}',
fixed: 'a {\n\n --custom-prop: value;\n}',
fix: {
range: [3, 4],
text: '\n\n',
},
message: messages.expected,
line: 2,
column: 2,
},
{
code: 'a {\r\n --custom-prop: value;\r\n}',
fixed: 'a {\r\n\r\n --custom-prop: value;\r\n}',
fix: {
range: [4, 5],
text: '\n\r\n',
},
message: messages.expected,
line: 2,
column: 2,
},
{
code: 'a {\n top: 15px;\n --custom-prop: value;\n}',
fixed: 'a {\n top: 15px;\n\n --custom-prop: value;\n}',
fix: {
range: [16, 17],
text: '\n\n',
},
message: messages.expected,
line: 3,
column: 3,
description: "standard properties don't count",
},
],
});

testRule({
ruleName,
config: ['always', { ignore: ['first-nested'] }],
Expand Down
17 changes: 15 additions & 2 deletions lib/rules/custom-property-empty-line-before/index.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions lib/rules/custom-property-empty-line-before/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ const rule = (primary, secondaryOptions, context) => {
{
actual: secondaryOptions,
possible: {
except: ['first-nested', 'after-comment', 'after-custom-property'],
ignore: ['after-comment', 'first-nested', 'inside-single-line-block'],
except: ['after-comment', 'after-custom-property', 'first-nested'],
ignore: [
'after-comment',
'after-custom-property',
'first-nested',
'inside-single-line-block',
],
},
optional: true,
},
Expand All @@ -66,6 +71,14 @@ const rule = (primary, secondaryOptions, context) => {
return;
}

// Optionally ignore the node if a custom property precedes it
if (
optionsMatches(secondaryOptions, 'ignore', 'after-custom-property') &&
isAfterCustomProperty(decl)
) {
return;
}

// Optionally ignore the node if it is the first nested
if (optionsMatches(secondaryOptions, 'ignore', 'first-nested') && isFirstNested(decl)) {
return;
Expand Down
6 changes: 4 additions & 2 deletions types/stylelint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ declare namespace stylelint {
'custom-property-empty-line-before': CoreRule<
'always' | 'never',
{
except: OneOrMany<'first-nested' | 'after-comment' | 'after-custom-property'>;
ignore: OneOrMany<'after-comment' | 'first-nested' | 'inside-single-line-block'>;
except: OneOrMany<'after-comment' | 'after-custom-property' | 'first-nested'>;
ignore: OneOrMany<
'after-comment' | 'after-custom-property' | 'first-nested' | 'inside-single-line-block'
>;
}
>;
'custom-property-no-missing-var-function': CoreRule<true>;
Expand Down