@atlaskit/eslint-plugin-platform 2.7.0 → 2.7.2
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 +14 -0
- package/dist/cjs/index.js +4 -9
- package/dist/cjs/rules/constants.js +1 -1
- package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +7 -7
- package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +3 -0
- package/dist/cjs/rules/ensure-no-private-dependencies/index.js +48 -66
- package/dist/cjs/rules/feature-gating/inline-usage/index.js +14 -3
- package/dist/cjs/rules/feature-gating/no-alias/index.js +2 -2
- package/dist/cjs/rules/feature-gating/no-module-level-eval/index.js +1 -1
- package/dist/cjs/rules/feature-gating/no-module-level-eval-nav4/index.js +1 -1
- package/dist/cjs/rules/feature-gating/no-preconditioning/index.js +4 -1
- package/dist/cjs/rules/feature-gating/prefer-fg/index.js +1 -1
- package/dist/cjs/rules/feature-gating/static-feature-flags/index.js +2 -2
- package/dist/cjs/rules/feature-gating/use-recommended-utils/index.js +1 -1
- package/dist/cjs/rules/no-invalid-storybook-decorator-usage/index.js +1 -1
- package/dist/cjs/rules/no-sparse-checkout/index.js +1 -1
- package/dist/cjs/rules/prefer-crypto-random-uuid/index.js +87 -0
- package/dist/cjs/rules/use-entrypoints-in-examples/index.js +1 -1
- package/dist/cjs/rules/util/context-compat.js +4 -2
- package/dist/es2019/index.js +4 -9
- package/dist/es2019/rules/constants.js +1 -1
- package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +7 -7
- package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +3 -0
- package/dist/es2019/rules/ensure-no-private-dependencies/index.js +10 -9
- package/dist/es2019/rules/feature-gating/inline-usage/index.js +14 -3
- package/dist/es2019/rules/feature-gating/no-alias/index.js +2 -2
- package/dist/es2019/rules/feature-gating/no-module-level-eval/index.js +1 -1
- package/dist/es2019/rules/feature-gating/no-module-level-eval-nav4/index.js +1 -1
- package/dist/es2019/rules/feature-gating/no-preconditioning/index.js +4 -1
- package/dist/es2019/rules/feature-gating/prefer-fg/index.js +1 -1
- package/dist/es2019/rules/feature-gating/static-feature-flags/index.js +2 -2
- package/dist/es2019/rules/feature-gating/use-recommended-utils/index.js +1 -1
- package/dist/es2019/rules/no-invalid-storybook-decorator-usage/index.js +1 -1
- package/dist/es2019/rules/no-sparse-checkout/index.js +1 -1
- package/dist/es2019/rules/prefer-crypto-random-uuid/index.js +81 -0
- package/dist/es2019/rules/use-entrypoints-in-examples/index.js +1 -1
- package/dist/es2019/rules/util/context-compat.js +4 -2
- package/dist/esm/index.js +4 -9
- package/dist/esm/rules/constants.js +1 -1
- package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +7 -7
- package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +3 -0
- package/dist/esm/rules/ensure-no-private-dependencies/index.js +48 -65
- package/dist/esm/rules/feature-gating/inline-usage/index.js +14 -3
- package/dist/esm/rules/feature-gating/no-alias/index.js +2 -2
- package/dist/esm/rules/feature-gating/no-module-level-eval/index.js +1 -1
- package/dist/esm/rules/feature-gating/no-module-level-eval-nav4/index.js +1 -1
- package/dist/esm/rules/feature-gating/no-preconditioning/index.js +4 -1
- package/dist/esm/rules/feature-gating/prefer-fg/index.js +1 -1
- package/dist/esm/rules/feature-gating/static-feature-flags/index.js +2 -2
- package/dist/esm/rules/feature-gating/use-recommended-utils/index.js +1 -1
- package/dist/esm/rules/no-invalid-storybook-decorator-usage/index.js +1 -1
- package/dist/esm/rules/no-sparse-checkout/index.js +1 -1
- package/dist/esm/rules/prefer-crypto-random-uuid/index.js +81 -0
- package/dist/esm/rules/use-entrypoints-in-examples/index.js +1 -1
- package/dist/esm/rules/util/context-compat.js +4 -2
- package/dist/types/index.d.ts +6 -20
- package/dist/types/rules/util/handle-ast-object.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +6 -32
- package/dist/types-ts4.5/rules/util/handle-ast-object.d.ts +1 -1
- package/package.json +2 -5
- package/afm-cc/tsconfig.json +0 -24
- package/afm-jira/tsconfig.json +0 -24
- package/build/tsconfig.json +0 -17
- package/dist/cjs/rules/ensure-feature-flag-prefix/index.js +0 -75
- package/dist/cjs/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -79
- package/dist/es2019/rules/ensure-feature-flag-prefix/index.js +0 -65
- package/dist/es2019/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -62
- package/dist/esm/rules/ensure-feature-flag-prefix/index.js +0 -69
- package/dist/esm/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -75
- package/dist/types/rules/ensure-feature-flag-prefix/index.d.ts +0 -3
- package/dist/types/rules/ensure-valid-platform-yarn-protocol-usage/index.d.ts +0 -3
- package/src/__tests__/utils/_tester.tsx +0 -26
- package/src/index.tsx +0 -254
- package/src/rules/compiled/README.md +0 -3
- package/src/rules/compiled/expand-background-shorthand/README.md +0 -23
- package/src/rules/compiled/expand-background-shorthand/__tests__/rule.test.ts +0 -160
- package/src/rules/compiled/expand-background-shorthand/index.tsx +0 -43
- package/src/rules/compiled/expand-border-shorthand/README.md +0 -51
- package/src/rules/compiled/expand-border-shorthand/__tests__/rule.test.ts +0 -211
- package/src/rules/compiled/expand-border-shorthand/index.ts +0 -103
- package/src/rules/compiled/expand-spacing-shorthand/README.md +0 -38
- package/src/rules/compiled/expand-spacing-shorthand/__tests__/rule.test.ts +0 -448
- package/src/rules/compiled/expand-spacing-shorthand/index.ts +0 -240
- package/src/rules/constants.tsx +0 -20
- package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +0 -24
- package/src/rules/ensure-atlassian-team/index.ts +0 -51
- package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +0 -200
- package/src/rules/ensure-critical-dependency-resolutions/index.tsx +0 -172
- package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +0 -65
- package/src/rules/ensure-feature-flag-prefix/index.tsx +0 -81
- package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +0 -115
- package/src/rules/ensure-feature-flag-registration/index.tsx +0 -106
- package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +0 -199
- package/src/rules/ensure-native-and-af-exports-synced/index.tsx +0 -188
- package/src/rules/ensure-no-private-dependencies/__tests__/unit/rule.test.ts +0 -212
- package/src/rules/ensure-no-private-dependencies/index.ts +0 -64
- package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +0 -39
- package/src/rules/ensure-publish-valid/index.ts +0 -81
- package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +0 -298
- package/src/rules/ensure-test-runner-arguments/index.tsx +0 -121
- package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +0 -308
- package/src/rules/ensure-test-runner-nested-count/index.tsx +0 -82
- package/src/rules/ensure-valid-bin-values/__tests__/unit/rule.test.ts +0 -159
- package/src/rules/ensure-valid-bin-values/index.ts +0 -70
- package/src/rules/ensure-valid-platform-yarn-protocol-usage/__tests__/unit/rule.test.ts +0 -147
- package/src/rules/ensure-valid-platform-yarn-protocol-usage/index.ts +0 -67
- package/src/rules/feature-gating/README.md +0 -8
- package/src/rules/feature-gating/inline-usage/README.md +0 -53
- package/src/rules/feature-gating/inline-usage/__tests__/rule.test.tsx +0 -106
- package/src/rules/feature-gating/inline-usage/index.tsx +0 -135
- package/src/rules/feature-gating/no-alias/README.md +0 -29
- package/src/rules/feature-gating/no-alias/__tests__/rule.test.tsx +0 -76
- package/src/rules/feature-gating/no-alias/index.tsx +0 -80
- package/src/rules/feature-gating/no-module-level-eval/README.md +0 -53
- package/src/rules/feature-gating/no-module-level-eval/__tests__/test.tsx +0 -133
- package/src/rules/feature-gating/no-module-level-eval/index.tsx +0 -54
- package/src/rules/feature-gating/no-module-level-eval-nav4/README.md +0 -8
- package/src/rules/feature-gating/no-module-level-eval-nav4/__tests__/test.tsx +0 -130
- package/src/rules/feature-gating/no-module-level-eval-nav4/index.tsx +0 -73
- package/src/rules/feature-gating/no-preconditioning/README.md +0 -69
- package/src/rules/feature-gating/no-preconditioning/__tests__/rule.test.tsx +0 -164
- package/src/rules/feature-gating/no-preconditioning/index.tsx +0 -138
- package/src/rules/feature-gating/prefer-fg/README.md +0 -3
- package/src/rules/feature-gating/prefer-fg/__tests__/rule.test.tsx +0 -83
- package/src/rules/feature-gating/prefer-fg/index.tsx +0 -110
- package/src/rules/feature-gating/static-feature-flags/README.md +0 -3
- package/src/rules/feature-gating/static-feature-flags/__tests__/test.tsx +0 -135
- package/src/rules/feature-gating/static-feature-flags/index.tsx +0 -103
- package/src/rules/feature-gating/use-recommended-utils/README.md +0 -67
- package/src/rules/feature-gating/use-recommended-utils/__tests__/rule.test.tsx +0 -78
- package/src/rules/feature-gating/use-recommended-utils/index.tsx +0 -57
- package/src/rules/feature-gating/utils.tsx +0 -48
- package/src/rules/no-direct-document-usage/index.tsx +0 -111
- package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +0 -116
- package/src/rules/no-duplicate-dependencies/index.ts +0 -79
- package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +0 -69
- package/src/rules/no-invalid-feature-flag-usage/index.tsx +0 -128
- package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +0 -18
- package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +0 -39
- package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +0 -41
- package/src/rules/no-pre-post-installs/index.ts +0 -35
- package/src/rules/no-set-immediate/index.tsx +0 -43
- package/src/rules/no-sparse-checkout/__tests__/unit/rule.test.tsx +0 -48
- package/src/rules/no-sparse-checkout/index.tsx +0 -54
- package/src/rules/use-entrypoints-in-examples/README.md +0 -27
- package/src/rules/use-entrypoints-in-examples/__tests__/rule.test.tsx +0 -34
- package/src/rules/use-entrypoints-in-examples/index.tsx +0 -43
- package/src/rules/util/__tests__/context-compat.test.ts +0 -122
- package/src/rules/util/compiled-utils.ts +0 -27
- package/src/rules/util/context-compat.ts +0 -41
- package/src/rules/util/file-exclusions.ts +0 -39
- package/src/rules/util/handle-ast-object.ts +0 -33
- package/src/rules/util/registration-utils.ts +0 -59
- package/tsconfig.app.json +0 -43
- package/tsconfig.dev.json +0 -40
- package/tsconfig.json +0 -23
- /package/dist/{types-ts4.5/rules/ensure-valid-platform-yarn-protocol-usage → types/rules/prefer-crypto-random-uuid}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{ensure-feature-flag-prefix → prefer-crypto-random-uuid}/index.d.ts +0 -0
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { outdent } from 'outdent';
|
|
2
|
-
|
|
3
|
-
import { tester } from '../../../../__tests__/utils/_tester';
|
|
4
|
-
import { expandBorderShorthand } from '../index';
|
|
5
|
-
|
|
6
|
-
const included_packages_calls_and_imports = [
|
|
7
|
-
['css', 'css', '@atlaskit/css'],
|
|
8
|
-
['css', 'css', '@compiled/react'],
|
|
9
|
-
['styled', 'styled.div', '@compiled/react'],
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
const exempt_packages_calls_and_imports = [
|
|
13
|
-
['css', '@atlaskit/primitives'],
|
|
14
|
-
['css', '@emotion'],
|
|
15
|
-
['css', 'styled-components'],
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
19
|
-
valid: [
|
|
20
|
-
...exempt_packages_calls_and_imports.map(([pkg, imp]) => ({
|
|
21
|
-
name: `handle only Compiled APIs (${pkg}, ${imp})`,
|
|
22
|
-
code: outdent`
|
|
23
|
-
import {${pkg}} from '${imp}';
|
|
24
|
-
|
|
25
|
-
const styles = ${pkg}({
|
|
26
|
-
border: '1px solid red',
|
|
27
|
-
});
|
|
28
|
-
`,
|
|
29
|
-
})),
|
|
30
|
-
{
|
|
31
|
-
name: 'CallExpression matches with imported API',
|
|
32
|
-
code: outdent`
|
|
33
|
-
import { styled } from 'styled-components';
|
|
34
|
-
import { styled as styled2, css as compiledCSS, jsx } from '@compiled/react';
|
|
35
|
-
|
|
36
|
-
const styles = xcss({
|
|
37
|
-
border: '1px solid red',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const styles2 = styled.div({
|
|
41
|
-
border: '1px solid red',
|
|
42
|
-
});
|
|
43
|
-
`,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'excluded values',
|
|
47
|
-
code: outdent`
|
|
48
|
-
import {css} from '@compiled/react';
|
|
49
|
-
|
|
50
|
-
const styles = css({
|
|
51
|
-
border: 'none',
|
|
52
|
-
});
|
|
53
|
-
const styles2 = css({
|
|
54
|
-
border: '0',
|
|
55
|
-
});
|
|
56
|
-
const styles3 = css({
|
|
57
|
-
border: 'unset',
|
|
58
|
-
});
|
|
59
|
-
const styles4 = css({
|
|
60
|
-
border: 'none !important',
|
|
61
|
-
});
|
|
62
|
-
const styles5 = css({
|
|
63
|
-
border: \`none\`,
|
|
64
|
-
});
|
|
65
|
-
const styles6 = css({
|
|
66
|
-
border: \`0\`,
|
|
67
|
-
});
|
|
68
|
-
const styles7 = css({
|
|
69
|
-
border: \`unset\`,
|
|
70
|
-
});
|
|
71
|
-
const styles8 = css({
|
|
72
|
-
border: \`none !important\`,
|
|
73
|
-
});
|
|
74
|
-
const styles9 = css({
|
|
75
|
-
border: 0,
|
|
76
|
-
});
|
|
77
|
-
const styles10 = css({
|
|
78
|
-
border: 'var(--icon-border)',
|
|
79
|
-
});
|
|
80
|
-
const styles11 = css({
|
|
81
|
-
border: \`\${(props: { border?: boolean }) =>
|
|
82
|
-
props.border ? \`1px solid \${token('color.border.disabled', colors.N30)}\` : 'none'}\`,
|
|
83
|
-
});
|
|
84
|
-
const styles12 = css({
|
|
85
|
-
border: (props: { border?: boolean }) =>
|
|
86
|
-
props.border ? token('color.border.disabled', colors.N30) : 'none',
|
|
87
|
-
});
|
|
88
|
-
`,
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: 'not using border shorthand',
|
|
92
|
-
code: outdent`
|
|
93
|
-
import {css} from '@compiled/react';
|
|
94
|
-
|
|
95
|
-
const styles = css({
|
|
96
|
-
borderTop: '2px solid green',
|
|
97
|
-
borderRight: '3px dashed orange',
|
|
98
|
-
borderBottom: '4px double purple',
|
|
99
|
-
borderLeft: '5px groove teal',
|
|
100
|
-
});
|
|
101
|
-
const styles2 = css({
|
|
102
|
-
borderWidth: '1px',
|
|
103
|
-
borderStyle: 'solid',
|
|
104
|
-
borderColor: 'black',
|
|
105
|
-
});
|
|
106
|
-
`,
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
name: 'cssMap case where border is assigned an ObjectExpression',
|
|
110
|
-
code: outdent`
|
|
111
|
-
import { cssMap } from '@compiled/react';
|
|
112
|
-
|
|
113
|
-
const borderStyleMap = cssMap({
|
|
114
|
-
none: { borderStyle: 'none' },
|
|
115
|
-
border: { borderStyle: 'solid' },
|
|
116
|
-
});
|
|
117
|
-
`,
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
invalid: [
|
|
121
|
-
...included_packages_calls_and_imports.map(([pkg, call, imp]) => ({
|
|
122
|
-
name: `simple case (${call}, ${imp})`,
|
|
123
|
-
code: outdent`
|
|
124
|
-
import {${pkg}} from '${imp}';
|
|
125
|
-
|
|
126
|
-
const styles = ${call}({
|
|
127
|
-
border: '1px solid red',
|
|
128
|
-
});
|
|
129
|
-
const styles2 = ${call}({
|
|
130
|
-
border: '1px solid',
|
|
131
|
-
});
|
|
132
|
-
const styles3 = ${call}({
|
|
133
|
-
border: '1px',
|
|
134
|
-
});
|
|
135
|
-
`,
|
|
136
|
-
errors: Array.from(Array(3), () => ({ messageId: 'expandBorderShorthand' })),
|
|
137
|
-
})),
|
|
138
|
-
{
|
|
139
|
-
name: 'nested ObjectExpression',
|
|
140
|
-
code: outdent`
|
|
141
|
-
import {css} from '@compiled/react';
|
|
142
|
-
const styles = {
|
|
143
|
-
inverse: css({
|
|
144
|
-
border: '1px solid red',
|
|
145
|
-
}),
|
|
146
|
-
};
|
|
147
|
-
`,
|
|
148
|
-
errors: [{ messageId: 'expandBorderShorthand' }],
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'pseudo selector',
|
|
152
|
-
code: outdent`
|
|
153
|
-
import {css} from '@compiled/react';
|
|
154
|
-
const styles = css({
|
|
155
|
-
'&:hover': {
|
|
156
|
-
border: '1px solid red',
|
|
157
|
-
'&:hover': {
|
|
158
|
-
border: '1px solid red',
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
border: '1px solid red',
|
|
162
|
-
})
|
|
163
|
-
`,
|
|
164
|
-
errors: Array.from(Array(3), () => ({ messageId: 'expandBorderShorthand' })),
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
name: 'template string',
|
|
168
|
-
code: outdent`
|
|
169
|
-
import {css} from '@compiled/react';
|
|
170
|
-
|
|
171
|
-
const styles = css({
|
|
172
|
-
border: \`1px solid red\`,
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
const styles4 = css({
|
|
176
|
-
border: \`1px red\`,
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
const styles5 = css({
|
|
180
|
-
border: \`1px\`,
|
|
181
|
-
})
|
|
182
|
-
`,
|
|
183
|
-
errors: Array.from(Array(3), () => ({ messageId: 'expandBorderShorthand' })),
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
name: 'tokens',
|
|
187
|
-
code: outdent`
|
|
188
|
-
import {css} from '@compiled/react';
|
|
189
|
-
const styles = css({
|
|
190
|
-
border: token('color.border'),
|
|
191
|
-
})
|
|
192
|
-
const styles2 = css({
|
|
193
|
-
border: token('space.025', '2px'),
|
|
194
|
-
})
|
|
195
|
-
`,
|
|
196
|
-
errors: Array.from(Array(2), () => ({ messageId: 'expandBorderShorthand' })),
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: 'cssMap case where border is assigned an a Literal',
|
|
200
|
-
code: outdent`
|
|
201
|
-
import { cssMap } from '@compiled/react';
|
|
202
|
-
|
|
203
|
-
const borderStyleMap = cssMap({
|
|
204
|
-
none: { border: 'none' },
|
|
205
|
-
solid: { border: '1px solid blue' },
|
|
206
|
-
});
|
|
207
|
-
`,
|
|
208
|
-
errors: [{ messageId: 'expandBorderShorthand' }],
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
});
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'eslint';
|
|
2
|
-
import type { Property, Node, ImportDeclaration, CallExpression } from 'estree';
|
|
3
|
-
|
|
4
|
-
const EXCLUDED_VALUES = ['0', 'none', 'unset', 'none !important'];
|
|
5
|
-
|
|
6
|
-
const findCallExpression = (node: Node & { parent?: Node }): CallExpression | null => {
|
|
7
|
-
const parent = node.parent;
|
|
8
|
-
if (!parent) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
if (parent.type === 'CallExpression') {
|
|
12
|
-
return parent;
|
|
13
|
-
}
|
|
14
|
-
return findCallExpression(parent);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const separateBorderProperties = (
|
|
18
|
-
borderString: string,
|
|
19
|
-
property: Property,
|
|
20
|
-
context: Rule.RuleContext,
|
|
21
|
-
) => {
|
|
22
|
-
if (EXCLUDED_VALUES.includes(borderString)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (borderString.includes('var(--')) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
context.report({
|
|
30
|
-
node: property,
|
|
31
|
-
messageId: 'expandBorderShorthand',
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// checks if the function that holds the border property is using an import package that this rule is targeting
|
|
36
|
-
const isCompiledAPI = (importDeclaration: ImportDeclaration, callExpression: CallExpression) => {
|
|
37
|
-
let functionName;
|
|
38
|
-
if (callExpression.callee.type === 'Identifier') {
|
|
39
|
-
functionName = callExpression.callee.name;
|
|
40
|
-
} else if (callExpression.callee.type === 'MemberExpression') {
|
|
41
|
-
if (callExpression.callee.object.type === 'Identifier') {
|
|
42
|
-
functionName = callExpression.callee.object.name;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!functionName) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return importDeclaration.specifiers.some(
|
|
50
|
-
(specifier) => specifier.type === 'ImportSpecifier' && specifier.local.name === functionName,
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const expandBorderShorthand: Rule.RuleModule = {
|
|
55
|
-
meta: {
|
|
56
|
-
docs: {
|
|
57
|
-
url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-border-shorthand',
|
|
58
|
-
},
|
|
59
|
-
messages: {
|
|
60
|
-
expandBorderShorthand:
|
|
61
|
-
'Use borderColor, borderStyle, and borderWidth instead of border shorthand',
|
|
62
|
-
},
|
|
63
|
-
type: 'problem',
|
|
64
|
-
},
|
|
65
|
-
create(context) {
|
|
66
|
-
let importDeclaration: ImportDeclaration;
|
|
67
|
-
return {
|
|
68
|
-
'ImportDeclaration[source.value="@compiled/react"], ImportDeclaration[source.value="@atlaskit/css"]':
|
|
69
|
-
function (node: ImportDeclaration) {
|
|
70
|
-
importDeclaration = node;
|
|
71
|
-
},
|
|
72
|
-
'Property[key.name="border"]': function (node: Property) {
|
|
73
|
-
const callExpression = findCallExpression(node);
|
|
74
|
-
if (!callExpression) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (importDeclaration) {
|
|
78
|
-
if (isCompiledAPI(importDeclaration, callExpression)) {
|
|
79
|
-
if (node.value.type === 'Literal' && node.value.value !== null) {
|
|
80
|
-
const borderString =
|
|
81
|
-
typeof node.value.value === 'string' ? node.value.value : node.value.raw;
|
|
82
|
-
if (borderString) {
|
|
83
|
-
separateBorderProperties(borderString, node, context);
|
|
84
|
-
}
|
|
85
|
-
} else if (node.value.type === 'TemplateLiteral') {
|
|
86
|
-
if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
|
|
87
|
-
const borderQuasis: string = node.value.quasis[0].value.cooked;
|
|
88
|
-
separateBorderProperties(borderQuasis, node, context);
|
|
89
|
-
}
|
|
90
|
-
} else if (node.value.type === 'CallExpression') {
|
|
91
|
-
context.report({
|
|
92
|
-
node,
|
|
93
|
-
messageId: 'expandBorderShorthand',
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export default expandBorderShorthand;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# `expand-spacing-shorthand`
|
|
2
|
-
|
|
3
|
-
This ESLint rule enforces the expansion of the CSS `padding` and `margin` shorthand properties into
|
|
4
|
-
its longhand equivalent `{spacing}Top`, `{spacing}Right`, `{spacing}Bottom`, `{spacing}Left`, where
|
|
5
|
-
the property's value is either an Atlassian Design System token or a template literal which contains
|
|
6
|
-
a token, and the function call originates from `@compiled/react` or `@atlaskit/css`.
|
|
7
|
-
|
|
8
|
-
## Rule details
|
|
9
|
-
|
|
10
|
-
👎 Examples of **incorrect** code for this rule:
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
const styles = css({
|
|
14
|
-
padding: token('space.200'),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const styles = css({
|
|
18
|
-
margin: `${token('space.100')} 0 2px`,
|
|
19
|
-
});
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
👍 Examples of **correct** code for this rule:
|
|
23
|
-
|
|
24
|
-
```js
|
|
25
|
-
const styles = css({
|
|
26
|
-
paddingTop: token('space.200'),
|
|
27
|
-
paddingRight: token('space.200'),
|
|
28
|
-
paddingBottom: token('space.200'),
|
|
29
|
-
paddingLeft: token('space.200'),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const styles = css({
|
|
33
|
-
marginTop: token('space.100'),
|
|
34
|
-
marginRight: 0,
|
|
35
|
-
marginBottom: '2px',
|
|
36
|
-
marginLeft: 0,
|
|
37
|
-
});
|
|
38
|
-
```
|