Skip to content

Commit 9f15d9d

Browse files
Added lightness-notation support for computing EditInfo (#8458)
1 parent 9be82dd commit 9f15d9d

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

.changeset/great-dots-shine.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": minor
3+
---
4+
5+
Added: `lightness-notation` support for computing `EditInfo`

lib/rules/lightness-notation/__tests__/index.mjs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ testRule({
77
ruleName,
88
config: ['percentage'],
99
fix: true,
10+
computeEditInfo: true,
1011

1112
accept: [
1213
{
@@ -58,6 +59,10 @@ testRule({
5859
{
5960
code: 'a { color: oklch(0.7 0.1 241) }',
6061
fixed: 'a { color: oklch(70% 0.1 241) }',
62+
fix: {
63+
range: [17, 20],
64+
text: '70%',
65+
},
6166
message: messages.expected('0.7', '70%'),
6267
line: 1,
6368
column: 18,
@@ -67,6 +72,10 @@ testRule({
6772
{
6873
code: 'a { color: lch(70 0.1 241) }',
6974
fixed: 'a { color: lch(70% 0.1 241) }',
75+
fix: {
76+
range: [16, 17],
77+
text: '0%',
78+
},
7079
message: messages.expected('70', '70%'),
7180
line: 1,
7281
column: 16,
@@ -76,6 +85,10 @@ testRule({
7685
{
7786
code: 'a { color: oklab(0.7 0.1 241) }',
7887
fixed: 'a { color: oklab(70% 0.1 241) }',
88+
fix: {
89+
range: [17, 20],
90+
text: '70%',
91+
},
7992
message: messages.expected('0.7', '70%'),
8093
line: 1,
8194
column: 18,
@@ -85,6 +98,10 @@ testRule({
8598
{
8699
code: 'a { color: lab(70 0.1 241) }',
87100
fixed: 'a { color: lab(70% 0.1 241) }',
101+
fix: {
102+
range: [16, 17],
103+
text: '0%',
104+
},
88105
message: messages.expected('70', '70%'),
89106
line: 1,
90107
column: 16,
@@ -94,6 +111,10 @@ testRule({
94111
{
95112
code: 'a { color: lch(56.29 19.86 200) }',
96113
fixed: 'a { color: lch(56.29% 19.86 200) }',
114+
fix: {
115+
range: [19, 20],
116+
text: '9%',
117+
},
97118
message: messages.expected('56.29', '56.29%'),
98119
line: 1,
99120
column: 16,
@@ -103,6 +124,10 @@ testRule({
103124
{
104125
code: 'a { color: oklch(0.5629 0.1 241) }',
105126
fixed: 'a { color: oklch(56.29% 0.1 241) }',
127+
fix: {
128+
range: [17, 23],
129+
text: '56.29%',
130+
},
106131
message: messages.expected('0.5629', '56.29%'),
107132
line: 1,
108133
column: 18,
@@ -112,6 +137,10 @@ testRule({
112137
{
113138
code: 'a { color: lch(56.29 19.86 200/ 100%) }',
114139
fixed: 'a { color: lch(56.29% 19.86 200/ 100%) }',
140+
fix: {
141+
range: [19, 20],
142+
text: '9%',
143+
},
115144
message: messages.expected('56.29', '56.29%'),
116145
line: 1,
117146
column: 16,
@@ -121,6 +150,10 @@ testRule({
121150
{
122151
code: 'a { color: oklch(/*comment*/0.5629 0.1 241) }',
123152
fixed: 'a { color: oklch(/*comment*/56.29% 0.1 241) }',
153+
fix: {
154+
range: [28, 34],
155+
text: '56.29%',
156+
},
124157
message: messages.expected('0.5629', '56.29%'),
125158
line: 1,
126159
column: 29,
@@ -130,6 +163,10 @@ testRule({
130163
{
131164
code: 'a { color: lch(52.9 0.1 241/*comment*/) }',
132165
fixed: 'a { color: lch(52.9% 0.1 241/*comment*/) }',
166+
fix: {
167+
range: [18, 19],
168+
text: '9%',
169+
},
133170
message: messages.expected('52.9', '52.9%'),
134171
line: 1,
135172
column: 16,
@@ -158,13 +195,18 @@ testRule({
158195
warnings: [
159196
{
160197
message: messages.expected('29.2345', '29.2345%'),
198+
fix: {
199+
range: [64, 65],
200+
text: '5%',
201+
},
161202
line: 4,
162203
column: 7,
163204
endLine: 4,
164205
endColumn: 14,
165206
},
166207
{
167208
message: messages.expected('56.29', '56.29%'),
209+
fix: undefined,
168210
line: 5,
169211
column: 7,
170212
endLine: 5,
@@ -179,6 +221,7 @@ testRule({
179221
ruleName,
180222
config: ['number'],
181223
fix: true,
224+
computeEditInfo: true,
182225

183226
accept: [
184227
{
@@ -225,6 +268,10 @@ testRule({
225268
{
226269
code: 'a { color: oklch(70% 0.1 241) }',
227270
fixed: 'a { color: oklch(0.7 0.1 241) }',
271+
fix: {
272+
range: [17, 20],
273+
text: '0.7',
274+
},
228275
message: messages.expected('70%', '0.7'),
229276
line: 1,
230277
column: 18,
@@ -234,6 +281,10 @@ testRule({
234281
{
235282
code: 'a { color: lch(70% 0.1 241) }',
236283
fixed: 'a { color: lch(70 0.1 241) }',
284+
fix: {
285+
range: [17, 18],
286+
text: '',
287+
},
237288
message: messages.expected('70%', '70'),
238289
line: 1,
239290
column: 16,
@@ -243,6 +294,10 @@ testRule({
243294
{
244295
code: 'a { color: oklab(70% 0.1 241) }',
245296
fixed: 'a { color: oklab(0.7 0.1 241) }',
297+
fix: {
298+
range: [17, 20],
299+
text: '0.7',
300+
},
246301
message: messages.expected('70%', '0.7'),
247302
line: 1,
248303
column: 18,
@@ -252,6 +307,10 @@ testRule({
252307
{
253308
code: 'a { color: lab(70% 0.1 241) }',
254309
fixed: 'a { color: lab(70 0.1 241) }',
310+
fix: {
311+
range: [17, 18],
312+
text: '',
313+
},
255314
message: messages.expected('70%', '70'),
256315
line: 1,
257316
column: 16,
@@ -261,6 +320,10 @@ testRule({
261320
{
262321
code: 'a { color: lch(56.29% 19.86 200) }',
263322
fixed: 'a { color: lch(56.29 19.86 200) }',
323+
fix: {
324+
range: [20, 21],
325+
text: '',
326+
},
264327
message: messages.expected('56.29%', '56.29'),
265328
line: 1,
266329
column: 16,
@@ -270,6 +333,10 @@ testRule({
270333
{
271334
code: 'a { color: oklch(56.29% 0.1 241) }',
272335
fixed: 'a { color: oklch(0.5629 0.1 241) }',
336+
fix: {
337+
range: [17, 23],
338+
text: '0.5629',
339+
},
273340
message: messages.expected('56.29%', '0.5629'),
274341
line: 1,
275342
column: 18,
@@ -279,6 +346,10 @@ testRule({
279346
{
280347
code: 'a { color: lch(56.29% 19.86 200/ 100%) }',
281348
fixed: 'a { color: lch(56.29 19.86 200/ 100%) }',
349+
fix: {
350+
range: [20, 21],
351+
text: '',
352+
},
282353
message: messages.expected('56.29%', '56.29'),
283354
line: 1,
284355
column: 16,
@@ -288,6 +359,10 @@ testRule({
288359
{
289360
code: 'a { color: oklch(/*comment*/56.29% 0.1 241) }',
290361
fixed: 'a { color: oklch(/*comment*/0.5629 0.1 241) }',
362+
fix: {
363+
range: [28, 34],
364+
text: '0.5629',
365+
},
291366
message: messages.expected('56.29%', '0.5629'),
292367
line: 1,
293368
column: 29,
@@ -297,6 +372,10 @@ testRule({
297372
{
298373
code: 'a { color: lch(52.9% 0.1 241/*comment*/) }',
299374
fixed: 'a { color: lch(52.9 0.1 241/*comment*/) }',
375+
fix: {
376+
range: [19, 20],
377+
text: '',
378+
},
300379
message: messages.expected('52.9%', '52.9'),
301380
line: 1,
302381
column: 16,
@@ -325,13 +404,18 @@ testRule({
325404
warnings: [
326405
{
327406
message: messages.expected('29.2345%', '29.2345'),
407+
fix: {
408+
range: [65, 66],
409+
text: '',
410+
},
328411
line: 4,
329412
column: 7,
330413
endLine: 4,
331414
endColumn: 15,
332415
},
333416
{
334417
message: messages.expected('56.29%', '56.29'),
418+
fix: undefined,
335419
line: 5,
336420
column: 7,
337421
endLine: 5,

lib/rules/lightness-notation/index.cjs

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/lightness-notation/index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ const rule = (primary) => {
8888
endIndex: valueIndex + lightness.sourceEndIndex,
8989
result,
9090
ruleName,
91-
fix,
91+
fix: {
92+
apply: fix,
93+
node: decl,
94+
},
9295
});
9396
});
9497
});

0 commit comments

Comments
 (0)