@atlaskit/eslint-plugin-platform 2.0.2 → 2.1.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 (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/index.js +3 -0
  3. package/dist/cjs/rules/compiled/expand-background-shorthand/index.js +2 -17
  4. package/dist/cjs/rules/compiled/expand-spacing-shorthand/index.js +214 -0
  5. package/dist/cjs/rules/util/compiled-utils.js +21 -0
  6. package/dist/cjs/rules/util/context-compat.js +2 -2
  7. package/dist/es2019/index.js +3 -0
  8. package/dist/es2019/rules/compiled/expand-background-shorthand/index.js +1 -15
  9. package/dist/es2019/rules/compiled/expand-spacing-shorthand/index.js +178 -0
  10. package/dist/es2019/rules/util/compiled-utils.js +15 -0
  11. package/dist/es2019/rules/util/context-compat.js +1 -1
  12. package/dist/esm/index.js +3 -0
  13. package/dist/esm/rules/compiled/expand-background-shorthand/index.js +1 -16
  14. package/dist/esm/rules/compiled/expand-spacing-shorthand/index.js +207 -0
  15. package/dist/esm/rules/util/compiled-utils.js +16 -0
  16. package/dist/esm/rules/util/context-compat.js +1 -1
  17. package/dist/types/index.d.ts +3 -0
  18. package/dist/types/rules/compiled/expand-spacing-shorthand/index.d.ts +3 -0
  19. package/dist/types/rules/util/compiled-utils.d.ts +3 -0
  20. package/dist/types/rules/util/context-compat.d.ts +12 -1
  21. package/dist/types-ts4.5/index.d.ts +3 -0
  22. package/dist/types-ts4.5/rules/compiled/expand-spacing-shorthand/index.d.ts +3 -0
  23. package/dist/types-ts4.5/rules/util/compiled-utils.d.ts +3 -0
  24. package/dist/types-ts4.5/rules/util/context-compat.d.ts +12 -1
  25. package/package.json +1 -1
  26. package/src/index.tsx +3 -0
  27. package/src/rules/compiled/expand-background-shorthand/__tests__/rule.test.ts +1 -1
  28. package/src/rules/compiled/expand-background-shorthand/index.tsx +1 -25
  29. package/src/rules/compiled/expand-spacing-shorthand/README.md +38 -0
  30. package/src/rules/compiled/expand-spacing-shorthand/__tests__/rule.test.ts +400 -0
  31. package/src/rules/compiled/expand-spacing-shorthand/index.ts +195 -0
  32. package/src/rules/util/compiled-utils.ts +27 -0
  33. package/src/rules/util/context-compat.ts +1 -1
  34. package/tsconfig.app.json +0 -1
  35. package/tsconfig.dev.json +0 -1
  36. package/tsconfig.json +0 -1
@@ -0,0 +1,400 @@
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
+ ];
83
+ };
84
+
85
+ const invalidTestCases = (property: string) => {
86
+ return [
87
+ // Value of spacing property is plain token() call
88
+ ...included_compiled_libraries.map((imp) => ({
89
+ name: `expand ${property} with value as token: (${imp})`,
90
+ code: outdent`
91
+ import {css} from '${imp}';
92
+ const styles = css({
93
+ ${property}: token('space.200'),
94
+ });
95
+ `,
96
+ output: outdent`
97
+ import {css} from '${imp}';
98
+ const styles = css({
99
+ ${property}Top: token('space.200'),
100
+ ${property}Right: token('space.200'),
101
+ ${property}Bottom: token('space.200'),
102
+ ${property}Left: token('space.200'),
103
+ });
104
+ `,
105
+ errors: [{ messageId: 'expandSpacingShorthand' }],
106
+ })),
107
+ // Value of spacing property is a template string
108
+ ...included_compiled_libraries.map((imp) => ({
109
+ name: `${property}: template string case (one value) (${imp})`,
110
+ code: outdent`
111
+ import {css} from '${imp}';
112
+ const styles = css({
113
+ ${property}: \`\${token('space.200')}\`,
114
+ });
115
+ `,
116
+ output: outdent`
117
+ import {css} from '${imp}';
118
+ const styles = css({
119
+ ${property}Top: token('space.200'),
120
+ ${property}Right: token('space.200'),
121
+ ${property}Bottom: token('space.200'),
122
+ ${property}Left: token('space.200'),
123
+ });
124
+ `,
125
+ errors: [{ messageId: 'expandSpacingShorthand' }],
126
+ })),
127
+ ...included_compiled_libraries.map((imp) => ({
128
+ name: `${property}: template string case (two values) (${imp})`,
129
+ code: outdent`
130
+ import {css} from '${imp}';
131
+ const styles = css({
132
+ ${property}: \`\${token('space.100')} 0\`,
133
+ });
134
+ `,
135
+ output: outdent`
136
+ import {css} from '${imp}';
137
+ const styles = css({
138
+ ${property}Top: token('space.100'),
139
+ ${property}Right: 0,
140
+ ${property}Bottom: token('space.100'),
141
+ ${property}Left: 0,
142
+ });
143
+ `,
144
+ errors: [{ messageId: 'expandSpacingShorthand' }],
145
+ })),
146
+ ...included_compiled_libraries.map((imp) => ({
147
+ name: `${property}: template string case (three values) (${imp})`,
148
+ code: outdent`
149
+ import {css} from '${imp}';
150
+ const styles = css({
151
+ ${property}: \`\${token('space.100')} 0 2px\`,
152
+ });
153
+ `,
154
+ output: outdent`
155
+ import {css} from '${imp}';
156
+ const styles = css({
157
+ ${property}Top: token('space.100'),
158
+ ${property}Right: 0,
159
+ ${property}Bottom: '2px',
160
+ ${property}Left: 0,
161
+ });
162
+ `,
163
+ errors: [{ messageId: 'expandSpacingShorthand' }],
164
+ })),
165
+ ...included_compiled_libraries.map((imp) => ({
166
+ name: `${property}: template string case (four values) (${imp})`,
167
+ code: outdent`
168
+ import {css} from '${imp}';
169
+ const styles = css({
170
+ ${property}: \`\${token('space.100')} 0 0px 12px\`,
171
+ });
172
+ const styles2 = css({
173
+ ${property}: \`\${token('space.100')} \${token('space.200')} \${token('space.300')} \${token('space.400')}\`,
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: '0px',
182
+ ${property}Left: '12px',
183
+ });
184
+ const styles2 = css({
185
+ ${property}Top: token('space.100'),
186
+ ${property}Right: token('space.200'),
187
+ ${property}Bottom: token('space.300'),
188
+ ${property}Left: token('space.400'),
189
+ });
190
+ `,
191
+ errors: Array.from(Array(2), () => ({ messageId: 'expandSpacingShorthand' })),
192
+ })),
193
+ {
194
+ name: `${property}: compiled import (styled.div, @compiled/react)`,
195
+ code: outdent`
196
+ import { styled } from '@compiled/react';
197
+ const styledDiv = styled.div({
198
+ ${property}: \`0 \${token('space.100', '8px')} 0 0\`,
199
+ });
200
+ `,
201
+ output: outdent`
202
+ import { styled } from '@compiled/react';
203
+ const styledDiv = styled.div({
204
+ ${property}Top: 0,
205
+ ${property}Right: token('space.100', '8px'),
206
+ ${property}Bottom: 0,
207
+ ${property}Left: 0,
208
+ });
209
+ `,
210
+ errors: [{ messageId: 'expandSpacingShorthand' }],
211
+ },
212
+ {
213
+ name: `${property}: compiled import (cssMap, @compiled/react)`,
214
+ code: outdent`
215
+ import { cssMap } from '@compiled/react';
216
+ const backgroundMap = cssMap({
217
+ firstDiv: { ${property}: token('space.100') },
218
+ secondDiv: { ${property}: token('space.100') },
219
+ });
220
+ `,
221
+ output: outdent`
222
+ import { cssMap } from '@compiled/react';
223
+ const backgroundMap = cssMap({
224
+ firstDiv: { ${property}Top: token('space.100'),
225
+ ${property}Right: token('space.100'),
226
+ ${property}Bottom: token('space.100'),
227
+ ${property}Left: token('space.100') },
228
+ secondDiv: { ${property}Top: token('space.100'),
229
+ ${property}Right: token('space.100'),
230
+ ${property}Bottom: token('space.100'),
231
+ ${property}Left: token('space.100') },
232
+ });
233
+ `,
234
+ errors: Array.from(Array(2), () => ({ messageId: 'expandSpacingShorthand' })),
235
+ },
236
+ {
237
+ name: `${property}: compiled import with alias`,
238
+ code: outdent`
239
+ import { styled as styled2 } from '@compiled/react';
240
+ const style = styled2.span({
241
+ ${property}: \`0 \${token('space.100', '8px')} 0 0\`,
242
+ });
243
+ `,
244
+ output: outdent`
245
+ import { styled as styled2 } from '@compiled/react';
246
+ const style = styled2.span({
247
+ ${property}Top: 0,
248
+ ${property}Right: token('space.100', '8px'),
249
+ ${property}Bottom: 0,
250
+ ${property}Left: 0,
251
+ });
252
+ `,
253
+ errors: [{ messageId: 'expandSpacingShorthand' }],
254
+ },
255
+ // Template literal containing expressions that is not token should only throw error with no autofix
256
+ {
257
+ name: `${property}: property value template string where it contains an expression that is not a token`,
258
+ code: outdent`
259
+ import {css} from '@compiled/react';
260
+ const styles = css({
261
+ ${property}: \`\${token('space.100', '8px')} \${gridSize * 2}px\`,
262
+ });
263
+ const styles2 = css({
264
+ padding: \`\${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.075','6px')}
265
+ \${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.200', '16px')}\`,
266
+ });
267
+ const styles3 = css({
268
+ ${property}: \`\${token('space.050', '4px')} \${token('space.150', '12px')} \${token('space.150', '12px')}
269
+ \${({ isSummaryView }: EditFormContentWrapperProps) =>
270
+ isSummaryView ? token('space.0', '0') : token('space.150', '12px')}\`,
271
+ });
272
+ `,
273
+ errors: Array.from(Array(3), () => ({ messageId: 'expandSpacingShorthand' })),
274
+ },
275
+ // Miscellaneous
276
+ {
277
+ name: `${property}: new property should not be created if existing property already exists`,
278
+ code: outdent`
279
+ import {css} from '@compiled/react';
280
+ const styles = css({
281
+ ${property}: token('space.100'),
282
+ ${property}Top: token('space.200'),
283
+ });
284
+ `,
285
+ output: outdent`
286
+ import {css} from '@compiled/react';
287
+ const styles = css({
288
+ ${property}Top: token('space.200'),
289
+ ${property}Right: token('space.100'),
290
+ ${property}Bottom: token('space.100'),
291
+ ${property}Left: token('space.100'),
292
+ });
293
+ `,
294
+ errors: [{ messageId: 'expandSpacingShorthand' }],
295
+ },
296
+ {
297
+ name: `${property}: property with nested selectors`,
298
+ code: outdent`
299
+ import {css} from '@compiled/react';
300
+ const styles = css({
301
+ ${property}: token('space.100'),
302
+ '.some-selector': {
303
+ ${property}Top: token('space.200'),
304
+ }
305
+ });
306
+ const styles2 = css({
307
+ ${property}Top: token('space.100'),
308
+ '.some-selector': {
309
+ ${property}: token('space.200'),
310
+ }
311
+ });
312
+ const styles3 = css({
313
+ '.some-selector': {
314
+ ${property}: token('space.200'),
315
+ ${property}Top: token('space.100'),
316
+ }
317
+ });
318
+ `,
319
+ output: outdent`
320
+ import {css} from '@compiled/react';
321
+ const styles = css({
322
+ ${property}Top: token('space.100'),
323
+ ${property}Right: token('space.100'),
324
+ ${property}Bottom: token('space.100'),
325
+ ${property}Left: token('space.100'),
326
+ '.some-selector': {
327
+ ${property}Top: token('space.200'),
328
+ }
329
+ });
330
+ const styles2 = css({
331
+ ${property}Top: token('space.100'),
332
+ '.some-selector': {
333
+ ${property}Top: token('space.200'),
334
+ ${property}Right: token('space.200'),
335
+ ${property}Bottom: token('space.200'),
336
+ ${property}Left: token('space.200'),
337
+ }
338
+ });
339
+ const styles3 = css({
340
+ '.some-selector': {
341
+ ${property}Top: token('space.100'),
342
+ ${property}Right: token('space.200'),
343
+ ${property}Bottom: token('space.200'),
344
+ ${property}Left: token('space.200'),
345
+ }
346
+ });
347
+ `,
348
+ errors: Array.from(Array(3), () => ({ messageId: 'expandSpacingShorthand' })),
349
+ },
350
+ {
351
+ name: `${property}: property value includes newline and tab`,
352
+ code: outdent`
353
+ import {css} from '@compiled/react';
354
+ const styles = css({
355
+ ${property}: \`\${token('space.100')} \${token('space.200')}
356
+ \${token('space.300')} \${token('space.400')}\`,
357
+ });
358
+ `,
359
+ output: outdent`
360
+ import {css} from '@compiled/react';
361
+ const styles = css({
362
+ ${property}Top: token('space.100'),
363
+ ${property}Right: token('space.200'),
364
+ ${property}Bottom: token('space.300'),
365
+ ${property}Left: token('space.400'),
366
+ });
367
+ `,
368
+ errors: [{ messageId: 'expandSpacingShorthand' }],
369
+ },
370
+ // TODO (AFB-1022): Resolve this failing test
371
+ // {
372
+ // name: `${property}: styled components with prop input`,
373
+ // code: outdent`
374
+ // import { styled } from '@compiled/react';
375
+ // const MenuOptionWrapper = styled.div<{ isDisabled: boolean }>({
376
+ // '& button': ({ isDisabled }) => ({
377
+ // ${property}: \`\${token('space.075', '6px')} \${token('space.200', '16px')}\`,
378
+ // }),
379
+ // });
380
+ // `,
381
+ // output: outdent`
382
+ // import { styled } from '@compiled/react';
383
+ // const MenuOptionWrapper = styled.div<{ isDisabled: boolean }>({
384
+ // '& button': ({ isDisabled }) => ({
385
+ // ${property}Top: token('space.075', '6px'),
386
+ // ${property}Right: token('space.200', '16px'),
387
+ // ${property}Bottom: token('space.075', '6px'),
388
+ // ${property}Left: token('space.200', '16px'),
389
+ // }),
390
+ // });
391
+ // `,
392
+ // errors: [{ messageId: 'expandSpacingShorthand' }],
393
+ // },
394
+ ];
395
+ };
396
+
397
+ tester.run('expand-spacing-shorthand', expandSpacingShorthand, {
398
+ valid: [...validTestCases('padding'), ...validTestCases('margin')],
399
+ invalid: [...invalidTestCases('padding'), ...invalidTestCases('margin')],
400
+ });
@@ -0,0 +1,195 @@
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 splitQuasi = cookedQuasi.split(' ').filter((str) => str.trim().length > 0);
36
+ splitQuasi.forEach((str) => {
37
+ propertyValues.push(isNaN(Number(str)) ? `'${str}'` : str);
38
+ });
39
+ }
40
+ }
41
+ if (i < expressions.length) {
42
+ const expr = getSourceCode(context).getText(expressions[i]);
43
+ propertyValues.push(expr);
44
+ }
45
+ }
46
+ return propertyValues;
47
+ };
48
+
49
+ const checkValidPropertyValues = (propertyValues: string[]) => {
50
+ if (!propertyValues.some((str) => str.includes('token('))) {
51
+ return false;
52
+ }
53
+ if (propertyValues.length < 1 || propertyValues.length > 4) {
54
+ return false;
55
+ }
56
+ if (propertyValues.some((str) => str.includes('calc('))) {
57
+ return false;
58
+ }
59
+ return true;
60
+ };
61
+
62
+ // Check that all expressions in TemplateLiteral are token expressions
63
+ // If true: create an autofix
64
+ // If false: report violation without autofix
65
+ const hasOnlyTokens = (templateLiteral: TemplateLiteral) => {
66
+ const expressions = templateLiteral.expressions;
67
+ return expressions.every((expr) => expr.type === 'CallExpression' && isTokenCallExpression(expr));
68
+ };
69
+
70
+ // To fix spacing shorthands, given a list of spacing property values, expands the spacing property and adds autofix fixes
71
+ const expandSpacingProperties = ({
72
+ context,
73
+ node,
74
+ propertyValues,
75
+ fixer,
76
+ propertyShorthand,
77
+ }: ExpandSpacingPropertiesType) => {
78
+ const [top, right = top, bottom = top, left = right] = propertyValues;
79
+ const spacing: string[] = [top, right, bottom, left];
80
+
81
+ const fixes: Rule.Fix[] = [];
82
+
83
+ const parentNode = node.parent;
84
+ if (parentNode && parentNode.type === 'ObjectExpression') {
85
+ for (var prop of parentNode.properties) {
86
+ if (prop.type !== 'Property') {
87
+ continue;
88
+ }
89
+ if (
90
+ prop.key.type === 'Identifier' &&
91
+ prop.range &&
92
+ prop.key.name !== `${propertyShorthand}`
93
+ ) {
94
+ for (let i = 0; i < spacing.length; i++) {
95
+ if (prop.key.name === `${propertyShorthand}${spacingPos[i]}`) {
96
+ let [start, end] = prop.range;
97
+ // Remove the entire line for the duplicate property
98
+ while (getSourceCode(context).text[end] !== '\n') {
99
+ end += 1;
100
+ }
101
+ while (getSourceCode(context).text[start] !== '\n') {
102
+ start -= 1;
103
+ }
104
+ spacing[i] = getSourceCode(context).getText(prop.value);
105
+ fixes.push(fixer.removeRange([start, end]));
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ fixes.push(fixer.insertTextAfter(node, `${propertyShorthand}Top: ${spacing[0]},\n`));
114
+ fixes.push(fixer.insertTextAfter(node, `\t${propertyShorthand}Right: ${spacing[1]},\n`));
115
+ fixes.push(fixer.insertTextAfter(node, `\t${propertyShorthand}Bottom: ${spacing[2]},\n`));
116
+ fixes.push(fixer.insertTextAfter(node, `\t${propertyShorthand}Left: ${spacing[3]}`));
117
+ fixes.push(fixer.remove(node));
118
+ return fixes;
119
+ };
120
+
121
+ const executeExpandSpacingRule = (
122
+ context: Rule.RuleContext,
123
+ node: Property,
124
+ propertyShorthand: string,
125
+ ) => {
126
+ if (!isCompiledAPI(context, node)) {
127
+ return;
128
+ }
129
+ if (node.value.type === 'TemplateLiteral') {
130
+ // Value of spacing property is a TemplateLiteral type that contains a token, e.g. padding: `0 token('a')`
131
+ if (!hasOnlyTokens(node.value)) {
132
+ context.report({
133
+ node,
134
+ messageId: 'expandSpacingShorthand',
135
+ data: {
136
+ property: propertyShorthand,
137
+ },
138
+ });
139
+ return;
140
+ }
141
+ const propertyValues = parseTemplateLiteral(node.value, context);
142
+ if (!checkValidPropertyValues(propertyValues)) {
143
+ return;
144
+ }
145
+ context.report({
146
+ node,
147
+ messageId: 'expandSpacingShorthand',
148
+ data: {
149
+ property: propertyShorthand,
150
+ },
151
+ fix(fixer) {
152
+ return expandSpacingProperties({ context, node, propertyValues, fixer, propertyShorthand });
153
+ },
154
+ });
155
+ } else if (node.value.type === 'CallExpression' && isTokenCallExpression(node.value)) {
156
+ // Value of spacing property is a token CallExpression type, e.g. margin: token('space.100', '8px')
157
+ const propertyValues = [getSourceCode(context).getText(node.value)];
158
+ context.report({
159
+ node,
160
+ messageId: 'expandSpacingShorthand',
161
+ data: {
162
+ property: propertyShorthand,
163
+ },
164
+ fix(fixer) {
165
+ return expandSpacingProperties({ context, node, propertyValues, fixer, propertyShorthand });
166
+ },
167
+ });
168
+ }
169
+ };
170
+
171
+ export const expandSpacingShorthand: Rule.RuleModule = {
172
+ meta: {
173
+ docs: {
174
+ url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-spacing-shorthand/',
175
+ },
176
+ messages: {
177
+ expandSpacingShorthand:
178
+ 'Use {{ property }}Top, {{ property }}Right, {{ property }}Bottom and {{ property }}Left instead of {{ property }} shorthand',
179
+ },
180
+ type: 'problem',
181
+ fixable: 'code',
182
+ },
183
+ create(context) {
184
+ return {
185
+ 'Property[key.name="padding"]': function (node: Property) {
186
+ executeExpandSpacingRule(context, node, 'padding');
187
+ },
188
+ 'Property[key.name="margin"]': function (node: Property) {
189
+ executeExpandSpacingRule(context, node, 'margin');
190
+ },
191
+ };
192
+ },
193
+ };
194
+
195
+ export default expandSpacingShorthand;
@@ -0,0 +1,27 @@
1
+ import type { Node } from 'estree';
2
+ import { getAncestors, getScope } from './context-compat';
3
+ import type { Rule } from 'eslint';
4
+ import {
5
+ getImportSources,
6
+ isCompiled,
7
+ isAtlasKitCSS,
8
+ } from '@atlaskit/eslint-utils/is-supported-import';
9
+
10
+ // Checks if the function that holds the property is using a Compiled import package that this rule is targeting
11
+ export const isCompiledAPI = (context: Rule.RuleContext, node: Node): boolean => {
12
+ const importSources = getImportSources(context);
13
+ const { references } = getScope(context, node);
14
+ const ancestors = getAncestors(context, node);
15
+ if (
16
+ ancestors.some(
17
+ (ancestor) =>
18
+ ancestor.type === 'CallExpression' &&
19
+ ancestor.callee &&
20
+ (isCompiled(ancestor.callee, references, importSources) ||
21
+ isAtlasKitCSS(ancestor.callee, references, importSources)),
22
+ )
23
+ ) {
24
+ return true;
25
+ }
26
+ return false;
27
+ };
@@ -12,7 +12,7 @@ import type { Node } from 'estree';
12
12
  * `context.getSourceCode()` is deprecated in v8 and removed in v9.
13
13
  * @param context - The ESLint rule context
14
14
  */
15
- const getSourceCode = (context: Rule.RuleContext): SourceCode => {
15
+ export const getSourceCode = (context: Rule.RuleContext): SourceCode => {
16
16
  return context.sourceCode ?? context.getSourceCode();
17
17
  };
18
18
 
package/tsconfig.app.json CHANGED
@@ -27,7 +27,6 @@
27
27
  "**/codemods/**/*.tsx"
28
28
  ],
29
29
  "compilerOptions": {
30
- "baseUrl": "./",
31
30
  "lib": ["ES2021.String"],
32
31
  "composite": true,
33
32
  "outDir": "../../../tsDist/@atlaskit__eslint-plugin-platform/app"
package/tsconfig.dev.json CHANGED
@@ -27,7 +27,6 @@
27
27
  ],
28
28
  "exclude": ["./dist/**/*", "./build/**/*", "./node_modules/**/*"],
29
29
  "compilerOptions": {
30
- "baseUrl": "./",
31
30
  "lib": ["ES2021.String"],
32
31
  "composite": true,
33
32
  "outDir": "../../../tsDist/@atlaskit__eslint-plugin-platform/dev"
package/tsconfig.json CHANGED
@@ -12,7 +12,6 @@
12
12
  "scripts"
13
13
  ],
14
14
  "compilerOptions": {
15
- "baseUrl": "./",
16
15
  "lib": ["ES2021.String"]
17
16
  },
18
17
  "ts-node": {