@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,26 +0,0 @@
1
- /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
- /* eslint-disable no-undef */
3
- import { RuleTester } from 'eslint';
4
-
5
- (RuleTester as any).describe = (text: string, method: Function) => {
6
- const origHasAssertions = expect.hasAssertions;
7
- describe(text, () => {
8
- beforeAll(() => {
9
- // Stub out expect.hasAssertions beforeEach from jest-presetup.js
10
- expect.hasAssertions = () => {};
11
- });
12
- afterAll(() => {
13
- expect.hasAssertions = origHasAssertions;
14
- });
15
-
16
- method();
17
- });
18
- };
19
-
20
- export const tester = new RuleTester({
21
- parser: require.resolve('@babel/eslint-parser'),
22
- parserOptions: {
23
- ecmaVersion: 6,
24
- sourceType: 'module',
25
- },
26
- });
package/src/index.tsx DELETED
@@ -1,254 +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 noSetImmediate from './rules/no-set-immediate';
34
- import { join, normalize } from 'node:path';
35
- import { readFileSync } from 'node:fs';
36
-
37
- let jiraRoot: string | undefined;
38
-
39
- try {
40
- const findUp = require('find-up') as typeof import('find-up');
41
- findUp.sync((dir) => {
42
- const productsJsonPath = join(dir, 'products.json');
43
- if (findUp.sync.exists(productsJsonPath)) {
44
- const productJson: Record<string, { path: string }> = JSON.parse(
45
- readFileSync(productsJsonPath, 'utf-8'),
46
- );
47
- if (productJson.Jira) {
48
- jiraRoot = normalize(join(dir, productJson.Jira.path));
49
- return findUp.stop;
50
- }
51
- }
52
- });
53
- } catch {
54
- // we aren't running inside of AFM, so we can ignore this.
55
- }
56
-
57
- const packageJson: {
58
- name: string;
59
- version: string;
60
- // eslint-disable-next-line import/no-extraneous-dependencies
61
- } = require('@atlaskit/eslint-plugin-platform/package.json');
62
-
63
- const rules = {
64
- 'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
65
- 'ensure-feature-flag-prefix': ensureFeatureFlagPrefix,
66
- 'ensure-test-runner-arguments': ensureTestRunnerArguments,
67
- 'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
68
- 'ensure-atlassian-team': ensureAtlassianTeam,
69
- 'ensure-critical-dependency-resolutions': ensureCriticalDependencyResolutions,
70
- 'ensure-valid-platform-yarn-protocol-usage': ensureValidPlatformYarnProtocolUsage,
71
- 'ensure-valid-bin-values': ensureValidBinValues,
72
- 'ensure-no-private-dependencies': ensureNoPrivateDependencies,
73
- 'expand-border-shorthand': expandBorderShorthand,
74
- 'expand-background-shorthand': expandBackgroundShorthand,
75
- 'expand-spacing-shorthand': expandSpacingShorthand,
76
- 'no-duplicate-dependencies': noDuplicateDependencies,
77
- 'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
78
- 'no-pre-post-install-scripts': noPreAndPostInstallScripts,
79
- 'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
80
- 'ensure-publish-valid': ensurePublishValid,
81
- 'ensure-native-and-af-exports-synced': ensureNativeAndAfExportsSynced,
82
- 'no-module-level-eval': noModuleLevelEval,
83
- 'no-module-level-eval-nav4': noModuleLevelEvalNav4,
84
- 'static-feature-flags': staticFeatureFlags,
85
- 'no-preconditioning': noPreconditioning,
86
- 'inline-usage': inlineUsage,
87
- 'prefer-fg': preferFG,
88
- 'no-alias': noAlias,
89
- 'use-entrypoints-in-examples': useEntrypointsInExamples,
90
- 'use-recommended-utils': useRecommendedUtils,
91
- 'no-sparse-checkout': noSparseCheckout,
92
- 'no-direct-document-usage': noDirectDocumentUsage,
93
- 'no-set-immediate': noSetImmediate,
94
- };
95
-
96
- const commonConfig = {
97
- '@atlaskit/platform/ensure-test-runner-arguments': 'error',
98
- '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
99
- '@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
100
- '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
101
- '@atlaskit/platform/ensure-atlassian-team': 'error',
102
- '@atlaskit/platform/no-module-level-eval-nav4': 'error',
103
- '@atlaskit/platform/no-direct-document-usage': 'warn',
104
- '@atlaskit/platform/no-set-immediate': 'error',
105
- // Compiled: rules that are not included via `@compiled/recommended
106
- '@atlaskit/platform/expand-border-shorthand': 'error',
107
- '@atlaskit/platform/expand-background-shorthand': 'error',
108
- '@atlaskit/platform/expand-spacing-shorthand': 'error',
109
- '@compiled/jsx-pragma': [
110
- 'error',
111
- {
112
- importSources: ['@atlaskit/css'],
113
- onlyRunIfImportingCompiled: true,
114
- runtime: 'classic',
115
- },
116
- ],
117
- } satisfies Linter.RulesRecord;
118
-
119
- const recommendedRules = {
120
- ...commonConfig,
121
- // See platform/packages/platform/eslint-plugin/src/rules/feature-gating/README.md
122
- // These rules are specific to `platform` and seem a WIP; jira and confluence currently have their own rules
123
- '@atlaskit/platform/no-module-level-eval': 'error',
124
- '@atlaskit/platform/static-feature-flags': 'error',
125
- '@atlaskit/platform/no-preconditioning': 'error',
126
- '@atlaskit/platform/inline-usage': 'error',
127
- '@atlaskit/platform/prefer-fg': 'error',
128
- '@atlaskit/platform/no-alias': 'error',
129
- // end: feature-gating rules
130
- '@atlaskit/platform/ensure-feature-flag-registration': 'error',
131
- '@atlaskit/platform/ensure-feature-flag-prefix': [
132
- 'warn',
133
- { allowedPrefixes: ['platform.', 'platform_'] },
134
- ],
135
- } satisfies Linter.RulesRecord;
136
-
137
- const jiraRules = commonConfig;
138
-
139
- const jsonPrefix =
140
- '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ';
141
-
142
- const jsonPrefixForFlatConfig =
143
- '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
144
-
145
- const jsonPrefixForJira = 'module.exports = ';
146
-
147
- const { name, version } = packageJson;
148
- const plugin = {
149
- meta: {
150
- name,
151
- version,
152
- },
153
- rules,
154
- configs: {
155
- recommended: {
156
- plugins: ['@atlaskit/platform', '@compiled'],
157
- rules: recommendedRules,
158
- },
159
- 'recommended/flat': {
160
- plugins: {
161
- get '@atlaskit/platform'(): ESLint.Plugin {
162
- return plugin;
163
- },
164
- // @ts-expect-error there's an issue with the types for @compiled/eslint-plugin ('no-css-prop-without-css-function' specifically)
165
- '@compiled': { meta: compiledPlugin.meta, rules: compiledPlugin.rules } as ESLint.Plugin,
166
- },
167
- rules: recommendedRules,
168
- },
169
- jira: {
170
- plugins: ['@atlaskit/platform', '@compiled'],
171
- rules: jiraRules,
172
- },
173
- 'jira/flat': {
174
- plugins: {
175
- get '@atlaskit/platform'(): ESLint.Plugin {
176
- return plugin;
177
- },
178
- // @ts-expect-error there's an issue with the types for @compiled/eslint-plugin ('no-css-prop-without-css-function' specifically)
179
- '@compiled': { meta: compiledPlugin.meta, rules: compiledPlugin.rules } as ESLint.Plugin,
180
- },
181
- rules: jiraRules,
182
- },
183
- },
184
- processors: {
185
- 'package-json-processor': {
186
- preprocess: (source, filename) => {
187
- // we only need to check for jiraRoot because it uses a different
188
- // ESLint version and produces fake errors due to how this processor handles JSON
189
- if (jiraRoot && filename.startsWith(jiraRoot)) {
190
- // augment the json into a js file
191
- return [jsonPrefixForJira + source.trim()];
192
- }
193
-
194
- // augment the json into a js file
195
- return [jsonPrefix + source.trim()];
196
- },
197
- postprocess: (messages) => {
198
- return messages[0].map((message) => {
199
- const { fix } = message;
200
- if (!fix) {
201
- return message;
202
- }
203
-
204
- const offset = jsonPrefix.length;
205
- return {
206
- ...message,
207
- fix: {
208
- ...fix,
209
- range: [fix.range[0] - offset, fix.range[1] - offset],
210
- },
211
- };
212
- });
213
- },
214
- supportsAutofix: true,
215
- } as Linter.Processor,
216
- // This processor is used for ESLint FlatConfig,
217
- // once we roll out FlatConfig, we can remove the above processor
218
- 'package-json-processor-for-flat-config': {
219
- // we only need to check for jiraRoot because it uses a different
220
- // ESLint version and produces fake errors due to how this processor handles JSON
221
- preprocess: (source, filename) => {
222
- if (jiraRoot && filename.startsWith(jiraRoot)) {
223
- // augment the json into a js file
224
- return [jsonPrefixForJira + source.trim()];
225
- }
226
- // augment the json into a js file
227
- return [jsonPrefixForFlatConfig + source.trim()];
228
- },
229
- postprocess: (messages) => {
230
- return messages[0].map((message) => {
231
- const { fix } = message;
232
- if (!fix) {
233
- return message;
234
- }
235
-
236
- const offset = jsonPrefixForFlatConfig.length;
237
- return {
238
- ...message,
239
- fix: {
240
- ...fix,
241
- range: [fix.range[0] - offset, fix.range[1] - offset],
242
- },
243
- };
244
- });
245
- },
246
- supportsAutofix: true,
247
- } as Linter.Processor,
248
- },
249
- } satisfies ESLint.Plugin;
250
- const configs = plugin.configs;
251
- const processors = plugin.processors;
252
-
253
- export { configs, plugin, processors, rules };
254
- 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
- ```