@atlaskit/eslint-plugin-platform 2.7.0 → 2.7.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/index.js +0 -2
  3. package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +2 -2
  4. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  5. package/dist/cjs/rules/feature-gating/no-alias/index.js +1 -1
  6. package/dist/cjs/rules/util/context-compat.js +4 -2
  7. package/dist/es2019/index.js +0 -2
  8. package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +2 -2
  9. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  10. package/dist/es2019/rules/feature-gating/no-alias/index.js +1 -1
  11. package/dist/es2019/rules/util/context-compat.js +4 -2
  12. package/dist/esm/index.js +0 -2
  13. package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +2 -2
  14. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  15. package/dist/esm/rules/feature-gating/no-alias/index.js +1 -1
  16. package/dist/esm/rules/util/context-compat.js +4 -2
  17. package/dist/types/index.d.ts +4 -6
  18. package/dist/types/rules/util/handle-ast-object.d.ts +1 -1
  19. package/dist/types-ts4.5/index.d.ts +4 -6
  20. package/dist/types-ts4.5/rules/util/handle-ast-object.d.ts +1 -1
  21. package/package.json +2 -2
  22. package/afm-cc/tsconfig.json +0 -24
  23. package/afm-jira/tsconfig.json +0 -24
  24. package/build/tsconfig.json +0 -17
  25. package/dist/cjs/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -79
  26. package/dist/es2019/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -62
  27. package/dist/esm/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -75
  28. package/dist/types/rules/ensure-valid-platform-yarn-protocol-usage/index.d.ts +0 -3
  29. package/dist/types-ts4.5/rules/ensure-valid-platform-yarn-protocol-usage/index.d.ts +0 -3
  30. package/src/__tests__/utils/_tester.tsx +0 -26
  31. package/src/index.tsx +0 -254
  32. package/src/rules/compiled/README.md +0 -3
  33. package/src/rules/compiled/expand-background-shorthand/README.md +0 -23
  34. package/src/rules/compiled/expand-background-shorthand/__tests__/rule.test.ts +0 -160
  35. package/src/rules/compiled/expand-background-shorthand/index.tsx +0 -43
  36. package/src/rules/compiled/expand-border-shorthand/README.md +0 -51
  37. package/src/rules/compiled/expand-border-shorthand/__tests__/rule.test.ts +0 -211
  38. package/src/rules/compiled/expand-border-shorthand/index.ts +0 -103
  39. package/src/rules/compiled/expand-spacing-shorthand/README.md +0 -38
  40. package/src/rules/compiled/expand-spacing-shorthand/__tests__/rule.test.ts +0 -448
  41. package/src/rules/compiled/expand-spacing-shorthand/index.ts +0 -240
  42. package/src/rules/constants.tsx +0 -20
  43. package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +0 -24
  44. package/src/rules/ensure-atlassian-team/index.ts +0 -51
  45. package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +0 -200
  46. package/src/rules/ensure-critical-dependency-resolutions/index.tsx +0 -172
  47. package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +0 -65
  48. package/src/rules/ensure-feature-flag-prefix/index.tsx +0 -81
  49. package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +0 -115
  50. package/src/rules/ensure-feature-flag-registration/index.tsx +0 -106
  51. package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +0 -199
  52. package/src/rules/ensure-native-and-af-exports-synced/index.tsx +0 -188
  53. package/src/rules/ensure-no-private-dependencies/__tests__/unit/rule.test.ts +0 -212
  54. package/src/rules/ensure-no-private-dependencies/index.ts +0 -64
  55. package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +0 -39
  56. package/src/rules/ensure-publish-valid/index.ts +0 -81
  57. package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +0 -298
  58. package/src/rules/ensure-test-runner-arguments/index.tsx +0 -121
  59. package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +0 -308
  60. package/src/rules/ensure-test-runner-nested-count/index.tsx +0 -82
  61. package/src/rules/ensure-valid-bin-values/__tests__/unit/rule.test.ts +0 -159
  62. package/src/rules/ensure-valid-bin-values/index.ts +0 -70
  63. package/src/rules/ensure-valid-platform-yarn-protocol-usage/__tests__/unit/rule.test.ts +0 -147
  64. package/src/rules/ensure-valid-platform-yarn-protocol-usage/index.ts +0 -67
  65. package/src/rules/feature-gating/README.md +0 -8
  66. package/src/rules/feature-gating/inline-usage/README.md +0 -53
  67. package/src/rules/feature-gating/inline-usage/__tests__/rule.test.tsx +0 -106
  68. package/src/rules/feature-gating/inline-usage/index.tsx +0 -135
  69. package/src/rules/feature-gating/no-alias/README.md +0 -29
  70. package/src/rules/feature-gating/no-alias/__tests__/rule.test.tsx +0 -76
  71. package/src/rules/feature-gating/no-alias/index.tsx +0 -80
  72. package/src/rules/feature-gating/no-module-level-eval/README.md +0 -53
  73. package/src/rules/feature-gating/no-module-level-eval/__tests__/test.tsx +0 -133
  74. package/src/rules/feature-gating/no-module-level-eval/index.tsx +0 -54
  75. package/src/rules/feature-gating/no-module-level-eval-nav4/README.md +0 -8
  76. package/src/rules/feature-gating/no-module-level-eval-nav4/__tests__/test.tsx +0 -130
  77. package/src/rules/feature-gating/no-module-level-eval-nav4/index.tsx +0 -73
  78. package/src/rules/feature-gating/no-preconditioning/README.md +0 -69
  79. package/src/rules/feature-gating/no-preconditioning/__tests__/rule.test.tsx +0 -164
  80. package/src/rules/feature-gating/no-preconditioning/index.tsx +0 -138
  81. package/src/rules/feature-gating/prefer-fg/README.md +0 -3
  82. package/src/rules/feature-gating/prefer-fg/__tests__/rule.test.tsx +0 -83
  83. package/src/rules/feature-gating/prefer-fg/index.tsx +0 -110
  84. package/src/rules/feature-gating/static-feature-flags/README.md +0 -3
  85. package/src/rules/feature-gating/static-feature-flags/__tests__/test.tsx +0 -135
  86. package/src/rules/feature-gating/static-feature-flags/index.tsx +0 -103
  87. package/src/rules/feature-gating/use-recommended-utils/README.md +0 -67
  88. package/src/rules/feature-gating/use-recommended-utils/__tests__/rule.test.tsx +0 -78
  89. package/src/rules/feature-gating/use-recommended-utils/index.tsx +0 -57
  90. package/src/rules/feature-gating/utils.tsx +0 -48
  91. package/src/rules/no-direct-document-usage/index.tsx +0 -111
  92. package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +0 -116
  93. package/src/rules/no-duplicate-dependencies/index.ts +0 -79
  94. package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +0 -69
  95. package/src/rules/no-invalid-feature-flag-usage/index.tsx +0 -128
  96. package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +0 -18
  97. package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +0 -39
  98. package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +0 -41
  99. package/src/rules/no-pre-post-installs/index.ts +0 -35
  100. package/src/rules/no-set-immediate/index.tsx +0 -43
  101. package/src/rules/no-sparse-checkout/__tests__/unit/rule.test.tsx +0 -48
  102. package/src/rules/no-sparse-checkout/index.tsx +0 -54
  103. package/src/rules/use-entrypoints-in-examples/README.md +0 -27
  104. package/src/rules/use-entrypoints-in-examples/__tests__/rule.test.tsx +0 -34
  105. package/src/rules/use-entrypoints-in-examples/index.tsx +0 -43
  106. package/src/rules/util/__tests__/context-compat.test.ts +0 -122
  107. package/src/rules/util/compiled-utils.ts +0 -27
  108. package/src/rules/util/context-compat.ts +0 -41
  109. package/src/rules/util/file-exclusions.ts +0 -39
  110. package/src/rules/util/handle-ast-object.ts +0 -33
  111. package/src/rules/util/registration-utils.ts +0 -59
  112. package/tsconfig.app.json +0 -43
  113. package/tsconfig.dev.json +0 -40
  114. package/tsconfig.json +0 -23
