From 1a5238cd28b55d9c0573e5ee98be6eb2e7db0716 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Sat, 30 Nov 2019 13:05:40 +1100 Subject: [PATCH] =?UTF-8?q?Fixed:=20`selector-class-*`=20regex=20to=20acco?= =?UTF-8?q?unt=20for=20numerals,=20case=20de=E2=80=A6=20(#247)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed: `selector-class-*` regex to account for numerals, case detection, and ensure kebab-case --- .../stylelint-config-wordpress/CHANGELOG.md | 2 ++ .../__snapshots__/selectors.test.js.snap | 28 +++++++++++++++++++ .../__tests__/selectors-valid.css | 8 ++++++ .../__tests__/selectors.test.js | 2 +- .../__tests__/structure-valid.css | 18 ++++++++++++ packages/stylelint-config-wordpress/index.js | 4 +-- 6 files changed, 59 insertions(+), 3 deletions(-) diff --git a/packages/stylelint-config-wordpress/CHANGELOG.md b/packages/stylelint-config-wordpress/CHANGELOG.md index aaf4b6fd4327b..c03b3eecf4b92 100644 --- a/packages/stylelint-config-wordpress/CHANGELOG.md +++ b/packages/stylelint-config-wordpress/CHANGELOG.md @@ -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`. diff --git a/packages/stylelint-config-wordpress/__tests__/__snapshots__/selectors.test.js.snap b/packages/stylelint-config-wordpress/__tests__/__snapshots__/selectors.test.js.snap index b68957d82c980..6debd6f6f38b0 100644 --- a/packages/stylelint-config-wordpress/__tests__/__snapshots__/selectors.test.js.snap +++ b/packages/stylelint-config-wordpress/__tests__/__snapshots__/selectors.test.js.snap @@ -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, diff --git a/packages/stylelint-config-wordpress/__tests__/selectors-valid.css b/packages/stylelint-config-wordpress/__tests__/selectors-valid.css index e25e013dbe833..19a87ff51f35d 100644 --- a/packages/stylelint-config-wordpress/__tests__/selectors-valid.css +++ b/packages/stylelint-config-wordpress/__tests__/selectors-valid.css @@ -9,3 +9,11 @@ input[type="text"] { .selector::after { color: #000; } + +.selector-class { + color: #000; +} + +#selector-id { + color: #000; +} diff --git a/packages/stylelint-config-wordpress/__tests__/selectors.test.js b/packages/stylelint-config-wordpress/__tests__/selectors.test.js index 55ead86e3bcab..f91aaafc1018a 100644 --- a/packages/stylelint-config-wordpress/__tests__/selectors.test.js +++ b/packages/stylelint-config-wordpress/__tests__/selectors.test.js @@ -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 ) ) ); } ); diff --git a/packages/stylelint-config-wordpress/__tests__/structure-valid.css b/packages/stylelint-config-wordpress/__tests__/structure-valid.css index fa886b59cf18b..b7b28949f3cd5 100644 --- a/packages/stylelint-config-wordpress/__tests__/structure-valid.css +++ b/packages/stylelint-config-wordpress/__tests__/structure-valid.css @@ -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; +} diff --git a/packages/stylelint-config-wordpress/index.js b/packages/stylelint-config-wordpress/index.js index 072a7dc6fa4d4..3d14b9d240726 100644 --- a/packages/stylelint-config-wordpress/index.js +++ b/packages/stylelint-config-wordpress/index.js @@ -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)', },