Skip to content

Commit 3b45045

Browse files
committed
Add limited autofix for properties in rules containing interpolation in CSS-in-JS syntax
1 parent 08cc9da commit 3b45045

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Every rule supports autofixing with `stylelint --fix`. [postcss-sorting] is used
5252

5353
Automatic sorting has some limitations that are described for every rule, if any. Please, take a look at [how comments are handled](https://github.com/hudochenkov/postcss-sorting#handling-comments) by `postcss-sorting`.
5454

55-
CSS-in-JS styles with template interpolation [could be ignored by autofixing](https://github.com/hudochenkov/postcss-sorting#css-in-js) to avoid style corruption.
55+
CSS-in-JS styles with template interpolation [has limited autofixing](https://github.com/hudochenkov/postcss-sorting#css-in-js) to avoid style corruption.
5656

5757
Autofixing in Less syntax may work but isn't officially supported.
5858

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"dependencies": {
2929
"postcss": "^8.5.8",
30-
"postcss-sorting": "^9.1.0"
30+
"postcss-sorting": "^10.0.0"
3131
},
3232
"peerDependencies": {
3333
"stylelint": "^16.18.0 || ^17.0.0"

rules/properties-order/tests/flat.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,40 @@ testRule({
394394
`,
395395
message: messages.expected('top', 'color'),
396396
},
397+
{
398+
code: `
399+
const Component = styled.div\`
400+
\${props => props.great && 'color: red;'}
401+
color: tomato;
402+
top: 0;
403+
\`;
404+
`,
405+
fixed: `
406+
const Component = styled.div\`
407+
\${props => props.great && 'color: red;'}
408+
top: 0;
409+
color: tomato;
410+
\`;
411+
`,
412+
message: messages.expected('top', 'color'),
413+
},
414+
{
415+
code: `
416+
const Component = styled.div\`
417+
color: tomato;
418+
top: 0;
419+
\${props => props.great && 'color: red;'}
420+
\`;
421+
`,
422+
fixed: `
423+
const Component = styled.div\`
424+
top: 0;
425+
color: tomato;
426+
\${props => props.great && 'color: red;'}
427+
\`;
428+
`,
429+
message: messages.expected('top', 'color'),
430+
},
397431
{
398432
code: `
399433
const Component = styled.div\`
@@ -460,6 +494,44 @@ testRule({
460494
],
461495
});
462496

497+
testRule({
498+
ruleName,
499+
config: [['top', 'color', 'position', 'display']],
500+
customSyntax: 'postcss-styled-syntax',
501+
fix: true,
502+
503+
reject: [
504+
{
505+
code: `
506+
const Component = styled.div\`
507+
color: tomato;
508+
top: 0;
509+
\${props => props.great && 'color: red;'}
510+
display: block;
511+
position: relative;
512+
\`;
513+
`,
514+
fixed: `
515+
const Component = styled.div\`
516+
top: 0;
517+
color: tomato;
518+
\${props => props.great && 'color: red;'}
519+
position: relative;
520+
display: block;
521+
\`;
522+
`,
523+
warnings: [
524+
{
525+
message: messages.expected('top', 'color'),
526+
},
527+
{
528+
message: messages.expected('position', 'display'),
529+
},
530+
],
531+
},
532+
],
533+
});
534+
463535
testRule({
464536
ruleName,
465537
config: [['top', 'color']],

0 commit comments

Comments
 (0)