@atlaskit/eslint-plugin-platform 2.6.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 (119) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/index.js +4 -3
  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/no-direct-document-usage/index.js +1 -1
  7. package/dist/cjs/rules/no-set-immediate/index.js +39 -0
  8. package/dist/cjs/rules/util/context-compat.js +4 -2
  9. package/dist/es2019/index.js +4 -3
  10. package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +2 -2
  11. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  12. package/dist/es2019/rules/feature-gating/no-alias/index.js +1 -1
  13. package/dist/es2019/rules/no-direct-document-usage/index.js +1 -1
  14. package/dist/es2019/rules/no-set-immediate/index.js +33 -0
  15. package/dist/es2019/rules/util/context-compat.js +4 -2
  16. package/dist/esm/index.js +4 -3
  17. package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +2 -2
  18. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +3 -0
  19. package/dist/esm/rules/feature-gating/no-alias/index.js +1 -1
  20. package/dist/esm/rules/no-direct-document-usage/index.js +1 -1
  21. package/dist/esm/rules/no-set-immediate/index.js +33 -0
  22. package/dist/esm/rules/util/context-compat.js +4 -2
  23. package/dist/types/index.d.ts +14 -6
  24. package/dist/types/rules/util/handle-ast-object.d.ts +1 -1
  25. package/dist/types-ts4.5/index.d.ts +14 -6
  26. package/dist/types-ts4.5/rules/util/handle-ast-object.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/afm-cc/tsconfig.json +0 -24
  29. package/afm-jira/tsconfig.json +0 -24
  30. package/build/tsconfig.json +0 -17
  31. package/dist/cjs/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -79
  32. package/dist/es2019/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -62
  33. package/dist/esm/rules/ensure-valid-platform-yarn-protocol-usage/index.js +0 -75
  34. package/src/__tests__/utils/_tester.tsx +0 -26
  35. package/src/index.tsx +0 -251
  36. package/src/rules/compiled/README.md +0 -3
  37. package/src/rules/compiled/expand-background-shorthand/README.md +0 -23
  38. package/src/rules/compiled/expand-background-shorthand/__tests__/rule.test.ts +0 -160
  39. package/src/rules/compiled/expand-background-shorthand/index.tsx +0 -43
  40. package/src/rules/compiled/expand-border-shorthand/README.md +0 -51
  41. package/src/rules/compiled/expand-border-shorthand/__tests__/rule.test.ts +0 -211
  42. package/src/rules/compiled/expand-border-shorthand/index.ts +0 -103
  43. package/src/rules/compiled/expand-spacing-shorthand/README.md +0 -38
  44. package/src/rules/compiled/expand-spacing-shorthand/__tests__/rule.test.ts +0 -448
  45. package/src/rules/compiled/expand-spacing-shorthand/index.ts +0 -240
  46. package/src/rules/constants.tsx +0 -20
  47. package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +0 -24
  48. package/src/rules/ensure-atlassian-team/index.ts +0 -51
  49. package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +0 -200
  50. package/src/rules/ensure-critical-dependency-resolutions/index.tsx +0 -172
  51. package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +0 -65
  52. package/src/rules/ensure-feature-flag-prefix/index.tsx +0 -81
  53. package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +0 -115
  54. package/src/rules/ensure-feature-flag-registration/index.tsx +0 -106
  55. package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +0 -199
  56. package/src/rules/ensure-native-and-af-exports-synced/index.tsx +0 -188
  57. package/src/rules/ensure-no-private-dependencies/__tests__/unit/rule.test.ts +0 -212
  58. package/src/rules/ensure-no-private-dependencies/index.ts +0 -64
  59. package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +0 -39
  60. package/src/rules/ensure-publish-valid/index.ts +0 -81
  61. package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +0 -298
  62. package/src/rules/ensure-test-runner-arguments/index.tsx +0 -121
  63. package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +0 -308
  64. package/src/rules/ensure-test-runner-nested-count/index.tsx +0 -82
  65. package/src/rules/ensure-valid-bin-values/__tests__/unit/rule.test.ts +0 -159
  66. package/src/rules/ensure-valid-bin-values/index.ts +0 -70
  67. package/src/rules/ensure-valid-platform-yarn-protocol-usage/__tests__/unit/rule.test.ts +0 -147
  68. package/src/rules/ensure-valid-platform-yarn-protocol-usage/index.ts +0 -67
  69. package/src/rules/feature-gating/README.md +0 -8
  70. package/src/rules/feature-gating/inline-usage/README.md +0 -53
  71. package/src/rules/feature-gating/inline-usage/__tests__/rule.test.tsx +0 -106
  72. package/src/rules/feature-gating/inline-usage/index.tsx +0 -135
  73. package/src/rules/feature-gating/no-alias/README.md +0 -29
  74. package/src/rules/feature-gating/no-alias/__tests__/rule.test.tsx +0 -76
  75. package/src/rules/feature-gating/no-alias/index.tsx +0 -80
  76. package/src/rules/feature-gating/no-module-level-eval/README.md +0 -53
  77. package/src/rules/feature-gating/no-module-level-eval/__tests__/test.tsx +0 -133
  78. package/src/rules/feature-gating/no-module-level-eval/index.tsx +0 -54
  79. package/src/rules/feature-gating/no-module-level-eval-nav4/README.md +0 -8
  80. package/src/rules/feature-gating/no-module-level-eval-nav4/__tests__/test.tsx +0 -130
  81. package/src/rules/feature-gating/no-module-level-eval-nav4/index.tsx +0 -73
  82. package/src/rules/feature-gating/no-preconditioning/README.md +0 -69
  83. package/src/rules/feature-gating/no-preconditioning/__tests__/rule.test.tsx +0 -164
  84. package/src/rules/feature-gating/no-preconditioning/index.tsx +0 -138
  85. package/src/rules/feature-gating/prefer-fg/README.md +0 -3
  86. package/src/rules/feature-gating/prefer-fg/__tests__/rule.test.tsx +0 -83
  87. package/src/rules/feature-gating/prefer-fg/index.tsx +0 -110
  88. package/src/rules/feature-gating/static-feature-flags/README.md +0 -3
  89. package/src/rules/feature-gating/static-feature-flags/__tests__/test.tsx +0 -135
  90. package/src/rules/feature-gating/static-feature-flags/index.tsx +0 -103
  91. package/src/rules/feature-gating/use-recommended-utils/README.md +0 -67
  92. package/src/rules/feature-gating/use-recommended-utils/__tests__/rule.test.tsx +0 -78
  93. package/src/rules/feature-gating/use-recommended-utils/index.tsx +0 -57
  94. package/src/rules/feature-gating/utils.tsx +0 -48
  95. package/src/rules/no-direct-document-usage/index.tsx +0 -109
  96. package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +0 -116
  97. package/src/rules/no-duplicate-dependencies/index.ts +0 -79
  98. package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +0 -69
  99. package/src/rules/no-invalid-feature-flag-usage/index.tsx +0 -128
  100. package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +0 -18
  101. package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +0 -39
  102. package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +0 -41
  103. package/src/rules/no-pre-post-installs/index.ts +0 -35
  104. package/src/rules/no-sparse-checkout/__tests__/unit/rule.test.tsx +0 -48
  105. package/src/rules/no-sparse-checkout/index.tsx +0 -54
  106. package/src/rules/use-entrypoints-in-examples/README.md +0 -27
  107. package/src/rules/use-entrypoints-in-examples/__tests__/rule.test.tsx +0 -34
  108. package/src/rules/use-entrypoints-in-examples/index.tsx +0 -43
  109. package/src/rules/util/__tests__/context-compat.test.ts +0 -122
  110. package/src/rules/util/compiled-utils.ts +0 -27
  111. package/src/rules/util/context-compat.ts +0 -41
  112. package/src/rules/util/file-exclusions.ts +0 -39
  113. package/src/rules/util/handle-ast-object.ts +0 -33
  114. package/src/rules/util/registration-utils.ts +0 -59
  115. package/tsconfig.app.json +0 -43
  116. package/tsconfig.dev.json +0 -40
  117. package/tsconfig.json +0 -23
  118. /package/dist/types/rules/{ensure-valid-platform-yarn-protocol-usage → no-set-immediate}/index.d.ts +0 -0
  119. /package/dist/types-ts4.5/rules/{ensure-valid-platform-yarn-protocol-usage → no-set-immediate}/index.d.ts +0 -0
