Skip to content

Commit 9911899

Browse files
jhae-dejeddy3
andauthored
Fix layer-name-pattern false positives for dot notation (#373)
Co-authored-by: jeddy3 <[email protected]>
1 parent 807ed8d commit 9911899

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fixed: `layer-name-pattern` false positives for dot notation.
6+
37
## 39.0.0
48

59
- Removed: `stylelint` less than `16.23.0` from peer dependencies.

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ To see the rules that this config uses, please read the [config itself](./index.
4242
left: calc(var(--offset) + 50%);
4343
}
4444

45-
/* Flush nested single line comment */
46-
a::after {
47-
display: block;
48-
content: "";
49-
background-image: url("x.svg");
45+
@layer layer-foo.layer-bar {
46+
a::after {
47+
display: block;
48+
content: "";
49+
background-image: url("x.svg");
50+
}
5051
}
5152
}
5253

@@ -55,6 +56,7 @@ To see the rules that this config uses, please read the [config itself](./index.
5556
opacity: 0;
5657
}
5758

59+
/* Flush nested single line comment */
5860
to {
5961
opacity: 1;
6062
}

__tests__/index.test.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('flags warnings with invalid css', () => {
4242
});
4343

4444
it('flags warnings', () => {
45-
assert.equal(result.results[0].warnings.length, 5);
45+
assert.equal(result.results[0].warnings.length, 7);
4646
});
4747

4848
it('correct warning text', () => {
@@ -52,6 +52,8 @@ describe('flags warnings with invalid css', () => {
5252
'Expected custom media query name "--FOO" to be kebab-case (custom-media-pattern)',
5353
'Expected custom property name "--FOO" to be kebab-case (custom-property-pattern)',
5454
'Expected keyframe name "FOO" to be kebab-case (keyframes-name-pattern)',
55+
'Expected layer name "layer-BAR" to be kebab-case (layer-name-pattern)',
56+
'Expected layer name "layer-foo.layer-BAR" to be kebab-case (layer-name-pattern)',
5557
'Expected class selector ".FOO" to be kebab-case (selector-class-pattern)',
5658
'Expected id selector "#FOO" to be kebab-case (selector-id-pattern)',
5759
],
@@ -65,6 +67,8 @@ describe('flags warnings with invalid css', () => {
6567
'custom-media-pattern',
6668
'custom-property-pattern',
6769
'keyframes-name-pattern',
70+
'layer-name-pattern',
71+
'layer-name-pattern',
6872
'selector-class-pattern',
6973
'selector-id-pattern',
7074
],

__tests__/invalid.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@
1515
#FOO {
1616
/* ... */
1717
}
18+
19+
@layer layer-foo {
20+
/* ... */
21+
22+
@layer layer-BAR {
23+
/* ... */
24+
}
25+
}
26+
27+
@layer layer-foo.layer-BAR {
28+
/* ... */
29+
}

__tests__/valid.css

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
left: calc(var(--offset) + 50%);
3030
}
3131

32-
/* Flush nested single line comment */
33-
a::after {
34-
display: block;
35-
content: '→';
36-
background-image: url('x.svg');
32+
@layer layer-foo.layer-bar {
33+
a::after {
34+
display: block;
35+
content: '→';
36+
background-image: url('x.svg');
37+
}
3738
}
3839
}
3940

@@ -42,6 +43,7 @@
4243
opacity: 0;
4344
}
4445

46+
/* Flush nested single line comment */
4547
to {
4648
opacity: 1;
4749
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = {
8282
},
8383
],
8484
'layer-name-pattern': [
85-
'^([a-z][a-z0-9]*)(-[a-z0-9]+)*$',
85+
'^([a-z][a-z0-9]*)([.-][a-z0-9]+)*$',
8686
{
8787
message: (name) => `Expected layer name "${name}" to be kebab-case`,
8888
},

0 commit comments

Comments
 (0)