GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Change `ignore*` for `value-type-custom-property-required-list` (#9626) · stylelint/stylelint@9040322

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .changeset/pre
    • public-birds-join.md
  • CHANGELOG.md
  • docs
    • about
      • semantic-versioning.md
    • migration-guide
      • to-18.md
    • user-guide
      • customize.md
  • lib
    • rules
      • declaration-property-value-no-unknown
        • index.mjs
      • value-type-custom-property-required-list
        • README.md
        • __tests__
          • index.mjs
        • index.mjs
    • utils
      • __tests__
        • isWithinRange.test.mjs
      • isWithinRange.mjs
  • types/stylelint
    • index.d.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.changeset/pre/public-birds-join.md‎

Copy file name to clipboardExpand all lines: .changeset/pre/public-birds-join.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"stylelint": minor
33
---
44

5-
Added: `value-type-custom-property-required-list` rule
5+
Added: experimental `value-type-custom-property-required-list` rule
Collapse file

‎CHANGELOG.md‎

Copy file name to clipboardExpand all lines: CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This is a prerelease. Help us test the next major version: `npm i -D stylelint@n
2323
- Added: `result.stylelint.postcss` property for plugins ([#9594](https://github.com/stylelint/stylelint/pull/9594)) ([@jeddy3](https://github.com/jeddy3)).
2424
- Added: `stylelint.version` property ([#9595](https://github.com/stylelint/stylelint/pull/9595)) ([@ybiquitous](https://github.com/ybiquitous)).
2525
- Added: `value-no-invalid` rule ([#9507](https://github.com/stylelint/stylelint/pull/9507)) ([@jeddy3](https://github.com/jeddy3)).
26-
- Added: `value-type-custom-property-required-list` rule ([#9572](https://github.com/stylelint/stylelint/pull/9572)) ([@jeddy3](https://github.com/jeddy3)).
26+
- Added: experimental `value-type-custom-property-required-list` rule ([#9572](https://github.com/stylelint/stylelint/pull/9572)) ([@jeddy3](https://github.com/jeddy3)).
2727
- Added: stable support for `processors` configuration property ([#9543](https://github.com/stylelint/stylelint/pull/9543)) ([@jeddy3](https://github.com/jeddy3)).
2828
- Added: stable support for `referenceFiles` configuration property ([#9598](https://github.com/stylelint/stylelint/pull/9598)) ([@jeddy3](https://github.com/jeddy3)).
2929
- Fixed: `--fix` for files where the only change is the removal of a byte order mark ([#9512](https://github.com/stylelint/stylelint/pull/9512)) ([@firefoxic](https://github.com/firefoxic)).
Collapse file

‎docs/about/semantic-versioning.md‎

Copy file name to clipboardExpand all lines: docs/about/semantic-versioning.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Might break your lint build:
2525
- a new public API capability is created
2626
- a new formatter is created
2727
- a new deprecation is introduced
28+
- a feature documented as experimental is changed in an incompatible way
2829

2930
## Major release
3031

Collapse file

‎docs/migration-guide/to-18.md‎

Copy file name to clipboardExpand all lines: docs/migration-guide/to-18.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ You can use the [`referenceFiles`](../user-guide/configure.md#referencefiles) co
5959

6060
### Added `declaration-property-custom-property-allowed-list` and `value-type-custom-property-required-list` rules
6161

62-
We've added the [`declaration-property-custom-property-allowed-list`](../../lib/rules/declaration-property-custom-property-allowed-list/README.md) rule to specify which custom properties are allowed in which properties, and the [`value-type-custom-property-required-list`](../../lib/rules/value-type-custom-property-required-list/README.md) rule to specify which value types require custom properties.
62+
We've added the [`declaration-property-custom-property-allowed-list`](../../lib/rules/declaration-property-custom-property-allowed-list/README.md) rule to specify which custom properties are allowed in which properties, and the experimental [`value-type-custom-property-required-list`](../../lib/rules/value-type-custom-property-required-list/README.md) rule to specify which value types require custom properties.
6363

6464
For example, to allow only `--spacing-*` custom properties in `margin` and `padding` properties and only `--radii-*` in `border-radius`, and to require custom properties for `<length>` values:
6565

Collapse file

‎docs/user-guide/customize.md‎

Copy file name to clipboardExpand all lines: docs/user-guide/customize.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ You can combine the [`referenceFiles`](configure.md#referencefiles) configuratio
5959
+ },
6060
+ "value-type-custom-property-required-list": [
6161
+ ["color", "length"],
62-
+ { "ignoreProperties": { "/.+/": ["0", "transparent", "currentcolor"] } }
62+
+ { "ignoreValues": ["0", "transparent", "currentcolor"] }
6363
+ ]
6464
+ }
6565
}
Collapse file

‎lib/rules/declaration-property-value-no-unknown/index.mjs‎

Copy file name to clipboardExpand all lines: lib/rules/declaration-property-value-no-unknown/index.mjs
+1-10Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import isDescriptorDeclaration from '../../utils/isDescriptorDeclaration.mjs';
2727
import isStandardSyntaxDeclaration from '../../utils/isStandardSyntaxDeclaration.mjs';
2828
import isStandardSyntaxProperty from '../../utils/isStandardSyntaxProperty.mjs';
2929
import isStandardSyntaxValue from '../../utils/isStandardSyntaxValue.mjs';
30+
import isWithinRange from '../../utils/isWithinRange.mjs';
3031
import memoize from '../../utils/memoize.mjs';
3132
import memoizeForReferenceRoots from '../../utils/memoizeForReferenceRoots.mjs';
3233
import optionsMatchesEntry from '../../utils/optionsMatchesEntry.mjs';
@@ -701,16 +702,6 @@ function getPrefixedPropName(name) {
701702
return `-stylelint${name}`;
702703
}
703704

704-
/**
705-
* @param {VarFunctionSubstitution} substitution
706-
* @param {number} start
707-
* @param {number} end
708-
* @returns {boolean}
709-
*/
710-
function isWithinRange(substitution, start, end) {
711-
return start <= substitution.start && substitution.end <= end;
712-
}
713-
714705
/**
715706
* @param {import('css-tree').LexerMatchResult['error']} error
716707
* @returns {error is import('css-tree').SyntaxMatchError}
Collapse file

‎lib/rules/value-type-custom-property-required-list/README.md‎

Copy file name to clipboardExpand all lines: lib/rules/value-type-custom-property-required-list/README.md
+78-13Lines changed: 78 additions & 13 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ a { border: 1px solid red; }
99
* These <length> and <color> values */
1010
```
1111

12+
> [!WARNING]
13+
> This rule is **experimental**, as it's our first whose options take value types. To give feedback on them, [open an issue](https://github.com/stylelint/stylelint/issues/new/choose).
14+
1215
Use this rule to enforce a convention. For example, require custom properties for:
1316

1417
- `color`, so that colors come from your palette
@@ -70,32 +73,63 @@ a {
7073

7174
## Optional secondary options
7275

73-
### `ignoreProperties`
76+
### `ignoreFunctions`
77+
78+
```json
79+
{ "ignoreFunctions": { "type": ["array", "of", "functions", "/regex/"] } }
80+
```
81+
82+
Ignore the parts of a type that are within the specified functions.
83+
84+
Given:
7485

7586
```json
7687
{
77-
"ignoreProperties": { "property-name": ["array", "of", "values", "/regex/"] }
88+
"value-type-custom-property-required-list": [
89+
["color", "number", "angle", "percentage"],
90+
{
91+
"ignoreFunctions": {
92+
"number": ["/.+/"],
93+
"color": ["color-mix"],
94+
"/^(angle|percentage)$/": ["/-gradient$/"]
95+
}
96+
}
97+
]
7898
}
7999
```
80100

81-
Ignore the specified property and value pairs.
101+
The following patterns are _not_ considered problems:
102+
103+
<!-- prettier-ignore -->
104+
```css
105+
a { transform: scale(1.5); }
106+
```
107+
108+
<!-- prettier-ignore -->
109+
```css
110+
a { color: color-mix(in srgb, red, blue); }
111+
```
82112

83-
Keys in the object indicate property names and values indicate the parts of a value.
113+
<!-- prettier-ignore -->
114+
```css
115+
a { background: linear-gradient(45deg, var(--foo) 0%, var(--bar) 100%); }
116+
```
117+
118+
### `ignoreProperties`
119+
120+
```json
121+
{ "ignoreProperties": { "type": ["array", "of", "properties", "/regex/"] } }
122+
```
84123

85-
You can specify a regex for a property name, such as `{ "/.+/": ["transparent"] }`, and for a value, such as `{ "transform": ["/.+/"] }`.
124+
Ignore the parts of a type in the values of the specified properties.
86125

87126
Given:
88127

89128
```json
90129
{
91130
"value-type-custom-property-required-list": [
92131
["color", "length"],
93-
{
94-
"ignoreProperties": {
95-
"/.+/": ["transparent"],
96-
"transform": ["/.+/"]
97-
}
98-
}
132+
{ "ignoreProperties": { "/.+/": ["transform"], "length": ["/^border/"] } }
99133
]
100134
}
101135
```
@@ -104,10 +138,41 @@ The following patterns are _not_ considered problems:
104138

105139
<!-- prettier-ignore -->
106140
```css
107-
a { color: transparent; }
141+
a { transform: translateX(1px); }
108142
```
109143

110144
<!-- prettier-ignore -->
111145
```css
112-
a { transform: translateX(4px); }
146+
a { border-width: 1px; }
147+
```
148+
149+
### `ignoreValues`
150+
151+
```json
152+
{ "ignoreValues": ["array", "of", "values", "/regex/"] }
153+
```
154+
155+
Ignore the specified parts of a value.
156+
157+
Given:
158+
159+
```json
160+
{
161+
"value-type-custom-property-required-list": [
162+
["color", "number"],
163+
{ "ignoreValues": ["0", "transparent"] }
164+
]
165+
}
166+
```
167+
168+
The following patterns are _not_ considered problems:
169+
170+
<!-- prettier-ignore -->
171+
```css
172+
a { flex: 0; }
173+
```
174+
175+
<!-- prettier-ignore -->
176+
```css
177+
a { color: transparent; }
113178
```
Collapse file

‎lib/rules/value-type-custom-property-required-list/__tests__/index.mjs‎

Copy file name to clipboardExpand all lines: lib/rules/value-type-custom-property-required-list/__tests__/index.mjs
+127-10Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,39 +146,142 @@ testRule({
146146
],
147147
});
148148

149+
testRule({
150+
ruleName,
151+
config: [['color', 'number'], { ignoreValues: ['0', 'transparent', '/^oklch\\(/'] }],
152+
153+
accept: [
154+
{
155+
code: 'a { flex: 0; }',
156+
},
157+
{
158+
code: 'a { color: transparent; }',
159+
},
160+
{
161+
code: 'a { color: oklch(20% 0.1 0deg); }',
162+
},
163+
],
164+
165+
reject: [
166+
{
167+
code: 'a { color: rgb(0 0 0); }',
168+
message: messages.expected('rgb(0 0 0)', 'color'),
169+
line: 1,
170+
column: 12,
171+
endLine: 1,
172+
endColumn: 22,
173+
},
174+
{
175+
code: 'a { color: color-mix(in srgb, transparent, red); }',
176+
message: messages.expected('red', 'color'),
177+
line: 1,
178+
column: 44,
179+
endLine: 1,
180+
endColumn: 47,
181+
},
182+
],
183+
});
184+
149185
testRule({
150186
ruleName,
151187
config: [
152-
['color', 'length'],
153-
{ ignoreProperties: { '/.+/': ['transparent'], transform: ['/.+/'] } },
188+
['color', 'number', 'angle', 'percentage'],
189+
{
190+
ignoreFunctions: {
191+
number: ['/.+/'],
192+
color: ['color-mix'],
193+
'/^(angle|percentage)$/': ['/-gradient$/'],
194+
},
195+
},
154196
],
155197

156198
accept: [
157199
{
158-
code: 'a { color: transparent; }',
200+
code: 'a { transform: scale(1.5); }',
159201
},
202+
{
203+
code: 'a { color: color-mix(in srgb, red, blue); }',
204+
},
205+
{
206+
code: 'a { --foo: 0; color: rgb(var(--foo) 0 0); }',
207+
description: 'color function with a custom property argument',
208+
},
209+
{
210+
code: 'a { --foo: red; --bar: blue; background: linear-gradient(45deg, var(--foo) 0%, var(--bar) 100%); }',
211+
},
212+
],
213+
214+
reject: [
215+
{
216+
code: 'a { opacity: 0.5; }',
217+
message: messages.expected('0.5', 'number'),
218+
line: 1,
219+
column: 14,
220+
endLine: 1,
221+
endColumn: 17,
222+
},
223+
{
224+
code: 'a { color: rgb(0 0 0); }',
225+
message: messages.expected('rgb(0 0 0)', 'color'),
226+
line: 1,
227+
column: 12,
228+
endLine: 1,
229+
endColumn: 22,
230+
},
231+
{
232+
code: 'a { background: linear-gradient(45deg, red 0%, blue 100%); }',
233+
warnings: [
234+
{
235+
message: messages.expected('red', 'color'),
236+
line: 1,
237+
column: 40,
238+
endLine: 1,
239+
endColumn: 43,
240+
},
241+
{
242+
message: messages.expected('blue', 'color'),
243+
line: 1,
244+
column: 48,
245+
endLine: 1,
246+
endColumn: 52,
247+
},
248+
],
249+
},
250+
],
251+
});
252+
253+
testRule({
254+
ruleName,
255+
config: [
256+
['color', 'length'],
257+
{ ignoreProperties: { '/.+/': ['transform'], length: ['/^border/'] } },
258+
],
259+
260+
accept: [
160261
{
161262
code: 'a { transform: translateX(1px); }',
162263
},
264+
{
265+
code: 'a { border-width: 1px; }',
266+
},
163267
],
164268

165269
reject: [
166270
{
167-
code: 'a { border: 1px solid transparent; }',
271+
code: 'a { margin: 1px; }',
168272
message: messages.expected('1px', 'length'),
169273
line: 1,
170274
column: 13,
171275
endLine: 1,
172276
endColumn: 16,
173277
},
174278
{
175-
code: 'a { color: color-mix(in srgb, transparent, red); }',
279+
code: 'a { border: 1px solid red; }',
176280
message: messages.expected('red', 'color'),
177281
line: 1,
178-
column: 44,
282+
column: 23,
179283
endLine: 1,
180-
endColumn: 47,
181-
description: 'color function with an ignored argument',
284+
endColumn: 26,
182285
},
183286
],
184287
});
@@ -191,7 +294,13 @@ testRuleConfigs({
191294
config: 'color',
192295
},
193296
{
194-
config: [['color'], { ignoreProperties: { color: ['transparent', /^calc\(/] } }],
297+
config: [['color'], { ignoreValues: ['transparent', /^calc\(/] }],
298+
},
299+
{
300+
config: [['color'], { ignoreFunctions: { color: ['rgb', /^color-/] } }],
301+
},
302+
{
303+
config: [['color'], { ignoreProperties: { color: ['border', /^background/] } }],
195304
},
196305
],
197306

@@ -205,7 +314,15 @@ testRuleConfigs({
205314
description: 'invalid primary option type',
206315
},
207316
{
208-
config: [['color'], { ignoreProperties: 1 }],
317+
config: [['color'], { ignoreValues: { color: ['transparent'] } }],
318+
description: 'invalid ignoreValues option type',
319+
},
320+
{
321+
config: [['color'], { ignoreFunctions: ['rgb'] }],
322+
description: 'invalid ignoreFunctions option type',
323+
},
324+
{
325+
config: [['color'], { ignoreProperties: ['border'] }],
209326
description: 'invalid ignoreProperties option type',
210327
},
211328
],

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.