@atlaskit/eslint-plugin-ui-styling-standard 0.15.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/dist/cjs/rules/no-nested-selectors/index.js +68 -49
- package/dist/es2019/rules/no-nested-selectors/index.js +63 -45
- package/dist/esm/rules/no-nested-selectors/index.js +64 -49
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +186 -149
- package/src/rules/no-nested-selectors/index.tsx +92 -105
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -8,225 +8,219 @@ import type { Rule } from 'eslint';
|
|
|
8
8
|
import type * as ESTree from 'eslint-codemod-utils';
|
|
9
9
|
|
|
10
10
|
type CssMapVisitorArgs =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
| {
|
|
12
|
+
type: 'variant' | 'declaration' | 'ruleset' | 'selectors';
|
|
13
|
+
node: ESTree.Property;
|
|
14
|
+
}
|
|
15
|
+
| { type: 'grouped-at-rules'; node: ESTree.Property; atRule: string };
|
|
16
16
|
|
|
17
17
|
type CssMapVisitor = (args: CssMapVisitorArgs) => void;
|
|
18
18
|
|
|
19
19
|
export function walkCssMap({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
context,
|
|
21
|
+
importSources,
|
|
22
|
+
visitor,
|
|
23
23
|
}: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
context: Rule.RuleContext;
|
|
25
|
+
program: ESTree.Program;
|
|
26
|
+
importSources: string[];
|
|
27
|
+
visitor: CssMapVisitor;
|
|
28
28
|
}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (variantMap.type !== 'ObjectExpression') {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
walkCssMapVariantMap({ variantMap, visitor });
|
|
70
|
-
});
|
|
29
|
+
const program = context.getSourceCode().ast;
|
|
30
|
+
|
|
31
|
+
const importDeclaration = program.body.find(
|
|
32
|
+
(node): node is ESTree.ImportDeclaration =>
|
|
33
|
+
node.type === 'ImportDeclaration' && importSources.includes(node.source.value as string),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const specifier = importDeclaration?.specifiers.find(
|
|
37
|
+
(specifier) => specifier.type === 'ImportSpecifier' && specifier.imported.name === 'cssMap',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (!specifier) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const [variable] = context.getSourceCode().scopeManager.getDeclaredVariables(specifier);
|
|
45
|
+
|
|
46
|
+
if (!variable) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
variable.references.forEach((reference) => {
|
|
51
|
+
const identifier = reference.identifier as ESTree.Identifier & Rule.NodeParentExtension;
|
|
52
|
+
|
|
53
|
+
const { parent } = identifier;
|
|
54
|
+
if (parent.type !== 'CallExpression') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const variantMap = parent.arguments[0];
|
|
59
|
+
if (variantMap.type !== 'ObjectExpression') {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
walkCssMapVariantMap({ variantMap, visitor });
|
|
64
|
+
});
|
|
71
65
|
}
|
|
72
66
|
|
|
73
67
|
function walkCssMapVariantMap({
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
variantMap,
|
|
69
|
+
visitor,
|
|
76
70
|
}: {
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
variantMap: ESTree.ObjectExpression;
|
|
72
|
+
visitor: CssMapVisitor;
|
|
79
73
|
}) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
variantMap.properties.forEach((property) => {
|
|
75
|
+
if (property.type !== 'Property') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
84
78
|
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
walkCssMapVariant({ variant: property, visitor });
|
|
80
|
+
});
|
|
87
81
|
}
|
|
88
82
|
|
|
89
83
|
function walkCssMapVariant({
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
variant,
|
|
85
|
+
visitor,
|
|
92
86
|
}: {
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
variant: ESTree.Property;
|
|
88
|
+
visitor: CssMapVisitor;
|
|
95
89
|
}) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
90
|
+
visitor({
|
|
91
|
+
type: 'variant',
|
|
92
|
+
node: variant,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (variant.value.type !== 'ObjectExpression') {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
variant.value.properties.forEach((property) => {
|
|
100
|
+
if (property.type !== 'Property') {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (property.value.type !== 'ObjectExpression') {
|
|
105
|
+
visitor({
|
|
106
|
+
type: 'declaration',
|
|
107
|
+
node: property,
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const keyValue = getKeyValue(property.key);
|
|
113
|
+
|
|
114
|
+
if (keyValue && /^@[A-z-]+$/.test(keyValue)) {
|
|
115
|
+
walkCssMapAtRuleGrouping({ atRuleGrouping: property, visitor });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (keyValue === 'selectors') {
|
|
120
|
+
walkCssMapSelectors({ selectors: property, visitor });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
walkStyleRuleset({ ruleset: property, visitor });
|
|
124
|
+
});
|
|
131
125
|
}
|
|
132
126
|
|
|
133
127
|
function walkCssMapAtRuleGrouping({
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
atRuleGrouping,
|
|
129
|
+
visitor,
|
|
136
130
|
}: {
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
atRuleGrouping: ESTree.Property;
|
|
132
|
+
visitor: CssMapVisitor;
|
|
139
133
|
}) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
134
|
+
const atRule = getKeyValue(atRuleGrouping.key);
|
|
135
|
+
if (!atRule) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
visitor({
|
|
140
|
+
type: 'grouped-at-rules',
|
|
141
|
+
node: atRuleGrouping,
|
|
142
|
+
atRule,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (atRuleGrouping.value.type !== 'ObjectExpression') {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
atRuleGrouping.value.properties.forEach((property) => {
|
|
150
|
+
if (property.type !== 'Property') {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
walkStyleRuleset({ ruleset: property, visitor });
|
|
155
|
+
});
|
|
162
156
|
}
|
|
163
157
|
|
|
164
158
|
function walkCssMapSelectors({
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
selectors,
|
|
160
|
+
visitor,
|
|
167
161
|
}: {
|
|
168
|
-
|
|
169
|
-
|
|
162
|
+
selectors: ESTree.Property;
|
|
163
|
+
visitor: CssMapVisitor;
|
|
170
164
|
}) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
165
|
+
visitor({
|
|
166
|
+
type: 'selectors',
|
|
167
|
+
node: selectors,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (selectors.value.type !== 'ObjectExpression') {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
selectors.value.properties.forEach((property) => {
|
|
175
|
+
if (property.type !== 'Property') {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
walkStyleRuleset({ ruleset: property, visitor });
|
|
180
|
+
});
|
|
187
181
|
}
|
|
188
182
|
|
|
189
183
|
function walkStyleRuleset({
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
ruleset,
|
|
185
|
+
visitor,
|
|
192
186
|
}: {
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
ruleset: ESTree.Property;
|
|
188
|
+
visitor: CssMapVisitor;
|
|
195
189
|
}) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
190
|
+
visitor({
|
|
191
|
+
type: 'ruleset',
|
|
192
|
+
node: ruleset,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (ruleset.value.type !== 'ObjectExpression') {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
ruleset.value.properties.forEach((property) => {
|
|
200
|
+
if (property.type !== 'Property') {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (property.value.type === 'ObjectExpression') {
|
|
205
|
+
walkStyleRuleset({ ruleset: property, visitor });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
visitor({
|
|
210
|
+
type: 'declaration',
|
|
211
|
+
node: property,
|
|
212
|
+
});
|
|
213
|
+
});
|
|
220
214
|
}
|
|
221
215
|
|
|
222
216
|
function getKeyValue(key: ESTree.Property['key']): string | null {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
217
|
+
if (key.type === 'Identifier') {
|
|
218
|
+
return key.name;
|
|
219
|
+
}
|
|
226
220
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
221
|
+
if (key.type === 'Literal') {
|
|
222
|
+
return key.value?.toString() ?? null;
|
|
223
|
+
}
|
|
230
224
|
|
|
231
|
-
|
|
225
|
+
return null;
|
|
232
226
|
}
|
|
@@ -6,14 +6,14 @@ This rule prevents the usage of styles that are difficult/impossible to statical
|
|
|
6
6
|
|
|
7
7
|
**Function calls**
|
|
8
8
|
|
|
9
|
-
Function calls are not allowed as arguments or as values,
|
|
10
|
-
|
|
9
|
+
Function calls are not allowed as arguments or as values, unless they are specified in
|
|
10
|
+
`allowedFunctionCalls` (or in the default list).
|
|
11
11
|
|
|
12
12
|
```tsx
|
|
13
13
|
import { css } from '@compiled/react';
|
|
14
14
|
|
|
15
15
|
function getStyles() {
|
|
16
|
-
|
|
16
|
+
return { width: 100 };
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const styles = css(getStyles());
|
|
@@ -23,30 +23,30 @@ const styles = css(getStyles());
|
|
|
23
23
|
import { css } from '@compiled/react';
|
|
24
24
|
|
|
25
25
|
function getWidth() {
|
|
26
|
-
|
|
26
|
+
return 100;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const styles = css({
|
|
30
|
-
|
|
30
|
+
width: getWidth(),
|
|
31
31
|
});
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
**Dynamic keys**
|
|
35
35
|
|
|
36
|
-
Dynamic keys are not allowed,
|
|
37
|
-
|
|
36
|
+
Dynamic keys are not allowed, unless they are specified in `allowedDynamicKeys` (or in the default
|
|
37
|
+
list).
|
|
38
38
|
|
|
39
39
|
```tsx
|
|
40
40
|
import { css } from '@compiled/react';
|
|
41
41
|
import { SELECTOR } from 'my-package';
|
|
42
42
|
|
|
43
43
|
const styles = css({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
[SELECTOR]: {
|
|
45
|
+
color: 'red',
|
|
46
|
+
},
|
|
47
|
+
[`${SELECTOR} > p`]: {
|
|
48
|
+
width: 100,
|
|
49
|
+
},
|
|
50
50
|
});
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -62,11 +62,11 @@ import { css } from '@compiled/react';
|
|
|
62
62
|
import { SELECTOR } from 'my-package';
|
|
63
63
|
|
|
64
64
|
function myFunction() {
|
|
65
|
-
|
|
65
|
+
return '5px';
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const styles = css({
|
|
69
|
-
|
|
69
|
+
height: myFunction,
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
@@ -79,11 +79,11 @@ import { css } from '@compiled/react';
|
|
|
79
79
|
import { token } from '@atlaskit/tokens';
|
|
80
80
|
|
|
81
81
|
const colors = {
|
|
82
|
-
|
|
82
|
+
text: token('color.text'),
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
const styles = css({
|
|
86
|
-
|
|
86
|
+
color: colors.text,
|
|
87
87
|
});
|
|
88
88
|
```
|
|
89
89
|
|
|
@@ -95,24 +95,23 @@ Spread elements are not allowed.
|
|
|
95
95
|
import { css } from '@compiled/react';
|
|
96
96
|
|
|
97
97
|
const buttonStyles = {
|
|
98
|
-
|
|
98
|
+
color: 'blue',
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
const styles = css({
|
|
102
|
-
|
|
102
|
+
...buttonStyles,
|
|
103
103
|
});
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
**Array values**
|
|
107
107
|
|
|
108
|
-
Array values are not allowed.
|
|
109
|
-
This syntax is not supported by most styling libraries.
|
|
108
|
+
Array values are not allowed. This syntax is not supported by most styling libraries.
|
|
110
109
|
|
|
111
110
|
```tsx
|
|
112
111
|
import { css } from '@compiled/react';
|
|
113
112
|
|
|
114
113
|
const styles = css({
|
|
115
|
-
|
|
114
|
+
'::before': [{ fontWeight: 'bold' }, { color: 'red' }],
|
|
116
115
|
});
|
|
117
116
|
```
|
|
118
117
|
|
|
@@ -122,31 +121,24 @@ Things to note about the following example:
|
|
|
122
121
|
|
|
123
122
|
- The `warningStyles` are conditionally applied using the `css` prop
|
|
124
123
|
- The dynamic `width` is applied using the `style` prop
|
|
125
|
-
- The `token()` calls are allowed because they are statically analyzable (and in the default
|
|
124
|
+
- The `token()` calls are allowed because they are statically analyzable (and in the default
|
|
125
|
+
allow-list)
|
|
126
126
|
|
|
127
127
|
```tsx
|
|
128
128
|
import { css } from '@compiled/react';
|
|
129
129
|
import { token } from '@atlaskit/tokens';
|
|
130
130
|
|
|
131
131
|
const baseStyles = css({
|
|
132
|
-
|
|
132
|
+
height: 100,
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
const warningStyles = css({
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
color: token('color.text.warning'),
|
|
137
|
+
backgroundColor: token('color.background.warning'),
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
const Component = ({
|
|
141
|
-
|
|
142
|
-
width,
|
|
143
|
-
}: {
|
|
144
|
-
isWarning: boolean;
|
|
145
|
-
width: number;
|
|
146
|
-
}) => {
|
|
147
|
-
return (
|
|
148
|
-
<div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />
|
|
149
|
-
);
|
|
140
|
+
const Component = ({ isWarning, width }: { isWarning: boolean; width: number }) => {
|
|
141
|
+
return <div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />;
|
|
150
142
|
};
|
|
151
143
|
```
|
|
152
144
|
|
|
@@ -156,7 +148,8 @@ const Component = ({
|
|
|
156
148
|
|
|
157
149
|
Use this to allow specified imports as dynamic keys, in addition to the built-in allow-list.
|
|
158
150
|
|
|
159
|
-
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
151
|
+
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
152
|
+
named export.
|
|
160
153
|
|
|
161
154
|
Default imports are not supported.
|
|
162
155
|
|
|
@@ -182,7 +175,8 @@ Default imports are not supported.
|
|
|
182
175
|
|
|
183
176
|
Use this to allow specific functions to be called, in addition to the built-in allow-list.
|
|
184
177
|
|
|
185
|
-
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
178
|
+
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
179
|
+
named export.
|
|
186
180
|
|
|
187
181
|
Default imports are not currently supported.
|
|
188
182
|
|
|
@@ -216,5 +210,5 @@ By default, this rule will check `css` usages from:
|
|
|
216
210
|
- `@emotion/styled`
|
|
217
211
|
- `styled-components`
|
|
218
212
|
|
|
219
|
-
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
220
|
-
This will override the built-in allow-list.
|
|
213
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
214
|
+
array of package names (strings). This will override the built-in allow-list.
|
|
@@ -2,15 +2,15 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
typescriptEslintTester.run(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
'no-unsafe-values',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [],
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
name: 'passing an array of values',
|
|
13
|
+
code: `
|
|
14
14
|
import { css } from '@compiled/react';
|
|
15
15
|
|
|
16
16
|
const styles = css({
|
|
@@ -20,8 +20,8 @@ typescriptEslintTester.run(
|
|
|
20
20
|
]
|
|
21
21
|
});
|
|
22
22
|
`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
errors: [{ messageId: 'no-array-values' }],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
27
|
);
|
|
@@ -2,15 +2,15 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
typescriptEslintTester.run(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
'no-unsafe-values',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [],
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
name: 'ternary value',
|
|
13
|
+
code: `
|
|
14
14
|
import { css } from '@compiled/react';
|
|
15
15
|
|
|
16
16
|
const isVisible = false;
|
|
@@ -18,11 +18,11 @@ typescriptEslintTester.run(
|
|
|
18
18
|
opacity: isVisible ? 1 : 0
|
|
19
19
|
});
|
|
20
20
|
`,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
errors: [{ messageId: 'no-conditional-values' }],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'boolean expression values',
|
|
25
|
+
code: `
|
|
26
26
|
import { css } from '@compiled/react';
|
|
27
27
|
|
|
28
28
|
const isVisible = false;
|
|
@@ -30,8 +30,8 @@ typescriptEslintTester.run(
|
|
|
30
30
|
opacity: isVisible && 1
|
|
31
31
|
});
|
|
32
32
|
`,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
errors: [{ messageId: 'no-conditional-values' }],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
37
|
);
|