@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.1
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/consistent-css-prop-usage/usage.mdx +3 -1
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/constellation/no-css-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-empty-styled-expression/usage.mdx +5 -2
- package/constellation/no-exported-css/usage.mdx +5 -2
- package/constellation/no-exported-keyframes/usage.mdx +5 -2
- package/constellation/no-invalid-css-map/usage.mdx +5 -2
- package/constellation/no-js-xcss/usage.mdx +3 -1
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-suppress-xcss/usage.mdx +6 -3
- 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 +141 -128
- 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 +133 -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
|
@@ -2,14 +2,14 @@ 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
|
-
|
|
5
|
+
'no-imported-style-values',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [
|
|
10
|
+
{
|
|
11
|
+
name: 'Basic valid test for css',
|
|
12
|
+
code: `
|
|
13
13
|
import { css } from '@compiled/react';
|
|
14
14
|
const sharedObject = { padding: 0 };
|
|
15
15
|
const styles = css({
|
|
@@ -17,10 +17,10 @@ typescriptEslintTester.run(
|
|
|
17
17
|
color: 'red',
|
|
18
18
|
});
|
|
19
19
|
`,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'Valid emotion css call',
|
|
23
|
+
code: `
|
|
24
24
|
import { css } from '@emotion/react';
|
|
25
25
|
import { CURRENT_SURFACE_CSS_VAR, token } from '@atlaskit/tokens';
|
|
26
26
|
const styles = css({
|
|
@@ -29,20 +29,20 @@ typescriptEslintTester.run(
|
|
|
29
29
|
[CURRENT_SURFACE_CSS_VAR]: token('elevation.surface.overlay', N0),
|
|
30
30
|
});
|
|
31
31
|
`,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Valid styled component',
|
|
35
|
+
code: `
|
|
36
36
|
import { styled } from '@compiled/react';
|
|
37
37
|
import { token } from '@atlaskit/tokens';
|
|
38
38
|
const Component = styled.div({
|
|
39
39
|
borderRadius: token('border.radius', '3px')
|
|
40
40
|
})
|
|
41
41
|
`,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'Variables defined in same file',
|
|
45
|
+
code: `
|
|
46
46
|
import { css } from '@compiled/react';
|
|
47
47
|
const color = 'red',
|
|
48
48
|
const containerWidth = 0;
|
|
@@ -51,20 +51,20 @@ typescriptEslintTester.run(
|
|
|
51
51
|
width: containerWidth
|
|
52
52
|
});
|
|
53
53
|
`,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'Importing token function',
|
|
57
|
+
code: `
|
|
58
58
|
import { css } from '@compiled/react';
|
|
59
59
|
import { token } from '@atlaskit/tokens';
|
|
60
60
|
const styles = css({
|
|
61
61
|
padding: token('space.150'),
|
|
62
62
|
});
|
|
63
63
|
`,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'Valid cssMap call',
|
|
67
|
+
code: `
|
|
68
68
|
import { cssMap } from '@compiled/react';
|
|
69
69
|
import { token } from '@atlaskit/tokens';
|
|
70
70
|
const styles = cssMap({
|
|
@@ -77,57 +77,57 @@ typescriptEslintTester.run(
|
|
|
77
77
|
},
|
|
78
78
|
});
|
|
79
79
|
`,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'Custom import sources (subtractive)',
|
|
83
|
+
code: `
|
|
84
84
|
import { css } from '@compiled/react';
|
|
85
85
|
import { color } from '../shared'
|
|
86
86
|
const styles = css({
|
|
87
87
|
color
|
|
88
88
|
});
|
|
89
89
|
`,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
options: [
|
|
91
|
+
{
|
|
92
|
+
importSources: [],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Custom allowed function',
|
|
98
|
+
code: `
|
|
99
99
|
import { css } from '@compiled/react';
|
|
100
100
|
import { getColor } from 'my-package'
|
|
101
101
|
const styles = css({
|
|
102
102
|
color: getColor()
|
|
103
103
|
});
|
|
104
104
|
`,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
options: [
|
|
106
|
+
{
|
|
107
|
+
allowedFunctionCalls: [['my-package', 'getColor']],
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'Custom allowed dynamic key',
|
|
113
|
+
code: `
|
|
114
114
|
import { css } from '@compiled/react';
|
|
115
115
|
import { colorKey } from 'my-package';
|
|
116
116
|
const styles = css({
|
|
117
117
|
[colorKey]: 'red',
|
|
118
118
|
});
|
|
119
119
|
`,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
120
|
+
options: [
|
|
121
|
+
{
|
|
122
|
+
allowedDynamicKeys: [['my-package', 'colorKey']],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
invalid: [
|
|
128
|
+
{
|
|
129
|
+
name: 'Importing spreadElement',
|
|
130
|
+
code: `
|
|
131
131
|
import { css } from '@compiled/react';
|
|
132
132
|
import { importedStyles } from '../shared';
|
|
133
133
|
const styles = css({
|
|
@@ -135,11 +135,11 @@ typescriptEslintTester.run(
|
|
|
135
135
|
color: 'red',
|
|
136
136
|
});
|
|
137
137
|
`,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'Importing functions to use within css',
|
|
142
|
+
code: `
|
|
143
143
|
import { css } from '@compiled/react';
|
|
144
144
|
import { getColor } from '@mui/theme';
|
|
145
145
|
import { colorKey } from '../shared';
|
|
@@ -147,36 +147,36 @@ typescriptEslintTester.run(
|
|
|
147
147
|
[colorKey]: getColor('red'),
|
|
148
148
|
});
|
|
149
149
|
`,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
errors: [
|
|
151
|
+
{ messageId: 'no-imported-style-values' },
|
|
152
|
+
{ messageId: 'no-imported-style-values' },
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'Importing objects to use within css',
|
|
157
|
+
code: `
|
|
158
158
|
import { css } from '@compiled/react';
|
|
159
159
|
import { colors } from '@mui/theme';
|
|
160
160
|
const styles = css({
|
|
161
161
|
background: colors['red'],
|
|
162
162
|
});
|
|
163
163
|
`,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'Importing variables to use within template literal',
|
|
168
|
+
code: `
|
|
169
169
|
import { css } from '@compiled/react';
|
|
170
170
|
import { HEIGHT } from '../shared';
|
|
171
171
|
const styles = css({
|
|
172
172
|
height: \`\${HEIGHT}px\`,
|
|
173
173
|
});
|
|
174
174
|
`,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'Importing variables to within conditional expression',
|
|
179
|
+
code: `
|
|
180
180
|
import { css } from '@compiled/react';
|
|
181
181
|
import { ff } from '@atlaskit/ff';
|
|
182
182
|
import { HEIGHT } from '../shared';
|
|
@@ -184,14 +184,14 @@ typescriptEslintTester.run(
|
|
|
184
184
|
width: ff('…') ? \`\${HEIGHT}px\` : undefined,
|
|
185
185
|
});
|
|
186
186
|
`,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
errors: [
|
|
188
|
+
{ messageId: 'no-imported-style-values' },
|
|
189
|
+
{ messageId: 'no-imported-style-values' },
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: 'Invalid styled component',
|
|
194
|
+
code: `
|
|
195
195
|
import { styled } from '@compiled/react';
|
|
196
196
|
import { HEIGHT, importedStyles, getWidth } from '../shared';
|
|
197
197
|
|
|
@@ -203,15 +203,15 @@ typescriptEslintTester.run(
|
|
|
203
203
|
width: getWidth(10),
|
|
204
204
|
});
|
|
205
205
|
`,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
206
|
+
errors: [
|
|
207
|
+
{ messageId: 'no-imported-style-values' },
|
|
208
|
+
{ messageId: 'no-imported-style-values' },
|
|
209
|
+
{ messageId: 'no-imported-style-values' },
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'Invalid cssMap call',
|
|
214
|
+
code: `
|
|
215
215
|
import { cssMap } from '@compiled/react';
|
|
216
216
|
import { textColor, bgColor } from '../shared';
|
|
217
217
|
|
|
@@ -220,14 +220,14 @@ typescriptEslintTester.run(
|
|
|
220
220
|
bg: { background: bgColor },
|
|
221
221
|
});
|
|
222
222
|
`,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
errors: [
|
|
224
|
+
{ messageId: 'no-imported-style-values' },
|
|
225
|
+
{ messageId: 'no-imported-style-values' },
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: 'Invalid style composition in css prop',
|
|
230
|
+
code: `
|
|
231
231
|
import { css } from '@compiled/react';
|
|
232
232
|
import { buttonStyles } from '../shared';
|
|
233
233
|
|
|
@@ -237,20 +237,20 @@ typescriptEslintTester.run(
|
|
|
237
237
|
|
|
238
238
|
export default () => <div css={[styles, buttonStyles]} />;
|
|
239
239
|
`,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: 'Importing value within style prop',
|
|
244
|
+
code: `
|
|
245
245
|
import { importedWidth } from '../shared';
|
|
246
246
|
|
|
247
247
|
export default () => <div style={{ width: importedWidth }} />;
|
|
248
248
|
`,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'Importing member expression',
|
|
253
|
+
code: `
|
|
254
254
|
import { hello } from 'package';
|
|
255
255
|
import { css } from '@compiled/react';
|
|
256
256
|
|
|
@@ -258,8 +258,8 @@ typescriptEslintTester.run(
|
|
|
258
258
|
color: hello.world,
|
|
259
259
|
});
|
|
260
260
|
`,
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
},
|
|
265
265
|
);
|
|
@@ -1,154 +1,150 @@
|
|
|
1
1
|
import { createLintRule } from '../utils/create-rule';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
getImportSources,
|
|
4
|
+
hasStyleObjectArguments,
|
|
5
5
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
6
|
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
7
7
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
8
8
|
import type { Rule } from 'eslint';
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
type AllowList,
|
|
11
|
+
getAllowedDynamicKeys,
|
|
12
|
+
getAllowedFunctionCalls,
|
|
13
|
+
isAllowListedVariable,
|
|
14
14
|
} from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
15
15
|
import type { Identifier, Node } from 'eslint-codemod-utils';
|
|
16
16
|
import esquery from 'esquery';
|
|
17
17
|
|
|
18
18
|
const schema: JSONSchema4 = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
{
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
importSources: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
items: { type: 'string' },
|
|
25
|
+
uniqueItems: true,
|
|
26
|
+
},
|
|
27
|
+
allowedFunctionCalls: {
|
|
28
|
+
type: 'array',
|
|
29
|
+
items: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
minItems: 2,
|
|
32
|
+
maxItems: 2,
|
|
33
|
+
items: [{ type: 'string' }, { type: 'string' }],
|
|
34
|
+
},
|
|
35
|
+
uniqueItems: true,
|
|
36
|
+
},
|
|
37
|
+
allowedDynamicKeys: {
|
|
38
|
+
type: 'array',
|
|
39
|
+
items: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
minItems: 2,
|
|
42
|
+
maxItems: 2,
|
|
43
|
+
items: [{ type: 'string' }, { type: 'string' }],
|
|
44
|
+
},
|
|
45
|
+
uniqueItems: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
49
|
];
|
|
50
50
|
|
|
51
51
|
const isIdentifierImported = (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
identifier: Identifier,
|
|
53
|
+
context: Rule.RuleContext,
|
|
54
|
+
functionAllowList: AllowList,
|
|
55
|
+
keysAllowList: AllowList,
|
|
56
56
|
): boolean => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
const variable = findVariable({
|
|
58
|
+
identifier: identifier,
|
|
59
|
+
sourceCode: context.sourceCode,
|
|
60
|
+
});
|
|
61
|
+
if (!variable) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
(definition) => definition.type === 'ImportBinding',
|
|
67
|
-
);
|
|
65
|
+
const isImported = variable.defs.some((definition) => definition.type === 'ImportBinding');
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
// check if imported variable is allowed
|
|
68
|
+
return (
|
|
69
|
+
isImported &&
|
|
70
|
+
!isAllowListedVariable({
|
|
71
|
+
allowList: functionAllowList,
|
|
72
|
+
variable,
|
|
73
|
+
}) &&
|
|
74
|
+
!isAllowListedVariable({ allowList: keysAllowList, variable })
|
|
75
|
+
);
|
|
78
76
|
};
|
|
79
77
|
|
|
80
78
|
const checkIdentifier = (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
identifier: Identifier,
|
|
80
|
+
context: Rule.RuleContext,
|
|
81
|
+
functionAllowList: AllowList,
|
|
82
|
+
keysAllowList: AllowList,
|
|
85
83
|
) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
}
|
|
84
|
+
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
85
|
+
context.report({
|
|
86
|
+
node: identifier,
|
|
87
|
+
messageId: 'no-imported-style-values',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
export const rule = createLintRule({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
meta: {
|
|
94
|
+
name: 'no-imported-style-values',
|
|
95
|
+
docs: {
|
|
96
|
+
description: 'Disallows imports of style values',
|
|
97
|
+
recommended: true,
|
|
98
|
+
severity: 'warn',
|
|
99
|
+
},
|
|
100
|
+
messages: {
|
|
101
|
+
'no-imported-style-values':
|
|
102
|
+
'Styles should not be imported to use in css, cssMap, styled, keyframes or xcss calls. All styles should be defined and used in the same file instead.',
|
|
103
|
+
},
|
|
104
|
+
type: 'problem',
|
|
105
|
+
schema,
|
|
106
|
+
},
|
|
107
|
+
create(context) {
|
|
108
|
+
const importSources = getImportSources(context);
|
|
109
|
+
const functionAllowList = getAllowedFunctionCalls(context.options);
|
|
110
|
+
const keysAllowList = getAllowedDynamicKeys(context.options);
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
const checkForIdentifiers = (node: Node) => {
|
|
113
|
+
const matches = esquery(node, 'Identifier');
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
for (const match of matches) {
|
|
116
|
+
if (match.type === 'Identifier') {
|
|
117
|
+
checkIdentifier(match, context, functionAllowList, keysAllowList);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
125
121
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
122
|
+
return {
|
|
123
|
+
// Checking css/cssMap/keyframes/styled/xcss calls
|
|
124
|
+
CallExpression(node) {
|
|
125
|
+
const { references } = context.sourceCode.getScope(node.callee);
|
|
130
126
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
node.arguments.forEach(checkForIdentifiers);
|
|
131
|
+
},
|
|
132
|
+
'JSXAttribute[name.name="css"] Identifier': (node: Node) => {
|
|
133
|
+
if (node.type !== 'Identifier') {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
140
136
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
138
|
+
},
|
|
139
|
+
'JSXAttribute[name.name="style"] Identifier': (node: Node) => {
|
|
140
|
+
if (node.type !== 'Identifier') {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
147
143
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
},
|
|
152
148
|
});
|
|
153
149
|
|
|
154
150
|
export default rule;
|