@atlaskit/eslint-plugin-design-system 13.25.0 → 13.26.0

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 (33) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +71 -71
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -2
  4. package/dist/cjs/presets/all.codegen.js +2 -2
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -2
  6. package/dist/cjs/presets/recommended.codegen.js +2 -2
  7. package/dist/cjs/rules/index.codegen.js +3 -3
  8. package/dist/cjs/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.js +115 -19
  9. package/dist/es2019/presets/all-flat.codegen.js +2 -2
  10. package/dist/es2019/presets/all.codegen.js +2 -2
  11. package/dist/es2019/presets/recommended-flat.codegen.js +2 -2
  12. package/dist/es2019/presets/recommended.codegen.js +2 -2
  13. package/dist/es2019/rules/index.codegen.js +3 -3
  14. package/dist/es2019/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.js +109 -15
  15. package/dist/esm/presets/all-flat.codegen.js +2 -2
  16. package/dist/esm/presets/all.codegen.js +2 -2
  17. package/dist/esm/presets/recommended-flat.codegen.js +2 -2
  18. package/dist/esm/presets/recommended.codegen.js +2 -2
  19. package/dist/esm/rules/index.codegen.js +3 -3
  20. package/dist/esm/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.js +115 -19
  21. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  22. package/dist/types/presets/all.codegen.d.ts +1 -1
  23. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
  24. package/dist/types/presets/recommended.codegen.d.ts +1 -1
  25. package/dist/types/rules/index.codegen.d.ts +1 -1
  26. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
  27. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  28. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -1
  29. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
  30. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  31. package/package.json +3 -3
  32. /package/dist/types/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.d.ts +0 -0
  33. /package/dist/types-ts4.5/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.d.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7fae089db9d7d7153fea58c673bd56af>>
