Skip to content

Commit

Permalink
Fixed: selector-class-* regex to account for numerals, case de… (#247)
Browse files Browse the repository at this point in the history
Fixed: `selector-class-*` regex to account for numerals, case detection, and ensure kebab-case
  • Loading branch information
ntwb committed May 31, 2020
1 parent 9d9feee commit 1a5238c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/stylelint-config-wordpress/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# HEAD

- Fixed: `selector-class-pattern` rule regex to account for numerals, case detection, and ensure kebab-case over snake_case.
- Fixed: `selector-id-pattern` rule regex to account for numerals, case detection, and ensure kebab-case over snake_case.
- Updated: `stylelint-config-recommended-scss` to `4.1.0`.
- Updated: `stylelint-find-rules` to `2.2.0`.
- Updated: `stylelint-scss` to `3.13.0`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ Array [
"severity": "error",
"text": "Unexpected unit \\"%\\" for property \\"line-height\\" (declaration-property-unit-whitelist)",
},
Object {
"column": 1,
"line": 25,
"rule": "selector-class-pattern",
"severity": "error",
"text": "Selector should use lowercase and separate words with hyphens (selector-class-pattern)",
},
Object {
"column": 1,
"line": 1,
"rule": "selector-id-pattern",
"severity": "error",
"text": "Selector should use lowercase and separate words with hyphens (selector-id-pattern)",
},
Object {
"column": 1,
"line": 5,
"rule": "selector-id-pattern",
"severity": "error",
"text": "Selector should use lowercase and separate words with hyphens (selector-id-pattern)",
},
Object {
"column": 4,
"line": 9,
"rule": "selector-id-pattern",
"severity": "error",
"text": "Selector should use lowercase and separate words with hyphens (selector-id-pattern)",
},
Object {
"column": 1,
"line": 21,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ input[type="text"] {
.selector::after {
color: #000;
}

.selector-class {
color: #000;
}

#selector-id {
color: #000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe( 'flags warnings with invalid selectors css', () => {

it( 'flags correct number of warnings', () => {
return result.then( ( data ) => (
expect( data.results[ 0 ].warnings ).toHaveLength( 4 )
expect( data.results[ 0 ].warnings ).toHaveLength( 8 )
) );
} );

Expand Down
18 changes: 18 additions & 0 deletions packages/stylelint-config-wordpress/__tests__/structure-valid.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,21 @@
background: #fff;
color: #000;
}

h1,
.heading-size-1 {
background: #fff;
color: #000;
}

h2,
.heading-size-2 {
background: #fff;
color: #000;
}

h3,
.heading-size-3 {
background: #fff;
color: #000;
}
4 changes: 2 additions & 2 deletions packages/stylelint-config-wordpress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ module.exports = {
'selector-attribute-operator-space-before': 'never',
'selector-attribute-quotes': 'always',
'selector-class-pattern': [
'^[a-z]+(-[a-z]+)*',
'^([a-z][a-z0-9]*)(-[a-z0-9]+)*$',
{
message: 'Selector should use lowercase and separate words with hyphens (selector-class-pattern)',
},
],
'selector-id-pattern': [
'^[a-z]+(-[a-z]+)*',
'^([a-z][a-z0-9]*)(-[a-z0-9]+)*$',
{
message: 'Selector should use lowercase and separate words with hyphens (selector-id-pattern)',
},
Expand Down

0 comments on commit 1a5238c

Please sign in to comment.