From c91d22aa73a49412895152a7f0cc2b6a1732ec9d Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Wed, 3 Jan 2024 17:02:08 +0200 Subject: [PATCH 1/4] custom-property-pattern rule changed for compatibility with WP naming --- sources/@roots/bud-sass/config/stylelint.cjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sources/@roots/bud-sass/config/stylelint.cjs b/sources/@roots/bud-sass/config/stylelint.cjs index 8b63616cfd..2b59243b88 100644 --- a/sources/@roots/bud-sass/config/stylelint.cjs +++ b/sources/@roots/bud-sass/config/stylelint.cjs @@ -3,4 +3,12 @@ module.exports = { `@roots/bud-stylelint/config`, `stylelint-config-recommended-scss`, ], + rules: { + 'custom-property-pattern': [ + '^([a-z][a-z0-9]*)(-{1,2}[a-z0-9]+)*$', + { + message: name => `Expected custom property name "${name}" to be kebab-case`, + }, + ], + }, } From ca2e1594841995cb613a86f6edb1a0484eb30d19 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Sun, 7 Jan 2024 08:47:48 +0000 Subject: [PATCH 2/4] mode custom-property-pattern into bud-preset-wordpress --- sources/@roots/bud-preset-wordpress/config/stylelint.cjs | 7 ++++++- sources/@roots/bud-sass/config/stylelint.cjs | 8 -------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sources/@roots/bud-preset-wordpress/config/stylelint.cjs b/sources/@roots/bud-preset-wordpress/config/stylelint.cjs index a71bc83bc4..a4d7943aaa 100644 --- a/sources/@roots/bud-preset-wordpress/config/stylelint.cjs +++ b/sources/@roots/bud-preset-wordpress/config/stylelint.cjs @@ -3,6 +3,11 @@ */ module.exports = { rules: { - 'custom-property-pattern': null, + 'custom-property-pattern': [ + '^([a-z][a-z0-9]*)(-{1,2}[a-z0-9]+)*$', + { + message: name => `Expected custom property name "${name}" to be kebab-case`, + }, + ], }, } diff --git a/sources/@roots/bud-sass/config/stylelint.cjs b/sources/@roots/bud-sass/config/stylelint.cjs index 2b59243b88..8b63616cfd 100644 --- a/sources/@roots/bud-sass/config/stylelint.cjs +++ b/sources/@roots/bud-sass/config/stylelint.cjs @@ -3,12 +3,4 @@ module.exports = { `@roots/bud-stylelint/config`, `stylelint-config-recommended-scss`, ], - rules: { - 'custom-property-pattern': [ - '^([a-z][a-z0-9]*)(-{1,2}[a-z0-9]+)*$', - { - message: name => `Expected custom property name "${name}" to be kebab-case`, - }, - ], - }, } From 36e545bb1addb6f56b73b222174d1ae581b33f3a Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Mon, 8 Jan 2024 15:48:02 +0000 Subject: [PATCH 3/4] add tests --- .../test/stylelint-config.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sources/@roots/bud-preset-wordpress/test/stylelint-config.test.ts diff --git a/sources/@roots/bud-preset-wordpress/test/stylelint-config.test.ts b/sources/@roots/bud-preset-wordpress/test/stylelint-config.test.ts new file mode 100644 index 0000000000..590fdc38ea --- /dev/null +++ b/sources/@roots/bud-preset-wordpress/test/stylelint-config.test.ts @@ -0,0 +1,39 @@ +import * as stylelint from 'stylelint' +import {describe, expect, it} from 'vitest' + +describe(`@roots/bud-preset-wordpress/stylelint`, () => { + it(`should error without rule`, async () => { + const result = await stylelint.lint({ + code: ` + .foo { + color: var(--wp--preset--color--primary); + } + `, + config: { + extends: [ + `@roots/bud-sass/stylelint-config`, + ], + }, + }) + + expect(result.errored).toBe(true) + }) + + it(`should not error with rule`, async () => { + const result = await stylelint.lint({ + code: ` + .foo { + color: var(--wp--preset--color--primary); + } + `, + config: { + extends: [ + `@roots/bud-sass/stylelint-config`, + `@roots/bud-preset-wordpress/stylelint`, + ], + }, + }) + + expect(result.errored).toBe(false) + }) +}) \ No newline at end of file From 00db42dde12685f817210894b5f4758c8399000a Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Mon, 8 Jan 2024 17:30:37 +0000 Subject: [PATCH 4/4] use template literals --- sources/@roots/bud-preset-wordpress/config/stylelint.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/@roots/bud-preset-wordpress/config/stylelint.cjs b/sources/@roots/bud-preset-wordpress/config/stylelint.cjs index a4d7943aaa..e4622b1f48 100644 --- a/sources/@roots/bud-preset-wordpress/config/stylelint.cjs +++ b/sources/@roots/bud-preset-wordpress/config/stylelint.cjs @@ -4,7 +4,7 @@ module.exports = { rules: { 'custom-property-pattern': [ - '^([a-z][a-z0-9]*)(-{1,2}[a-z0-9]+)*$', + `^([a-z][a-z0-9]*)(-{1,2}[a-z0-9]+)*$`, { message: name => `Expected custom property name "${name}" to be kebab-case`, },