@@ -1,448 +0,0 @@
1
- import { outdent } from 'outdent';
2
- import { tester } from '../../../../__tests__/utils/_tester';
3
- import { expandSpacingShorthand } from '../index';
4
-
5
- const included_compiled_libraries = ['@compiled/react', '@atlaskit/css'];
6
- const exempt_libraries = ['@emotion/react', 'styled-components'];
7
-
8
- const validTestCases = (property: string) => {
9
- return [
10
- ...exempt_libraries.map((imp) => ({
11
- name: `${property}: do not have to handle non-compiled packages (${imp})`,
12
- code: outdent`
13
- import {css} from '${imp}';
14
- import {xcss} from '@atlaskit/primitives';
15
-
16
- const styles = css({
17
- ${property}: token('space.200'),
18
- });
19
- const styles2 = xcss({
20
- ${property}: token('space.200'),
21
- });
22
- `,
23
- })),
24
- {
25
- name: `${property}: no spacing shorthand`,
26
- code: outdent`
27
- import {css} from '@compiled/react';
28
- const styles = css({
29
- ${property}Top: token('space.200'),
30
- ${property}Bottom: token('space.200'),
31
- ${property}Left: token('space.200'),
32
- ${property}Right: token('space.200'),
33
- });
34
- `,
35
- },
36
- {
37
- name: `${property}: do not have to handle plain string values`,
38
- code: outdent`
39
- import {css} from '@compiled/react';
40
- const styles = css({
41
- ${property}: '0 auto',
42
- });
43
- `,
44
- },
45
- {
46
- name: `${property}: do not handle dynamic style`,
47
- code: outdent`
48
- import {css} from '@compiled/react';
49
- const styles = css({
50
- ${property}: ({ isCompact }) => \`\${isCompact ? token('space.050', '4px') : token('space.075', '6px')}\`
51
- });
52
- `,
53
- },
54
- {
55
- name: `${property}: do not handle calc(...) as value`,
56
- code: outdent`
57
- import {css} from '@compiled/react';
58
- const styles = css({
59
- ${property}: \`calc(var(--preview-block-width) + \${token('space.200', '16px')})\`,
60
- });
61
- `,
62
- },
63
- {
64
- name: `${property}: do not handle template literal if no token(...) in the expressions`,
65
- code: outdent`
66
- import {css} from '@compiled/react';
67
- const styles = css({
68
- ${property}: \`0px 2\`,
69
- });
70
- `,
71
- },
72
- {
73
- name: `${property}: do not handle where value is a function call which is not a token`,
74
- code: outdent`
75
- import { css } from '@compiled/react';
76
- import { functionCall } from 'somewhere';
77
- const styles = css({
78
- ${property}: functionCall(),
79
- });
80
- `,
81
- },
82
- // Template literal containing expressions that is not token should only throw error with no autofix
83
- {
84
- name: `${property}: property value template string where it contains an expression that is not a token`,
85
- code: outdent`
86
- import {css} from '@compiled/react';
87
- const styles = css({
88
- ${property}: \`\${token('space.100', '8px')} \${gridSize * 2}px\`,
89
- });
90
- const styles2 = css({
91
- padding: \`\${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.075','6px')}
92
- \${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.200', '16px')}\`,
93
- });
94
- const styles3 = css({
95
- ${property}: \`\${token('space.050', '4px')} \${token('space.150', '12px')} \${token('space.150', '12px')}
96
- \${({ isSummaryView }: EditFormContentWrapperProps) =>
97
- isSummaryView ? token('space.0', '0') : token('space.150', '12px')}\`,
98
- });
99
- const styles4 = css({
100
- ${property}: \`\${token('space.100', '8px')} -\${gridSize}px 0\`,
101
- });
102
- `,
103
- },
104
- ];
105
- };
106
-
107
- const invalidTestCases = (property: string) => {
108
- return [
109
- // Value of spacing property is plain token() call
110
- ...included_compiled_libraries.map((imp) => ({
111
- name: `expand ${property} with value as token: (${imp})`,
112
- code: outdent`
113
- import {css} from '${imp}';
114
- const styles = css({
115
- ${property}: token('space.200'),
116
- });
117
- `,
118
- output: outdent`
119
- import {css} from '${imp}';
120
- const styles = css({
121
- ${property}Top: token('space.200'),
122
- ${property}Right: token('space.200'),
123
- ${property}Bottom: token('space.200'),
124
- ${property}Left: token('space.200'),
125
- });
126
- `,
127
- errors: [{ messageId: 'expandSpacingShorthand' }],
128
- })),
129
- // Value of spacing property is a template string
130
- ...included_compiled_libraries.map((imp) => ({
131
- name: `${property}: template string case (one value) (${imp})`,
132
- code: outdent`
133
- import {css} from '${imp}';
134
- const styles = css({
135
- ${property}: \`\${token('space.200')}\`,
136
- });
137
- `,
138
- output: outdent`
139
- import {css} from '${imp}';
140
- const styles = css({
141
- ${property}Top: token('space.200'),
142
- ${property}Right: token('space.200'),
143
- ${property}Bottom: token('space.200'),
144
- ${property}Left: token('space.200'),
145
- });
146
- `,
147
- errors: [{ messageId: 'expandSpacingShorthand' }],
148
- })),
149
- ...included_compiled_libraries.map((imp) => ({
150
- name: `${property}: template string case (two values) (${imp})`,
151
- code: outdent`
152
- import {css} from '${imp}';
153
- const styles = css({
154
- ${property}: \`\${token('space.100')} 0\`,
155
- });
156
- `,
157
- output: outdent`
158
- import {css} from '${imp}';
159
- const styles = css({
160
- ${property}Top: token('space.100'),
161
- ${property}Right: 0,
162
- ${property}Bottom: token('space.100'),
163
- ${property}Left: 0,
164
- });
165
- `,
166
- errors: [{ messageId: 'expandSpacingShorthand' }],
167
- })),
168
- ...included_compiled_libraries.map((imp) => ({
169
- name: `${property}: template string case (three values) (${imp})`,
170
- code: outdent`
171
- import {css} from '${imp}';
172
- const styles = css({
173
- ${property}: \`\${token('space.100')} 0 2px\`,
174
- });
175
- `,
176
- output: outdent`
177
- import {css} from '${imp}';
178
- const styles = css({
179
- ${property}Top: token('space.100'),
180
- ${property}Right: 0,
181
- ${property}Bottom: '2px',
182
- ${property}Left: 0,
183
- });
184
- `,
185
- errors: [{ messageId: 'expandSpacingShorthand' }],
186
- })),
187
- ...included_compiled_libraries.map((imp) => ({
188
- name: `${property}: template string case (four values) (${imp})`,
189
- code: outdent`
190
- import {css} from '${imp}';
191
- const styles = css({
192
- ${property}: \`\${token('space.100')} 0 0px 12px\`,
193
- });
194
- const styles2 = css({
195
- ${property}: \`\${token('space.100')} \${token('space.200')} \${token('space.300')} \${token('space.400')}\`,
196
- });
197
- `,
198
- output: outdent`
199
- import {css} from '${imp}';
200
- const styles = css({
201
- ${property}Top: token('space.100'),
202
- ${property}Right: 0,
203
- ${property}Bottom: '0px',
204
- ${property}Left: '12px',
205
- });
206
- const styles2 = css({
207
- ${property}Top: token('space.100'),
208
- ${property}Right: token('space.200'),
209
- ${property}Bottom: token('space.300'),
210
- ${property}Left: token('space.400'),
211
- });
212
- `,
213
- errors: Array.from(Array(2), () => ({ messageId: 'expandSpacingShorthand' })),
214
- })),
215
- {
216
- name: `${property}: compiled import (styled.div, @compiled/react)`,
217
- code: outdent`
218
- import { styled } from '@compiled/react';
219
- const styledDiv = styled.div({
220
- ${property}: \`0 \${token('space.100', '8px')} 0 0\`,
221
- });
222
- `,
223
- output: outdent`
224
- import { styled } from '@compiled/react';
225
- const styledDiv = styled.div({
226
- ${property}Top: 0,
227
- ${property}Right: token('space.100', '8px'),
228
- ${property}Bottom: 0,
229
- ${property}Left: 0,
230
- });
231
- `,
232
- errors: [{ messageId: 'expandSpacingShorthand' }],
233
- },
234
- {
235
- name: `${property}: compiled import (cssMap, @compiled/react)`,
236
- code: outdent`
237
- import { cssMap } from '@compiled/react';
238
- const backgroundMap = cssMap({
239
- firstDiv: { ${property}: token('space.100') },
240
- secondDiv: { ${property}: token('space.100') },
241
- });
242
- `,
243
- output: outdent`
244
- import { cssMap } from '@compiled/react';
245
- const backgroundMap = cssMap({
246
- firstDiv: { ${property}Top: token('space.100'),
247
- ${property}Right: token('space.100'),
248
- ${property}Bottom: token('space.100'),
249
- ${property}Left: token('space.100') },
250
- secondDiv: { ${property}Top: token('space.100'),
251
- ${property}Right: token('space.100'),
252
- ${property}Bottom: token('space.100'),
253
- ${property}Left: token('space.100') },
254
- });
255
- `,
256
- errors: Array.from(Array(2), () => ({ messageId: 'expandSpacingShorthand' })),
257
- },
258
- {
259
- name: `${property}: compiled import with alias`,
260
- code: outdent`
261
- import { styled as styled2 } from '@compiled/react';
262
- const style = styled2.span({
263
- ${property}: \`0 \${token('space.100', '8px')} 0 0\`,
264
- });
265
- `,
266
- output: outdent`
267
- import { styled as styled2 } from '@compiled/react';
268
- const style = styled2.span({
269
- ${property}Top: 0,
270
- ${property}Right: token('space.100', '8px'),
271
- ${property}Bottom: 0,
272
- ${property}Left: 0,
273
- });
274
- `,
275
- errors: [{ messageId: 'expandSpacingShorthand' }],
276
- },
277
- // Strings that are not valid property values should not be autofixed (e.g. !important)
278
- {
279
- name: `${property}: Don't autofix if not able to handle all the string values, e.g !important`,
280
- code: outdent`
281
- import {css} from '@compiled/react';
282
- const styles = css({
283
- ${property}: \`0 \${token('space.200', '16px')} !important\`,
284
- });
285
- `,
286
- errors: [{ messageId: 'expandSpacingShorthand' }],
287
- },
288
- {
289
- name: `${property}: Autofix if able to handle all string values`,
290
- code: outdent`
291
- import {css} from '@compiled/react';
292
- const styles = css({
293
- ${property}: \`0 auto \${token('space.300', '24px')}\`,
294
- });
295
- `,
296
- output: outdent`
297
- import {css} from '@compiled/react';
298
- const styles = css({
299
- ${property}Top: 0,
300
- ${property}Right: 'auto',
301
- ${property}Bottom: token('space.300', '24px'),
302
- ${property}Left: 'auto',
303
- });
304
- `,
305
- errors: [{ messageId: 'expandSpacingShorthand' }],
306
- },
307
- // Miscellaneous
308
- {
309
- name: `${property}: new property should not be created if existing property already exists`,
310
- code: outdent`
311
- import {css} from '@compiled/react';
312
- const styles = css({
313
- ${property}: token('space.100'),
314
- ${property}Top: token('space.200'),
315
- });
316
- `,
317
- output: outdent`
318
- import {css} from '@compiled/react';
319
- const styles = css({
320
- ${property}Top: token('space.200'),
321
- ${property}Right: token('space.100'),
322
- ${property}Bottom: token('space.100'),
323
- ${property}Left: token('space.100'),
324
- });
325
- `,
326
- errors: [{ messageId: 'expandSpacingShorthand' }],
327
- },
328
- {
329
- name: `${property}: property with nested selectors`,
330
- code: outdent`
331
- import {css} from '@compiled/react';
332
- const styles = css({
333
- ${property}: token('space.100'),
334
- '.some-selector': {
335
- ${property}Top: token('space.200'),
336
- }
337
- });
338
- const styles2 = css({
339
- ${property}Top: token('space.100'),
340
- '.some-selector': {
341
- ${property}: token('space.200'),
342
- }
343
- });
344
- const styles3 = css({
345
- '.some-selector': {
346
- ${property}: token('space.200'),
347
- ${property}Top: token('space.100'),
348
- }
349
- });
350
- `,
351
- output: outdent`
352
- import {css} from '@compiled/react';
353
- const styles = css({
354
- ${property}Top: token('space.100'),
355
- ${property}Right: token('space.100'),
356
- ${property}Bottom: token('space.100'),
357
- ${property}Left: token('space.100'),
358
- '.some-selector': {
359
- ${property}Top: token('space.200'),
360
- }
361
- });
362
- const styles2 = css({
363
- ${property}Top: token('space.100'),
364
- '.some-selector': {
365
- ${property}Top: token('space.200'),
366
- ${property}Right: token('space.200'),
367
- ${property}Bottom: token('space.200'),
368
- ${property}Left: token('space.200'),
369
- }
370
- });
371
- const styles3 = css({
372
- '.some-selector': {
373
- ${property}Top: token('space.100'),
374
- ${property}Right: token('space.200'),
375
- ${property}Bottom: token('space.200'),
376
- ${property}Left: token('space.200'),
377
- }
378
- });
379
- `,
380
- errors: Array.from(Array(3), () => ({ messageId: 'expandSpacingShorthand' })),
381
- },
382
- {
383
- name: `${property}: property value includes newline and tab`,
384
- code: outdent`
385
- import {css} from '@compiled/react';
386
- const styles = css({
387
- ${property}: \`\${token('space.100')} \${token('space.200')}
388
- \${token('space.300')} \${token('space.400')}\`,
389
- });
390
- const styles2 = css({
391
- paddingBottom: token('space.050', '4px'),
392
- '&& > span': {
393
- padding: \`\${token('space.100', '8px')} \${token('space.150', '12px')} 7px
394
- \${token('space.150', '12px')}\`,
395
- },
396
- });
397
- `,
398
- output: outdent`
399
- import {css} from '@compiled/react';
400
- const styles = css({
401
- ${property}Top: token('space.100'),
402
- ${property}Right: token('space.200'),
403
- ${property}Bottom: token('space.300'),
404
- ${property}Left: token('space.400'),
405
- });
406
- const styles2 = css({
407
- paddingBottom: token('space.050', '4px'),
408
- '&& > span': {
409
- paddingTop: token('space.100', '8px'),
410
- paddingRight: token('space.150', '12px'),
411
- paddingBottom: '7px',
412
- paddingLeft: token('space.150', '12px'),
413
- },
414
- });
415
- `,
416
- errors: Array.from(Array(2), () => ({ messageId: 'expandSpacingShorthand' })),
417
- },
418
- // // TODO (AFB-1022): Resolve this failing test
419
- // {
420
- // name: `${property}: styled components with prop input`,
421
- // code: outdent`
422
- // import { styled } from '@compiled/react';
423
- // const MenuOptionWrapper = styled.div<{ isDisabled: boolean }>({
424
- // '& button': ({ isDisabled }) => ({
425
- // ${property}: \`\${token('space.075', '6px')} \${token('space.200', '16px')}\`,
426
- // }),
427
- // });
428
- // `,
429
- // output: outdent`
430
- // import { styled } from '@compiled/react';
431
- // const MenuOptionWrapper = styled.div<{ isDisabled: boolean }>({
432
- // '& button': ({ isDisabled }) => ({
433
- // ${property}Top: token('space.075', '6px'),
434
- // ${property}Right: token('space.200', '16px'),
435
- // ${property}Bottom: token('space.075', '6px'),
436
- // ${property}Left: token('space.200', '16px'),
437
- // }),
438
- // });
439
- // `,
440
- // errors: [{ messageId: 'expandSpacingShorthand' }],
441
- // },
442
- ];
443
- };
444
-
445
- tester.run('expand-spacing-shorthand', expandSpacingShorthand, {
446
- valid: [...validTestCases('padding'), ...validTestCases('margin')],
447
- invalid: [...invalidTestCases('padding'), ...invalidTestCases('margin')],
448
- });
@@ -1,240 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import type { Property, Node, TemplateLiteral, CallExpression } from 'estree';
3
- import { getSourceCode } from '../../util/context-compat';
4
- import { isCompiledAPI } from '../../util/compiled-utils';
5
-
6
- const spacingPos = ['Top', 'Right', 'Bottom', 'Left'] as const;
7
-
8
- interface ExpandSpacingPropertiesType {
9
- context: Rule.RuleContext;
10
- node: Property & { parent?: Node };
11
- propertyValues: string[];
12
- fixer: Rule.RuleFixer;
13
- propertyShorthand: string;
14
- }
15
-
16
- // Checks if node is a call expression with identifier 'token'
17
- const isTokenCallExpression = (node: CallExpression) => {
18
- if (node.callee.type === 'Identifier' && node.callee.name === 'token') {
19
- return true;
20
- }
21
- return false;
22
- };
23
-
24
- // Given a TemplateLiteral node, returns the value of the spacing property as an array of strings
25
- // e.g. `0 ${token('a')} ${token('b')}` -> ['0', 'token('a')', 'token('b')']
26
- const parseTemplateLiteral = (templateLiteral: TemplateLiteral, context: Rule.RuleContext) => {
27
- const expressions = templateLiteral.expressions;
28
- const quasis = templateLiteral.quasis;
29
-
30
- let propertyValues: string[] = [];
31
- for (let i = 0; i < expressions.length || i < quasis.length; i++) {
32
- if (i < quasis.length) {
33
- const cookedQuasi = quasis[i].value.cooked;
34
- if (cookedQuasi) {
35
- const splitQuasis = cookedQuasi.split(' ');
36
- splitQuasis.forEach((str) => {
37
- str = str.trim().replace("'", '');
38
- if (str.length > 0) {
39
- propertyValues.push(isNaN(Number(str)) ? `'${str}'` : str);
40
- }
41
- });
42
- }
43
- }
44
- if (i < expressions.length) {
45
- const expr = getSourceCode(context).getText(expressions[i]);
46
- propertyValues.push(expr);
47
- }
48
- }
49
- return propertyValues;
50
- };
51
-
52
- /**
53
- * Checks if the parsed property values are valid; values that we shouldn't handle with the fixer:
54
- * 1. At least one expression in TemplateLiteral is not a token expression
55
- * 2. Do not contain a token
56
- * 3. Have length that are not in the range [1, 4] for different spacing directions
57
- * - No more than 4 to exclude additional values such as `!important`
58
- * 4. Includes `calc(...)`
59
- * Then, the rule will return with no error
60
- * @param propertyValues property values parsed as list of strings
61
- * @returns boolean
62
- */
63
- const isPropertyValueExempted = (templateLiteral: TemplateLiteral, propertyValues: string[]) => {
64
- const expressions = templateLiteral.expressions;
65
- if (!expressions.every((expr) => expr.type === 'CallExpression' && isTokenCallExpression(expr))) {
66
- return true;
67
- }
68
- if (!propertyValues.some((str) => str.includes('token('))) {
69
- return true;
70
- }
71
- if (propertyValues.length < 1 || propertyValues.length > 4) {
72
- return true;
73
- }
74
- if (propertyValues.some((str) => str.includes('calc('))) {
75
- return true;
76
- }
77
- return false;
78
- };
79
-
80
- /**
81
- * Checks if the parsed property values are invalid (i.e. rule violation thrown) and autofix required. Cases are when
82
- * property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
83
- * The rule will return with error and provide a fix
84
- * @param templateLiteral TemplateLiteral AST Node
85
- * @param propertyValues property values parsed as list of strings
86
- * @returns boolean
87
- */
88
- const isPropertyValuesInvalidFix = (propertyValues: string[]) => {
89
- for (const propValue of propertyValues) {
90
- if (propValue === '0') {
91
- continue;
92
- }
93
- if (['auto', 'initial', 'inherit'].includes(propValue.slice(1, -1))) {
94
- continue;
95
- }
96
- if (/^token\(.*\)$/.test(propValue)) {
97
- continue;
98
- }
99
- if (/^['"]\d+(\.\d+)?((rem)|(em)|(px))['"]$/.test(propValue)) {
100
- continue;
101
- }
102
- return false;
103
- }
104
- return true;
105
- };
106
-
107
- // To fix spacing shorthands, given a list of spacing property values, expands the spacing property and adds autofix fixes
108
- const expandSpacingProperties = ({
109
- context,
110
- node,
111
- propertyValues,
112
- fixer,
113
- propertyShorthand,
114
- }: ExpandSpacingPropertiesType) => {
115
- const [top, right = top, bottom = top, left = right] = propertyValues;
116
- const spacing: string[] = [top, right, bottom, left];
117
-
118
- const fixes: Rule.Fix[] = [];
119
-
120
- const parentNode = node.parent;
121
- if (parentNode && parentNode.type === 'ObjectExpression') {
122
- for (var prop of parentNode.properties) {
123
- if (prop.type !== 'Property') {
124
- continue;
125
- }
126
- if (
127
- prop.key.type === 'Identifier' &&
128
- prop.range &&
129
- prop.key.name !== `${propertyShorthand}`
130
- ) {
131
- for (let i = 0; i < spacing.length; i++) {
132
- if (prop.key.name === `${propertyShorthand}${spacingPos[i]}`) {
133
- let [start, end] = prop.range;
134
- // Remove the entire line for the duplicate property
135
- while (getSourceCode(context).text[end] !== '\n') {
136
- end += 1;
137
- }
138
- while (getSourceCode(context).text[start] !== '\n') {
139
- start -= 1;
140
- }
141
- spacing[i] = getSourceCode(context).getText(prop.value);
142
- fixes.push(fixer.removeRange([start, end]));
143
- break;
144
- }
145
- }
146
- }
147
- }
148
- }
149
-
150
- fixes.push(fixer.insertTextAfter(node, `${propertyShorthand}Top: ${spacing[0]},\n`));
151
- fixes.push(fixer.insertTextAfter(node, `\t${propertyShorthand}Right: ${spacing[1]},\n`));
152
- fixes.push(fixer.insertTextAfter(node, `\t${propertyShorthand}Bottom: ${spacing[2]},\n`));
153
- fixes.push(fixer.insertTextAfter(node, `\t${propertyShorthand}Left: ${spacing[3]}`));
154
- fixes.push(fixer.remove(node));
155
- return fixes;
156
- };
157
-
158
- const executeExpandSpacingRule = (
159
- context: Rule.RuleContext,
160
- node: Property,
161
- propertyShorthand: string,
162
- ) => {
163
- if (!isCompiledAPI(context, node)) {
164
- return;
165
- }
166
- if (node.value.type === 'TemplateLiteral') {
167
- const propertyValues = parseTemplateLiteral(node.value, context);
168
- if (isPropertyValueExempted(node.value, propertyValues)) {
169
- // Valid, so no error should be thrown
170
- return;
171
- }
172
- if (isPropertyValuesInvalidFix(propertyValues)) {
173
- // Invalid, so error should be thrown and fix provided
174
- context.report({
175
- node,
176
- messageId: 'expandSpacingShorthand',
177
- data: {
178
- property: propertyShorthand,
179
- },
180
- fix(fixer) {
181
- return expandSpacingProperties({
182
- context,
183
- node,
184
- propertyValues,
185
- fixer,
186
- propertyShorthand,
187
- });
188
- },
189
- });
190
- } else {
191
- context.report({
192
- node,
193
- messageId: 'expandSpacingShorthand',
194
- data: {
195
- property: propertyShorthand,
196
- },
197
- });
198
- return;
199
- }
200
- } else if (node.value.type === 'CallExpression' && isTokenCallExpression(node.value)) {
201
- // Value of spacing property is a token CallExpression type, e.g. margin: token('space.100', '8px')
202
- const propertyValues = [getSourceCode(context).getText(node.value)];
203
- context.report({
204
- node,
205
- messageId: 'expandSpacingShorthand',
206
- data: {
207
- property: propertyShorthand,
208
- },
209
- fix(fixer) {
210
- return expandSpacingProperties({ context, node, propertyValues, fixer, propertyShorthand });
211
- },
212
- });
213
- }
214
- };
215
-
216
- export const expandSpacingShorthand: Rule.RuleModule = {
217
- meta: {
218
- docs: {
219
- url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-spacing-shorthand/',
220
- },
221
- messages: {
222
- expandSpacingShorthand:
223
- 'Use {{ property }}Top, {{ property }}Right, {{ property }}Bottom and {{ property }}Left instead of {{ property }} shorthand',
224
- },
225
- type: 'problem',
226
- fixable: 'code',
227
- },
228
- create(context) {
229
- return {
230
- 'Property[key.name="padding"]': function (node: Property) {
231
- executeExpandSpacingRule(context, node, 'padding');
232
- },
233
- 'Property[key.name="margin"]': function (node: Property) {
234
- executeExpandSpacingRule(context, node, 'margin');
235
- },
236
- };
237
- },
238
- };
239
-
240
- export default expandSpacingShorthand;
@@ -1,20 +0,0 @@
1
- // List of libraries that we maintain or have worked on
2
- // - eg `@atlaskit/feature-gate-js-client` shouldn't be included in here
3
- export const FEATURE_API_IMPORT_SOURCES = new Set([
4
- '@atlassian/jira-feature-flagging',
5
- '@atlassian/jira-feature-flagging-using-meta',
6
- '@atlassian/jira-feature-gating',
7
- '@atlassian/jira-feature-experiments',
8
- '@atlaskit/platform-feature-flags',
9
- ]);
10
-
11
- export const FEATURE_MOCKS_IMPORT_SOURCES = new Set([
12
- '@atlassian/jira-feature-flagging-mocks',
13
- '@atlassian/jira-feature-gates-test-mocks',
14
- '@atlassian/jira-feature-gates-storybook-mocks',
15
- ]);
16
-
17
- export const FEATURE_UTILS_IMPORT_SOURCES = new Set([
18
- '@atlassian/jira-feature-flagging-utils',
19
- '@atlassian/jira-feature-gate-component',
20
- ]);