Skip to content

Commit 7eca56c

Browse files
authored
Fix shorthand-property-no-redundant-values false negatives for additional radius (#8539)
1 parent 15e4232 commit 7eca56c

File tree

4 files changed

+396
-5
lines changed

4 files changed

+396
-5
lines changed

.changeset/dark-bees-crash.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+
Fixed: `shorthand-property-no-redundant-values` false negatives for additional radius

lib/rules/shorthand-property-no-redundant-values/__tests__/index.mjs

Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,19 @@ testRule({
8080
},
8181
{
8282
code: 'a { border-radius: 1px / 1px; }',
83-
description: 'ignore ellipse',
84-
},
85-
{
86-
code: 'a { border-radius: 1px 1px / 1px; }',
87-
description: 'ignore ellipse',
8883
},
8984
{
9085
code: 'a { margin: var(--margin) var(--margin); }',
9186
description: 'ignore variables',
9287
},
88+
{
89+
code: 'a { border-radius: var(--foo) var(--foo) / var(--foo) var(--foo); }',
90+
description: 'ignore variables with slash in shorthand',
91+
},
92+
{
93+
code: 'a { border-radius: 1px 1px , 1px 1px; }',
94+
description: 'ignore invalid divider in border-radius (comma)',
95+
},
9396
{
9497
code: 'a { border-color: #FFFFFF transparent transparent; }',
9598
description: 'ignore upper case value',
@@ -587,6 +590,125 @@ testRule({
587590
endLine: 1,
588591
endColumn: 62,
589592
},
593+
{
594+
code: 'a { border-radius: 1px 1px / 1px; }',
595+
fixed: 'a { border-radius: 1px / 1px; }',
596+
fix: {
597+
range: [23, 27],
598+
text: '',
599+
},
600+
message: messages.expected('1px 1px / 1px', '1px / 1px'),
601+
line: 1,
602+
column: 20,
603+
endLine: 1,
604+
endColumn: 33,
605+
},
606+
{
607+
code: 'a { border-radius: 1px 1px 1px 1px / 2px 2px 2px 2px; }',
608+
fixed: 'a { border-radius: 1px / 2px; }',
609+
fix: {
610+
range: [23, 48],
611+
text: '/',
612+
},
613+
message: messages.expected('1px 1px 1px 1px / 2px 2px 2px 2px', '1px / 2px'),
614+
line: 1,
615+
column: 20,
616+
endLine: 1,
617+
endColumn: 53,
618+
},
619+
{
620+
code: 'a { border-radius: 1px 1px 1px 1px / 2px; }',
621+
fixed: 'a { border-radius: 1px / 2px; }',
622+
description: 'Horizontal side redundant - vertical already shortest',
623+
fix: {
624+
range: [23, 35],
625+
text: '',
626+
},
627+
message: messages.expected('1px 1px 1px 1px / 2px', '1px / 2px'),
628+
line: 1,
629+
column: 20,
630+
endLine: 1,
631+
endColumn: 41,
632+
},
633+
{
634+
code: 'a { border-radius: 1px 2px / 2px 2px 2px 2px; }',
635+
fixed: 'a { border-radius: 1px 2px / 2px; }',
636+
description: 'Vertical side redundant - horizontal mixed',
637+
fix: {
638+
range: [32, 44],
639+
text: '',
640+
},
641+
message: messages.expected('1px 2px / 2px 2px 2px 2px', '1px 2px / 2px'),
642+
line: 1,
643+
column: 20,
644+
endLine: 1,
645+
endColumn: 45,
646+
},
647+
{
648+
code: 'a { border-radius: calc(1px + 1px) calc(1px + 1px) / calc(1px + 1px) calc(1px + 1px); }',
649+
fixed: 'a { border-radius: calc(1px + 1px) / calc(1px + 1px); }',
650+
description: 'slash with value functions',
651+
fix: {
652+
range: [35, 68],
653+
text: '/',
654+
},
655+
message: messages.expected(
656+
'calc(1px + 1px) calc(1px + 1px) / calc(1px + 1px) calc(1px + 1px)',
657+
'calc(1px + 1px) / calc(1px + 1px)',
658+
),
659+
line: 1,
660+
column: 20,
661+
endLine: 1,
662+
endColumn: 85,
663+
},
664+
{
665+
code: 'a { border-radius: 1px 1px / calc(1px + 1px) calc(1px + 1px); }',
666+
fixed: 'a { border-radius: 1px / calc(1px + 1px); }',
667+
description: 'slash with value words and value functions',
668+
fix: {
669+
range: [23, 44],
670+
text: '/',
671+
},
672+
message: messages.expected(
673+
'1px 1px / calc(1px + 1px) calc(1px + 1px)',
674+
'1px / calc(1px + 1px)',
675+
),
676+
line: 1,
677+
column: 20,
678+
endLine: 1,
679+
endColumn: 61,
680+
},
681+
{
682+
code: 'a { border-radius: 1px 1px / var(--foo) var(--foo); }',
683+
fixed: 'a { border-radius: 1px / var(--foo) var(--foo); }',
684+
description: 'slash with value words and variable functions',
685+
fix: {
686+
range: [23, 27],
687+
text: '',
688+
},
689+
message: messages.expected('1px 1px / var(--foo) var(--foo)', '1px / var(--foo) var(--foo)'),
690+
line: 1,
691+
column: 20,
692+
endLine: 1,
693+
endColumn: 51,
694+
},
695+
{
696+
code: 'a { border-radius: var(--foo) var(--foo) / calc(1px + 1px) calc(1px + 1px); }',
697+
fixed: 'a { border-radius: var(--foo) var(--foo) / calc(1px + 1px); }',
698+
description: 'slash with value functions and variable functions',
699+
fix: {
700+
range: [58, 74],
701+
text: '',
702+
},
703+
message: messages.expected(
704+
'var(--foo) var(--foo) / calc(1px + 1px) calc(1px + 1px)',
705+
'var(--foo) var(--foo) / calc(1px + 1px)',
706+
),
707+
line: 1,
708+
column: 20,
709+
endLine: 1,
710+
endColumn: 75,
711+
},
590712
],
591713
});
592714

lib/rules/shorthand-property-no-redundant-values/index.cjs

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)