package/src/index.tsx DELETED
@@ -1,251 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import compiledPlugin from '@compiled/eslint-plugin';
3
- import type { ESLint, Linter } from 'eslint';
4
- import ensureFeatureFlagRegistration from './rules/ensure-feature-flag-registration';
5
- import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
6
- import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
7
- import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
8
- import ensureAtlassianTeam from './rules/ensure-atlassian-team';
9
- import noDuplicateDependencies from './rules/no-duplicate-dependencies';
10
- import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
11
- import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
12
- import ensureCriticalDependencyResolutions from './rules/ensure-critical-dependency-resolutions';
13
- import ensureValidPlatformYarnProtocolUsage from './rules/ensure-valid-platform-yarn-protocol-usage';
14
- import ensureValidBinValues from './rules/ensure-valid-bin-values';
15
- import ensureNoPrivateDependencies from './rules/ensure-no-private-dependencies';
16
- import expandBorderShorthand from './rules/compiled/expand-border-shorthand';
17
- import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
18
- import ensurePublishValid from './rules/ensure-publish-valid';
19
- import ensureNativeAndAfExportsSynced from './rules/ensure-native-and-af-exports-synced';
20
- import noModuleLevelEval from './rules/feature-gating/no-module-level-eval';
21
- import noModuleLevelEvalNav4 from './rules/feature-gating/no-module-level-eval-nav4';
22
- import staticFeatureFlags from './rules/feature-gating/static-feature-flags';
23
- import noPreconditioning from './rules/feature-gating/no-preconditioning';
24
- import inlineUsage from './rules/feature-gating/inline-usage';
25
- import preferFG from './rules/feature-gating/prefer-fg';
26
- import noAlias from './rules/feature-gating/no-alias';
27
- import useEntrypointsInExamples from './rules/use-entrypoints-in-examples';
28
- import useRecommendedUtils from './rules/feature-gating/use-recommended-utils';
29
- import expandBackgroundShorthand from './rules/compiled/expand-background-shorthand';
30
- import expandSpacingShorthand from './rules/compiled/expand-spacing-shorthand';
31
- import noSparseCheckout from './rules/no-sparse-checkout';
32
- import noDirectDocumentUsage from './rules/no-direct-document-usage';
33
- import { join, normalize } from 'node:path';
34
- import { readFileSync } from 'node:fs';
35
-
36
- let jiraRoot: string | undefined;
37
-
38
- try {
39
- const findUp = require('find-up') as typeof import('find-up');
40
- findUp.sync((dir) => {
41
- const productsJsonPath = join(dir, 'products.json');
42
- if (findUp.sync.exists(productsJsonPath)) {
43
- const productJson: Record<string, { path: string }> = JSON.parse(
44
- readFileSync(productsJsonPath, 'utf-8'),
45
- );
46
- if (productJson.Jira) {
47
- jiraRoot = normalize(join(dir, productJson.Jira.path));
48
- return findUp.stop;
49
- }
50
- }
51
- });
52
- } catch {
53
- // we aren't running inside of AFM, so we can ignore this.
54
- }
55
-
56
- const packageJson: {
57
- name: string;
58
- version: string;
59
- // eslint-disable-next-line import/no-extraneous-dependencies
60
- } = require('@atlaskit/eslint-plugin-platform/package.json');
61
-
62
- const rules = {
63
- 'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
64
- 'ensure-feature-flag-prefix': ensureFeatureFlagPrefix,
65
- 'ensure-test-runner-arguments': ensureTestRunnerArguments,
66
- 'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
67
- 'ensure-atlassian-team': ensureAtlassianTeam,
68
- 'ensure-critical-dependency-resolutions': ensureCriticalDependencyResolutions,
69
- 'ensure-valid-platform-yarn-protocol-usage': ensureValidPlatformYarnProtocolUsage,
70
- 'ensure-valid-bin-values': ensureValidBinValues,
71
- 'ensure-no-private-dependencies': ensureNoPrivateDependencies,
72
- 'expand-border-shorthand': expandBorderShorthand,
73
- 'expand-background-shorthand': expandBackgroundShorthand,
74
- 'expand-spacing-shorthand': expandSpacingShorthand,
75
- 'no-duplicate-dependencies': noDuplicateDependencies,
76
- 'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
77
- 'no-pre-post-install-scripts': noPreAndPostInstallScripts,
78
- 'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
79
- 'ensure-publish-valid': ensurePublishValid,
80
- 'ensure-native-and-af-exports-synced': ensureNativeAndAfExportsSynced,
81
- 'no-module-level-eval': noModuleLevelEval,
82
- 'no-module-level-eval-nav4': noModuleLevelEvalNav4,
83
- 'static-feature-flags': staticFeatureFlags,
84
- 'no-preconditioning': noPreconditioning,
85
- 'inline-usage': inlineUsage,
86
- 'prefer-fg': preferFG,
87
- 'no-alias': noAlias,
88
- 'use-entrypoints-in-examples': useEntrypointsInExamples,
89
- 'use-recommended-utils': useRecommendedUtils,
90
- 'no-sparse-checkout': noSparseCheckout,
91
- 'no-direct-document-usage': noDirectDocumentUsage,
92
- };
93
-
94
- const commonConfig = {
95
- '@atlaskit/platform/ensure-test-runner-arguments': 'error',
96
- '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
97
- '@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
98
- '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
99
- '@atlaskit/platform/ensure-atlassian-team': 'error',
100
- '@atlaskit/platform/no-module-level-eval-nav4': 'error',
101
- '@atlaskit/platform/no-direct-document-usage': 'warn',
102
- // Compiled: rules that are not included via `@compiled/recommended
103
- '@atlaskit/platform/expand-border-shorthand': 'error',
104
- '@atlaskit/platform/expand-background-shorthand': 'error',
105
- '@atlaskit/platform/expand-spacing-shorthand': 'error',
106
- '@compiled/jsx-pragma': [
107
- 'error',
108
- {
109
- importSources: ['@atlaskit/css'],
110
- onlyRunIfImportingCompiled: true,
111
- runtime: 'classic',
112
- },
113
- ],
114
- } satisfies Linter.RulesRecord;
115
-
116
- const recommendedRules = {
117
- ...commonConfig,
118
- // See platform/packages/platform/eslint-plugin/src/rules/feature-gating/README.md
119
- // These rules are specific to `platform` and seem a WIP; jira and confluence currently have their own rules
120
- '@atlaskit/platform/no-module-level-eval': 'error',
121
- '@atlaskit/platform/static-feature-flags': 'error',
122
- '@atlaskit/platform/no-preconditioning': 'error',
123
- '@atlaskit/platform/inline-usage': 'error',
124
- '@atlaskit/platform/prefer-fg': 'error',
125
- '@atlaskit/platform/no-alias': 'error',
126
- // end: feature-gating rules
127
- '@atlaskit/platform/ensure-feature-flag-registration': 'error',
128
- '@atlaskit/platform/ensure-feature-flag-prefix': [
129
- 'warn',
130
- { allowedPrefixes: ['platform.', 'platform_'] },
131
- ],
132
- } satisfies Linter.RulesRecord;
133
-
134
- const jiraRules = commonConfig;
135
-
136
- const jsonPrefix =
137
- '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ';
138
-
139
- const jsonPrefixForFlatConfig =
140
- '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
141
-
142
- const jsonPrefixForJira = 'module.exports = ';
143
-
144
- const { name, version } = packageJson;
145
- const plugin = {
146
- meta: {
147
- name,
148
- version,
149
- },
150
- rules,
151
- configs: {
152
- recommended: {
153
- plugins: ['@atlaskit/platform', '@compiled'],
154
- rules: recommendedRules,
155
- },
156
- 'recommended/flat': {
157
- plugins: {
158
- get '@atlaskit/platform'(): ESLint.Plugin {
159
- return plugin;
160
- },
161
- // @ts-expect-error there's an issue with the types for @compiled/eslint-plugin ('no-css-prop-without-css-function' specifically)
162
- '@compiled': { meta: compiledPlugin.meta, rules: compiledPlugin.rules } as ESLint.Plugin,
163
- },
164
- rules: recommendedRules,
165
- },
166
- jira: {
167
- plugins: ['@atlaskit/platform', '@compiled'],
168
- rules: jiraRules,
169
- },
170
- 'jira/flat': {
171
- plugins: {
172
- get '@atlaskit/platform'(): ESLint.Plugin {
173
- return plugin;
174
- },
175
- // @ts-expect-error there's an issue with the types for @compiled/eslint-plugin ('no-css-prop-without-css-function' specifically)
176
- '@compiled': { meta: compiledPlugin.meta, rules: compiledPlugin.rules } as ESLint.Plugin,
177
- },
178
- rules: jiraRules,
179
- },
180
- },
181
- processors: {
182
- 'package-json-processor': {
183
- preprocess: (source, filename) => {
184
- // we only need to check for jiraRoot because it uses a different
185
- // ESLint version and produces fake errors due to how this processor handles JSON
186
- if (jiraRoot && filename.startsWith(jiraRoot)) {
187
- // augment the json into a js file
188
- return [jsonPrefixForJira + source.trim()];
189
- }
190
-
191
- // augment the json into a js file
192
- return [jsonPrefix + source.trim()];
193
- },
194
- postprocess: (messages) => {
195
- return messages[0].map((message) => {
196
- const { fix } = message;
197
- if (!fix) {
198
- return message;
199
- }
200
-
201
- const offset = jsonPrefix.length;
202
- return {
203
- ...message,
204
- fix: {
205
- ...fix,
206
- range: [fix.range[0] - offset, fix.range[1] - offset],
207
- },
208
- };
209
- });
210
- },
211
- supportsAutofix: true,
212
- } as Linter.Processor,
213
- // This processor is used for ESLint FlatConfig,
214
- // once we roll out FlatConfig, we can remove the above processor
215
- 'package-json-processor-for-flat-config': {
216
- // we only need to check for jiraRoot because it uses a different
217
- // ESLint version and produces fake errors due to how this processor handles JSON
218
- preprocess: (source, filename) => {
219
- if (jiraRoot && filename.startsWith(jiraRoot)) {
220
- // augment the json into a js file
221
- return [jsonPrefixForJira + source.trim()];
222
- }
223
- // augment the json into a js file
224
- return [jsonPrefixForFlatConfig + source.trim()];
225
- },
226
- postprocess: (messages) => {
227
- return messages[0].map((message) => {
228
- const { fix } = message;
229
- if (!fix) {
230
- return message;
231
- }
232
-
233
- const offset = jsonPrefixForFlatConfig.length;
234
- return {
235
- ...message,
236
- fix: {
237
- ...fix,
238
- range: [fix.range[0] - offset, fix.range[1] - offset],
239
- },
240
- };
241
- });
242
- },
243
- supportsAutofix: true,
244
- } as Linter.Processor,
245
- },
246
- } satisfies ESLint.Plugin;
247
- const configs = plugin.configs;
248
- const processors = plugin.processors;
249
-
250
- export { configs, plugin, processors, rules };
251
- export default plugin;
@@ -1,3 +0,0 @@
1
- # Atlassian platform ESLint Plugin > Compiled rules
2
-
3
- TODO
@@ -1,23 +0,0 @@
1
- # `expand-background-shorthand`
2
-
3
- This ESLint rule enforces the expansion of the CSS `background` shorthand property into
4
- its longhand equivalent `backgroundColor`, where the `background`'s value is an Atlassian
5
- Design System color token and the function call originates from `@compiled/react` or `@atlaskit/css`.
6
-
7
- ## Rule details
8
-
9
- 👎 Examples of **incorrect** code for this rule:
10
-
11
- ```js
12
- const styles = css({
13
- background: token('color.background.neutral.hovered'),
14
- });
15
- ```
16
-
17
- 👍 Examples of **correct** code for this rule:
18
-
19
- ```js
20
- const styles = css({
21
- backgroundColor: token('color.background.neutral.hovered'),
22
- });
23
- ```
@@ -1,160 +0,0 @@
1
- import { outdent } from 'outdent';
2
- import { tester } from '../../../../__tests__/utils/_tester';
3
- import { expandBackgroundShorthand } from '../index';
4
-
5
- const included_packages_calls_and_imports = [
6
- ['css', 'css', '@atlaskit/css'],
7
- ['css', 'css', '@compiled/react'],
8
- ['styled', 'styled.div', '@compiled/react'],
9
- ];
10
- const exempt_packages_calls_and_imports = [
11
- ['css', '@atlaskit/primitives'],
12
- ['css', '@emotion'],
13
- ['css', 'styled-components'],
14
- ['xcss', '@atlaskit/primitives'],
15
- ];
16
- tester.run('expand-background-shorthand', expandBackgroundShorthand, {
17
- valid: [
18
- ...exempt_packages_calls_and_imports.map(([pkg, imp]) => ({
19
- name: `do not have to handle non-Compiled packages (${pkg}, ${imp})`,
20
- code: outdent`
21
- import {${pkg}} from '${imp}';
22
- const styles = ${pkg}({
23
- background: token('color.background.accent.gray.subtlest')
24
- });
25
- `,
26
- })),
27
- {
28
- name: 'no background shorthand',
29
- code: outdent`
30
- import {css} from '@compiled/react';
31
- const styles = css({
32
- backgroundColor: token('color.background.neutral.hovered'),
33
- });
34
- const styles2 = css({
35
- backgroundColor: token('color.border', colors.N40),
36
- });
37
- const styles3 = css({
38
- backgroundColor: token('color.background.inverse.subtle', '#00000029'),
39
- });
40
- const styles4 = css({
41
- backgroundColor: token('color.background.brand.bold', 'lightblue'),
42
- });
43
- `,
44
- },
45
- // Other background shorthands that do not have token is out of scope for now
46
- {
47
- name: 'background shorthand without token',
48
- code: outdent`
49
- import {css} from '@compiled/react';
50
- const styles = css({
51
- background: 'transparent'
52
- });
53
- const styles2 = css({
54
- background: url('image.png')
55
- });
56
- const styles3 = css({
57
- background: 0
58
- });
59
- `,
60
- },
61
- // Usages of token within a template string are not used, so ESLint rule does not handle this case
62
- {
63
- name: 'background shorthand in a template literal as string text',
64
- code: outdent`
65
- import {css} from '@compiled/react';
66
- const styles = css({
67
- background: \`token('color.background.brand.bold', 'lightblue')\`,
68
- });
69
- `,
70
- },
71
- {
72
- name: 'background as key in cssMap call (cssMap, @compiled/react)',
73
- code: outdent`
74
- import { cssMap } from '@compiled/react';
75
- const colorMap = cssMap({
76
- background: {
77
- color: token('some.token')
78
- },
79
- foreground: {
80
- color: token('some.other.token')
81
- },
82
- });
83
- `,
84
- },
85
- ],
86
- invalid: [
87
- ...included_packages_calls_and_imports.map(([pkg, call, imp]) => ({
88
- name: `simple case (${call}, ${imp})`,
89
- code: outdent`
90
- import {${pkg}} from '${imp}';
91
- const styles = ${call}({
92
- background: token('color.background.accent.gray.subtlest'),
93
- });
94
- `,
95
- output: outdent`
96
- import {${pkg}} from '${imp}';
97
- const styles = ${call}({
98
- backgroundColor: token('color.background.accent.gray.subtlest'),
99
- });
100
- `,
101
- errors: [{ messageId: 'expandBackgroundShorthand' }],
102
- })),
103
- {
104
- name: `simple case (styled, @compiled/react)`,
105
- code: outdent`
106
- import { styled } from '@compiled/react';
107
- const Button = styled.div({
108
- paddingTop: '10px',
109
- });
110
- const StyledButton = styled(Button)({
111
- background: token('elevation.surface', colors.N0),
112
- });
113
- `,
114
- output: outdent`
115
- import { styled } from '@compiled/react';
116
- const Button = styled.div({
117
- paddingTop: '10px',
118
- });
119
- const StyledButton = styled(Button)({
120
- backgroundColor: token('elevation.surface', colors.N0),
121
- });
122
- `,
123
- errors: [{ messageId: 'expandBackgroundShorthand' }],
124
- },
125
- {
126
- name: `simple case (cssMap, @compiled/react)`,
127
- code: outdent`
128
- import { cssMap } from '@compiled/react';
129
- const backgroundMap = cssMap({
130
- firstBackground: { background: token('some.token') },
131
- secondBackground: { background: token('some.other.token') },
132
- });
133
- `,
134
- output: outdent`
135
- import { cssMap } from '@compiled/react';
136
- const backgroundMap = cssMap({
137
- firstBackground: { backgroundColor: token('some.token') },
138
- secondBackground: { backgroundColor: token('some.other.token') },
139
- });
140
- `,
141
- errors: Array.from(Array(2), () => ({ messageId: 'expandBackgroundShorthand' })),
142
- },
143
- {
144
- name: `compiled import with alias`,
145
- code: outdent`
146
- import { styled as styled2 } from '@compiled/react';
147
- const style = styled2.span({
148
- background: token('color.background.neutral.subtle', '#fff'),
149
- });
150
- `,
151
- output: outdent`
152
- import { styled as styled2 } from '@compiled/react';
153
- const style = styled2.span({
154
- backgroundColor: token('color.background.neutral.subtle', '#fff'),
155
- });
156
- `,
157
- errors: [{ messageId: 'expandBackgroundShorthand' }],
158
- },
159
- ],
160
- });
@@ -1,43 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import type { Property, Node } from 'estree';
3
- import { isCompiledAPI } from '../../util/compiled-utils';
4
-
5
- // Checks if node is a call expression with identifier 'token'
6
- const isTokenCallExpression = (node: Node) => {
7
- if (node.type === 'CallExpression') {
8
- if (node.callee.type === 'Identifier' && node.callee.name === 'token') {
9
- return true;
10
- }
11
- }
12
- return false;
13
- };
14
-
15
- export const expandBackgroundShorthand: Rule.RuleModule = {
16
- meta: {
17
- docs: {
18
- url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-background-shorthand/',
19
- },
20
- messages: {
21
- expandBackgroundShorthand: 'Use backgroundColor instead of background shorthand',
22
- },
23
- type: 'problem',
24
- fixable: 'code',
25
- },
26
- create(context) {
27
- return {
28
- 'Property[key.name="background"]': function (node: Property) {
29
- if (isCompiledAPI(context, node) && isTokenCallExpression(node.value)) {
30
- context.report({
31
- node,
32
- messageId: 'expandBackgroundShorthand',
33
- fix(fixer) {
34
- return fixer.replaceText(node.key, `backgroundColor`);
35
- },
36
- });
37
- }
38
- },
39
- };
40
- },
41
- };
42
-
43
- export default expandBackgroundShorthand;
@@ -1,51 +0,0 @@
1
- # `shorthand-property-sorting`
2
-
3
- This ESLint rule enforces the expansion of CSS `border` shorthand property, into its longhand
4
- equivalents `borderStyle`, `borderWidth`, `borderColor`, for packages that originates from
5
- `@compiled/react`, and `@atlaskit/css`.
6
-
7
- ## Rule details
8
-
9
- 👎 Examples of **incorrect** code for this rule:
10
-
11
- ```js
12
- const styles = css({
13
- border: '1px solid black',
14
- });
15
-
16
- const styles = css({
17
- border: '1px solid',
18
- });
19
-
20
- const styles = css({
21
- border: '1px',
22
- });
23
- ```
24
-
25
- 👍 Examples of **correct** code for this rule:
26
-
27
- ```js
28
- const styles = css({
29
- borderWidth: '1px',
30
- borderStyle: 'solid',
31
- borderColor: 'black',
32
- });
33
- ```
34
-
35
- ```js
36
- const styles = css({
37
- border: '0', // exempted from our ESLint rule
38
- });
39
-
40
- const styles = css({
41
- border: 'none', // exempted from our ESLint rule
42
- });
43
-
44
- const styles = css({
45
- border: 'unset', // exempted from our ESLint rule
46
- });
47
-
48
- const styles = css({
49
- border: 'none !important', // exempted from our ESLint rule
50
- });
51
- ```