3
+ * @codegen <<SignedSource::df988d512376c1317e5f7a350ad19fb9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -15,7 +15,7 @@ const rules = {
15
15
  '@atlaskit/design-system/ensure-icon-color': 'error',
16
16
  '@atlaskit/design-system/ensure-proper-xcss-usage': 'error',
17
17
  '@atlaskit/design-system/icon-label': 'warn',
18
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
18
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
19
19
  '@atlaskit/design-system/no-banned-imports': 'error',
20
20
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
21
21
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::655d7f24171da0dff60003d0f235e48a>>
3
+ * @codegen <<SignedSource::2dee8518d733b0b364809d0f5641afda>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -14,7 +14,7 @@ const rules = {
14
14
  '@atlaskit/design-system/ensure-icon-color': 'error',
15
15
  '@atlaskit/design-system/ensure-proper-xcss-usage': 'error',
16
16
  '@atlaskit/design-system/icon-label': 'warn',
17
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
17
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
18
18
  '@atlaskit/design-system/no-banned-imports': 'error',
19
19
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
20
20
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::ff76b50abd06b99746997ad4f51a9178>>
3
+ * @codegen <<SignedSource::7ed1a8eeaaea559980cb2c533ba9a2e6>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -11,7 +11,7 @@ const rules = {
11
11
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
12
12
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
13
13
  '@atlaskit/design-system/icon-label': 'warn',
14
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
14
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
15
15
  '@atlaskit/design-system/no-banned-imports': 'error',
16
16
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
17
17
  '@atlaskit/design-system/no-deprecated-apis': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::07d2533eef1accad3c7ace7be7a8ea24>>
3
+ * @codegen <<SignedSource::32a0942d7edc5a3fdc70dd0833bb8aca>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -10,7 +10,7 @@ const rules = {
10
10
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
11
11
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
12
12
  '@atlaskit/design-system/icon-label': 'warn',
13
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
13
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
14
14
  '@atlaskit/design-system/no-banned-imports': 'error',
15
15
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
16
16
  '@atlaskit/design-system/no-deprecated-apis': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::75f94fc6b6fa998eed54b610e41bb9b1>>
3
+ * @codegen <<SignedSource::c74b833590d4eb693616a3fcbf2e335a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -11,7 +11,7 @@ import ensureDesignTokenUsagePreview from './ensure-design-token-usage-preview';
11
11
  import ensureIconColor from './ensure-icon-color';
12
12
  import ensureProperXcssUsage from './ensure-proper-xcss-usage';
13
13
  import iconLabel from './icon-label';
14
- import lozengeAppearanceAndIsboldMigration from './lozenge-appearance-and-isbold-migration';
14
+ import lozengeIsBoldAndLozengeBadgeAppearanceMigration from './lozenge-isBold-and-lozenge-badge-appearance-migration';
15
15
  import noBannedImports from './no-banned-imports';
16
16
  import noBooleanAutofocusOnModalDialog from './no-boolean-autofocus-on-modal-dialog';
17
17
  import noCssTaggedTemplateExpression from './no-css-tagged-template-expression';
@@ -81,7 +81,7 @@ export const rules = {
81
81
  'ensure-icon-color': ensureIconColor,
82
82
  'ensure-proper-xcss-usage': ensureProperXcssUsage,
83
83
  'icon-label': iconLabel,
84
- 'lozenge-appearance-and-isbold-migration': lozengeAppearanceAndIsboldMigration,
84
+ 'lozenge-isBold-and-lozenge-badge-appearance-migration': lozengeIsBoldAndLozengeBadgeAppearanceMigration,
85
85
  'no-banned-imports': noBannedImports,
86
86
  'no-boolean-autofocus-on-modal-dialog': noBooleanAutofocusOnModalDialog,
87
87
  'no-css-tagged-template-expression': noCssTaggedTemplateExpression,
@@ -2,18 +2,20 @@ import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { createLintRule } from '../utils/create-rule';
3
3
  const rule = createLintRule({
4
4
  meta: {
5
- name: 'lozenge-appearance-and-isbold-migration',
5
+ name: 'lozenge-isBold-and-lozenge-badge-appearance-migration',
6
6
  fixable: 'code',
7
7
  type: 'suggestion',
8
8
  docs: {
9
- description: 'Helps migrate deprecated Lozenge usages to the new API or Tag component as part of the Labelling System Phase 1 migration.',
9
+ description: 'Helps migrate Lozenge isBold prop and appearance values (for both Lozenge and Badge components) as part of the Labelling System Phase 1 migration.',
10
10
  recommended: true,
11
11
  severity: 'warn'
12
12
  },
13
13
  messages: {
14
14
  updateAppearance: 'Update appearance value to new semantic value.',
15
15
  migrateTag: 'Non-bold <Lozenge> variants should migrate to <Tag> component.',
16
- manualReview: "Dynamic 'isBold' props require manual review before migration."
16
+ manualReview: "Dynamic 'isBold' props require manual review before migration.",
17
+ updateBadgeAppearance: 'Update Badge appearance value "{{oldValue}}" to new semantic value "{{newValue}}".',
18
+ dynamicBadgeAppearance: 'Dynamic appearance prop values require manual review to ensure they use the new semantic values: neutral, information, inverse, danger, success.'
17
19
  }
18
20
  },
19
21
  create(context) {
@@ -22,6 +24,11 @@ const rule = createLintRule({
22
24
  */
23
25
  const lozengeImports = {}; // local name -> import source
24
26
 
27
+ /**
28
+ * Contains a map of imported Badge components.
29
+ */
30
+ const badgeImports = {}; // local name -> import source
31
+
25
32
  /**
26
33
  * Check if a JSX attribute value is a literal false
27
34
  */
@@ -30,14 +37,25 @@ const rule = createLintRule({
30
37
  }
31
38
 
32
39
  /**
33
- * Check if a JSX attribute value is dynamic (not a literal boolean)
40
+ * Check if a JSX attribute value is dynamic (not a static literal value)
41
+ * Can be used for any prop type (boolean, string, etc.)
34
42
  */
35
43
  function isDynamicExpression(node) {
36
- if (!node || node.type !== 'JSXExpressionContainer') {
44
+ if (!node) {
45
+ return false;
46
+ }
47
+
48
+ // If it's a plain literal (e.g., appearance="value"), it's not dynamic
49
+ if (node.type === 'Literal') {
37
50
  return false;
38
51
  }
39
- const expr = node.expression;
40
- return expr && !(expr.type === 'Literal' && typeof expr.value === 'boolean');
52
+
53
+ // If it's an expression container with a non-literal expression, it's dynamic
54
+ if (node.type === 'JSXExpressionContainer') {
55
+ const expr = node.expression;
56
+ return expr && expr.type !== 'Literal';
57
+ }
58
+ return false;
41
59
  }
42
60
 
43
61
  /**
@@ -70,6 +88,21 @@ const rule = createLintRule({
70
88
  return mapping[oldValue] || oldValue;
71
89
  }
72
90
 
91
+ /**
92
+ * Map Badge old appearance values to new semantic appearance values
93
+ */
94
+ function mapBadgeToNewAppearanceValue(oldValue) {
95
+ const mapping = {
96
+ added: 'success',
97
+ removed: 'danger',
98
+ default: 'neutral',
99
+ primary: 'information',
100
+ primaryInverted: 'inverse',
101
+ important: 'danger'
102
+ };
103
+ return mapping[oldValue] || oldValue;
104
+ }
105
+
73
106
  /**
74
107
  * Extract the string value from a JSX attribute value
75
108
  */
@@ -86,6 +119,25 @@ const rule = createLintRule({
86
119
  return null;
87
120
  }
88
121
 
122
+ /**
123
+ * Create a fixer function to replace an appearance prop value
124
+ * Handles both Literal and JSXExpressionContainer with Literal
125
+ */
126
+ function createAppearanceFixer(attrValue, newValue) {
127
+ return fixer => {
128
+ if (!attrValue) {
129
+ return null;
130
+ }
131
+ if (attrValue.type === 'Literal') {
132
+ return fixer.replaceText(attrValue, `"${newValue}"`);
133
+ }
134
+ if (attrValue.type === 'JSXExpressionContainer' && 'expression' in attrValue && attrValue.expression && attrValue.expression.type === 'Literal') {
135
+ return fixer.replaceText(attrValue.expression, `"${newValue}"`);
136
+ }
137
+ return null;
138
+ };
139
+ }
140
+
89
141
  /**
90
142
  * Generate the replacement JSX element text
91
143
  */
@@ -147,6 +199,18 @@ const rule = createLintRule({
147
199
  }
148
200
  });
149
201
  }
202
+ // Track Badge imports
203
+ if (moduleSource === '@atlaskit/badge' || moduleSource.startsWith('@atlaskit/badge')) {
204
+ node.specifiers.forEach(spec => {
205
+ if (spec.type === 'ImportDefaultSpecifier') {
206
+ badgeImports[spec.local.name] = moduleSource;
207
+ } else if (spec.type === 'ImportSpecifier' && spec.imported.type === 'Identifier') {
208
+ if (spec.imported.name === 'Badge' || spec.imported.name === 'default') {
209
+ badgeImports[spec.local.name] = moduleSource;
210
+ }
211
+ }
212
+ });
213
+ }
150
214
  }
151
215
  },
152
216
  JSXElement(node) {
@@ -158,6 +222,43 @@ const rule = createLintRule({
158
222
  }
159
223
  const elementName = node.openingElement.name.name;
160
224
 
225
+ // Handle Badge components
226
+ if (badgeImports[elementName]) {
227
+ // Find the appearance prop
228
+ const appearanceProp = node.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.type === 'JSXIdentifier' && attr.name.name === 'appearance');
229
+ if (!appearanceProp || appearanceProp.type !== 'JSXAttribute') {
230
+ // No appearance prop or it's a spread attribute, nothing to migrate
231
+ return;
232
+ }
233
+
234
+ // Check if it's a dynamic expression
235
+ if (isDynamicExpression(appearanceProp.value)) {
236
+ context.report({
237
+ node: appearanceProp,
238
+ messageId: 'dynamicBadgeAppearance'
239
+ });
240
+ return;
241
+ }
242
+
243
+ // Extract the string value
244
+ const stringValue = extractStringValue(appearanceProp.value);
245
+ if (stringValue && typeof stringValue === 'string') {
246
+ const mappedValue = mapBadgeToNewAppearanceValue(stringValue);
247
+ if (mappedValue !== stringValue) {
248
+ context.report({
249
+ node: appearanceProp,
250
+ messageId: 'updateBadgeAppearance',
251
+ data: {
252
+ oldValue: stringValue,
253
+ newValue: mappedValue
254
+ },
255
+ fix: createAppearanceFixer(appearanceProp.value, mappedValue)
256
+ });
257
+ }
258
+ }
259
+ return;
260
+ }
261
+
161
262
  // Only process if this is a Lozenge component we've imported
162
263
  if (!lozengeImports[elementName]) {
163
264
  return;
@@ -178,14 +279,7 @@ const rule = createLintRule({
178
279
  context.report({
179
280
  node: appearanceProp,
180
281
  messageId: 'updateAppearance',
181
- fix: fixer => {
182
- if (appearanceProp.value.type === 'Literal') {
183
- return fixer.replaceText(appearanceProp.value, `"${mappedValue}"`);
184
- } else if (appearanceProp.value.type === 'JSXExpressionContainer' && appearanceProp.value.expression && appearanceProp.value.expression.type === 'Literal') {
185
- return fixer.replaceText(appearanceProp.value.expression, `"${mappedValue}"`);
186
- }
187
- return null;
188
- }
282
+ fix: createAppearanceFixer(appearanceProp.value, mappedValue)
189
283
  });
190
284
  }
191
285
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7fae089db9d7d7153fea58c673bd56af>>
3
+ * @codegen <<SignedSource::df988d512376c1317e5f7a350ad19fb9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -15,7 +15,7 @@ var rules = {
15
15
  '@atlaskit/design-system/ensure-icon-color': 'error',
16
16
  '@atlaskit/design-system/ensure-proper-xcss-usage': 'error',
17
17
  '@atlaskit/design-system/icon-label': 'warn',
18
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
18
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
19
19
  '@atlaskit/design-system/no-banned-imports': 'error',
20
20
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
21
21
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::655d7f24171da0dff60003d0f235e48a>>
3
+ * @codegen <<SignedSource::2dee8518d733b0b364809d0f5641afda>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -14,7 +14,7 @@ var rules = {
14
14
  '@atlaskit/design-system/ensure-icon-color': 'error',
15
15
  '@atlaskit/design-system/ensure-proper-xcss-usage': 'error',
16
16
  '@atlaskit/design-system/icon-label': 'warn',
17
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
17
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
18
18
  '@atlaskit/design-system/no-banned-imports': 'error',
19
19
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
20
20
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::ff76b50abd06b99746997ad4f51a9178>>
3
+ * @codegen <<SignedSource::7ed1a8eeaaea559980cb2c533ba9a2e6>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -11,7 +11,7 @@ var rules = {
11
11
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
12
12
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
13
13
  '@atlaskit/design-system/icon-label': 'warn',
14
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
14
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
15
15
  '@atlaskit/design-system/no-banned-imports': 'error',
16
16
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
17
17
  '@atlaskit/design-system/no-deprecated-apis': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::07d2533eef1accad3c7ace7be7a8ea24>>
3
+ * @codegen <<SignedSource::32a0942d7edc5a3fdc70dd0833bb8aca>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -10,7 +10,7 @@ var rules = {
10
10
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
11
11
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
12
12
  '@atlaskit/design-system/icon-label': 'warn',
13
- '@atlaskit/design-system/lozenge-appearance-and-isbold-migration': 'warn',
13
+ '@atlaskit/design-system/lozenge-isBold-and-lozenge-badge-appearance-migration': 'warn',
14
14
  '@atlaskit/design-system/no-banned-imports': 'error',
15
15
  '@atlaskit/design-system/no-boolean-autofocus-on-modal-dialog': 'warn',
16
16
  '@atlaskit/design-system/no-deprecated-apis': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::75f94fc6b6fa998eed54b610e41bb9b1>>
3
+ * @codegen <<SignedSource::c74b833590d4eb693616a3fcbf2e335a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -11,7 +11,7 @@ import ensureDesignTokenUsagePreview from './ensure-design-token-usage-preview';
11
11
  import ensureIconColor from './ensure-icon-color';
12
12
  import ensureProperXcssUsage from './ensure-proper-xcss-usage';
13
13
  import iconLabel from './icon-label';
14
- import lozengeAppearanceAndIsboldMigration from './lozenge-appearance-and-isbold-migration';
14
+ import lozengeIsBoldAndLozengeBadgeAppearanceMigration from './lozenge-isBold-and-lozenge-badge-appearance-migration';
15
15
  import noBannedImports from './no-banned-imports';
16
16
  import noBooleanAutofocusOnModalDialog from './no-boolean-autofocus-on-modal-dialog';
17
17
  import noCssTaggedTemplateExpression from './no-css-tagged-template-expression';
@@ -81,7 +81,7 @@ export var rules = {
81
81
  'ensure-icon-color': ensureIconColor,
82
82
  'ensure-proper-xcss-usage': ensureProperXcssUsage,
83
83
  'icon-label': iconLabel,
84
- 'lozenge-appearance-and-isbold-migration': lozengeAppearanceAndIsboldMigration,
84
+ 'lozenge-isBold-and-lozenge-badge-appearance-migration': lozengeIsBoldAndLozengeBadgeAppearanceMigration,
85
85
  'no-banned-imports': noBannedImports,
86
86
  'no-boolean-autofocus-on-modal-dialog': noBooleanAutofocusOnModalDialog,
87
87
  'no-css-tagged-template-expression': noCssTaggedTemplateExpression,
@@ -2,18 +2,20 @@ import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { createLintRule } from '../utils/create-rule';
3
3
  var rule = createLintRule({
4
4
  meta: {
5
- name: 'lozenge-appearance-and-isbold-migration',
5
+ name: 'lozenge-isBold-and-lozenge-badge-appearance-migration',
6
6
  fixable: 'code',
7
7
  type: 'suggestion',
8
8
  docs: {
9
- description: 'Helps migrate deprecated Lozenge usages to the new API or Tag component as part of the Labelling System Phase 1 migration.',
9
+ description: 'Helps migrate Lozenge isBold prop and appearance values (for both Lozenge and Badge components) as part of the Labelling System Phase 1 migration.',
10
10
  recommended: true,
11
11
  severity: 'warn'
12
12
  },
13
13
  messages: {
14
14
  updateAppearance: 'Update appearance value to new semantic value.',
15
15
  migrateTag: 'Non-bold <Lozenge> variants should migrate to <Tag> component.',
16
- manualReview: "Dynamic 'isBold' props require manual review before migration."
16
+ manualReview: "Dynamic 'isBold' props require manual review before migration.",
17
+ updateBadgeAppearance: 'Update Badge appearance value "{{oldValue}}" to new semantic value "{{newValue}}".',
18
+ dynamicBadgeAppearance: 'Dynamic appearance prop values require manual review to ensure they use the new semantic values: neutral, information, inverse, danger, success.'
17
19
  }
18
20
  },
19
21
  create: function create(context) {
@@ -22,6 +24,11 @@ var rule = createLintRule({
22
24
  */
23
25
  var lozengeImports = {}; // local name -> import source
24
26
 
27
+ /**
28
+ * Contains a map of imported Badge components.
29
+ */
30
+ var badgeImports = {}; // local name -> import source
31
+
25
32
  /**
26
33
  * Check if a JSX attribute value is a literal false
27
34
  */
@@ -30,14 +37,25 @@ var rule = createLintRule({
30
37
  }
31
38
 
32
39
  /**
33
- * Check if a JSX attribute value is dynamic (not a literal boolean)
40
+ * Check if a JSX attribute value is dynamic (not a static literal value)
41
+ * Can be used for any prop type (boolean, string, etc.)
34
42
  */
35
43
  function isDynamicExpression(node) {
36
- if (!node || node.type !== 'JSXExpressionContainer') {
44
+ if (!node) {
45
+ return false;
46
+ }
47
+
48
+ // If it's a plain literal (e.g., appearance="value"), it's not dynamic
49
+ if (node.type === 'Literal') {
37
50
  return false;
38
51
  }
39
- var expr = node.expression;
40
- return expr && !(expr.type === 'Literal' && typeof expr.value === 'boolean');
52
+
53
+ // If it's an expression container with a non-literal expression, it's dynamic
54
+ if (node.type === 'JSXExpressionContainer') {
55
+ var expr = node.expression;
56
+ return expr && expr.type !== 'Literal';
57
+ }
58
+ return false;
41
59
  }
42
60
 
43
61
  /**
@@ -70,6 +88,21 @@ var rule = createLintRule({
70
88
  return mapping[oldValue] || oldValue;
71
89
  }
72
90
 
91
+ /**
92
+ * Map Badge old appearance values to new semantic appearance values
93
+ */
94
+ function mapBadgeToNewAppearanceValue(oldValue) {
95
+ var mapping = {
96
+ added: 'success',
97
+ removed: 'danger',
98
+ default: 'neutral',
99
+ primary: 'information',
100
+ primaryInverted: 'inverse',
101
+ important: 'danger'
102
+ };
103
+ return mapping[oldValue] || oldValue;
104
+ }
105
+
73
106
  /**
74
107
  * Extract the string value from a JSX attribute value
75
108
  */
@@ -86,6 +119,25 @@ var rule = createLintRule({
86
119
  return null;
87
120
  }
88
121
 
122
+ /**
123
+ * Create a fixer function to replace an appearance prop value
124
+ * Handles both Literal and JSXExpressionContainer with Literal
125
+ */
126
+ function createAppearanceFixer(attrValue, newValue) {
127
+ return function (fixer) {
128
+ if (!attrValue) {
129
+ return null;
130
+ }
131
+ if (attrValue.type === 'Literal') {
132
+ return fixer.replaceText(attrValue, "\"".concat(newValue, "\""));
133
+ }
134
+ if (attrValue.type === 'JSXExpressionContainer' && 'expression' in attrValue && attrValue.expression && attrValue.expression.type === 'Literal') {
135
+ return fixer.replaceText(attrValue.expression, "\"".concat(newValue, "\""));
136
+ }
137
+ return null;
138
+ };
139
+ }
140
+
89
141
  /**
90
142
  * Generate the replacement JSX element text
91
143
  */
@@ -147,6 +199,18 @@ var rule = createLintRule({
147
199
  }
148
200
  });
149
201
  }
202
+ // Track Badge imports
203
+ if (moduleSource === '@atlaskit/badge' || moduleSource.startsWith('@atlaskit/badge')) {
204
+ node.specifiers.forEach(function (spec) {
205
+ if (spec.type === 'ImportDefaultSpecifier') {
206
+ badgeImports[spec.local.name] = moduleSource;
207
+ } else if (spec.type === 'ImportSpecifier' && spec.imported.type === 'Identifier') {
208
+ if (spec.imported.name === 'Badge' || spec.imported.name === 'default') {
209
+ badgeImports[spec.local.name] = moduleSource;
210
+ }
211
+ }
212
+ });
213
+ }
150
214
  }
151
215
  },
152
216
  JSXElement: function JSXElement(node) {
@@ -158,6 +222,45 @@ var rule = createLintRule({
158
222
  }
159
223
  var elementName = node.openingElement.name.name;
160
224
 
225
+ // Handle Badge components
226
+ if (badgeImports[elementName]) {
227
+ // Find the appearance prop
228
+ var _appearanceProp = node.openingElement.attributes.find(function (attr) {
229
+ return attr.type === 'JSXAttribute' && attr.name.type === 'JSXIdentifier' && attr.name.name === 'appearance';
230
+ });
231
+ if (!_appearanceProp || _appearanceProp.type !== 'JSXAttribute') {
232
+ // No appearance prop or it's a spread attribute, nothing to migrate
233
+ return;
234
+ }
235
+
236
+ // Check if it's a dynamic expression
237
+ if (isDynamicExpression(_appearanceProp.value)) {
238
+ context.report({
239
+ node: _appearanceProp,
240
+ messageId: 'dynamicBadgeAppearance'
241
+ });
242
+ return;
243
+ }
244
+
245
+ // Extract the string value
246
+ var stringValue = extractStringValue(_appearanceProp.value);
247
+ if (stringValue && typeof stringValue === 'string') {
248
+ var mappedValue = mapBadgeToNewAppearanceValue(stringValue);
249
+ if (mappedValue !== stringValue) {
250
+ context.report({
251
+ node: _appearanceProp,
252
+ messageId: 'updateBadgeAppearance',
253
+ data: {
254
+ oldValue: stringValue,
255
+ newValue: mappedValue
256
+ },
257
+ fix: createAppearanceFixer(_appearanceProp.value, mappedValue)
258
+ });
259
+ }
260
+ }
261
+ return;
262
+ }
263
+
161
264
  // Only process if this is a Lozenge component we've imported
162
265
  if (!lozengeImports[elementName]) {
163
266
  return;
@@ -171,21 +274,14 @@ var rule = createLintRule({
171
274
  var shouldMigrateToTag = !isBoldProp || isLiteralFalse(isBoldProp.value);
172
275
  if (!shouldMigrateToTag) {
173
276
  // Only update appearance values for Lozenge components that stay as Lozenge
174
- var stringValue = extractStringValue(appearanceProp.value);
175
- if (stringValue && typeof stringValue === 'string') {
176
- var mappedValue = mapToNewAppearanceValue(stringValue);
177
- if (mappedValue !== stringValue) {
277
+ var _stringValue = extractStringValue(appearanceProp.value);
278
+ if (_stringValue && typeof _stringValue === 'string') {
279
+ var _mappedValue = mapToNewAppearanceValue(_stringValue);
280
+ if (_mappedValue !== _stringValue) {
178
281
  context.report({
179
282
  node: appearanceProp,
180
283
  messageId: 'updateAppearance',
181
- fix: function fix(fixer) {
182
- if (appearanceProp.value.type === 'Literal') {
183
- return fixer.replaceText(appearanceProp.value, "\"".concat(mappedValue, "\""));
184
- } else if (appearanceProp.value.type === 'JSXExpressionContainer' && appearanceProp.value.expression && appearanceProp.value.expression.type === 'Literal') {
185
- return fixer.replaceText(appearanceProp.value.expression, "\"".concat(mappedValue, "\""));
186
- }
187
- return null;
188
- }
284
+ fix: createAppearanceFixer(appearanceProp.value, _mappedValue)
189
285
  });
190
286
  }
191
287
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7fae089db9d7d7153fea58c673bd56af>>
3
+ * @codegen <<SignedSource::df988d512376c1317e5f7a350ad19fb9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { Linter } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::655d7f24171da0dff60003d0f235e48a>>
3
+ * @codegen <<SignedSource::2dee8518d733b0b364809d0f5641afda>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { ESLint } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::ff76b50abd06b99746997ad4f51a9178>>
3
+ * @codegen <<SignedSource::7ed1a8eeaaea559980cb2c533ba9a2e6>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { Linter } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::07d2533eef1accad3c7ace7be7a8ea24>>
3
+ * @codegen <<SignedSource::32a0942d7edc5a3fdc70dd0833bb8aca>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { ESLint } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::75f94fc6b6fa998eed54b610e41bb9b1>>
3
+ * @codegen <<SignedSource::c74b833590d4eb693616a3fcbf2e335a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { Rule } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7fae089db9d7d7153fea58c673bd56af>>
3
+ * @codegen <<SignedSource::df988d512376c1317e5f7a350ad19fb9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { Linter } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::655d7f24171da0dff60003d0f235e48a>>
3
+ * @codegen <<SignedSource::2dee8518d733b0b364809d0f5641afda>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import type { ESLint } from 'eslint';