Skip to content

Commit 941a723

Browse files
authoredOct 24, 2023
fix for no-css-tagged-template linting rule (#1537)
* fix for no-css-tagged-template linting rule * Add changeset
1 parent 4a11c5f commit 941a723

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
 

‎.changeset/cold-chairs-float.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@compiled/eslint-plugin': patch
3+
'@compiled/webpack-loader': patch
4+
---
5+
6+
Bugfix: no-css-tagged-template-expression ESLint rule truncates strings which include colons during autofixing.

‎packages/eslint-plugin/src/rules/no-css-tagged-template-expression/__tests__/rule.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -612,5 +612,22 @@ tester.run('no-css-tagged-template-expression', noCssTaggedTemplateExpressionRul
612612
\`;
613613
`,
614614
},
615+
{
616+
filename: 'colon-in-value.ts',
617+
code: `
618+
import { css } from '@compiled/react';
619+
620+
css\`
621+
background-image: url('https://some-url-b');
622+
\`;
623+
`,
624+
output: `
625+
import { css } from '@compiled/react';
626+
627+
css({
628+
backgroundImage: "url('https://some-url-b')"
629+
});
630+
`,
631+
},
615632
]),
616633
});

‎packages/eslint-plugin/src/utils/create-no-tagged-template-expression-rule/to-arguments.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ const getArguments = (
2525
return args;
2626
}
2727

28-
const [property, value] = chars.split(':');
28+
// Split the property and value
29+
// e.g. `color: red` becomes ['color', 'red']
30+
// also consider `background: url("https://some-url-b")`, which has a colon in the value.
31+
const [property, ...v] = chars.split(':');
32+
const value = v.join(':');
2933

3034
// Extract any expressions listed before the property that were not delimited by a ;
3135
if (expressions.length) {

0 commit comments

Comments
 (0)
Please sign in to comment.