@atlaskit/eslint-plugin-design-system 10.10.0 → 10.10.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 (56) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/rules/no-legacy-icons/checks.js +63 -67
  3. package/dist/cjs/rules/no-legacy-icons/helpers.js +29 -24
  4. package/dist/cjs/rules/no-legacy-icons/index.js +4 -5
  5. package/dist/es2019/rules/no-legacy-icons/checks.js +20 -33
  6. package/dist/es2019/rules/no-legacy-icons/helpers.js +24 -21
  7. package/dist/es2019/rules/no-legacy-icons/index.js +4 -5
  8. package/dist/esm/rules/no-legacy-icons/checks.js +64 -68
  9. package/dist/esm/rules/no-legacy-icons/helpers.js +28 -23
  10. package/dist/esm/rules/no-legacy-icons/index.js +4 -5
  11. package/dist/types/rules/no-legacy-icons/helpers.d.ts +3 -13
  12. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +3 -13
  13. package/package.json +2 -2
  14. package/constellation/consistent-css-prop-usage/usage.mdx +0 -210
  15. package/constellation/ensure-design-token-usage/usage.mdx +0 -77
  16. package/constellation/ensure-design-token-usage-preview/usage.mdx +0 -6
  17. package/constellation/icon-label/usage.mdx +0 -41
  18. package/constellation/index/props.mdx +0 -30
  19. package/constellation/index/usage.mdx +0 -57
  20. package/constellation/no-banned-imports/usage.mdx +0 -19
  21. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -71
  22. package/constellation/no-custom-icons/usage.mdx +0 -36
  23. package/constellation/no-deprecated-apis/usage.mdx +0 -82
  24. package/constellation/no-deprecated-design-token-usage/usage.mdx +0 -30
  25. package/constellation/no-deprecated-imports/usage.mdx +0 -66
  26. package/constellation/no-direct-use-of-web-platform-drag-and-drop/usage.mdx +0 -149
  27. package/constellation/no-empty-styled-expression/usage.mdx +0 -82
  28. package/constellation/no-exported-css/usage.mdx +0 -55
  29. package/constellation/no-exported-keyframes/usage.mdx +0 -55
  30. package/constellation/no-html-anchor/usage.mdx +0 -46
  31. package/constellation/no-html-button/usage.mdx +0 -52
  32. package/constellation/no-invalid-css-map/usage.mdx +0 -210
  33. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -80
  34. package/constellation/no-legacy-icons/usage.mdx +0 -42
  35. package/constellation/no-margin/usage.mdx +0 -21
  36. package/constellation/no-nested-styles/usage.mdx +0 -47
  37. package/constellation/no-physical-properties/usage.mdx +0 -53
  38. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -135
  39. package/constellation/no-unsafe-design-token-usage/usage.mdx +0 -50
  40. package/constellation/no-unsafe-style-overrides/usage.mdx +0 -52
  41. package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +0 -23
  42. package/constellation/prefer-primitives/usage.mdx +0 -32
  43. package/constellation/use-button-group-label/usage.mdx +0 -60
  44. package/constellation/use-drawer-label/usage.mdx +0 -55
  45. package/constellation/use-heading/usage.mdx +0 -31
  46. package/constellation/use-heading-level-in-spotlight-card/usage.mdx +0 -21
  47. package/constellation/use-href-in-link-item/usage.mdx +0 -19
  48. package/constellation/use-latest-xcss-syntax/usage.mdx +0 -33
  49. package/constellation/use-latest-xcss-syntax-typography/usage.mdx +0 -34
  50. package/constellation/use-menu-section-title/usage.mdx +0 -55
  51. package/constellation/use-popup-label/usage.mdx +0 -56
  52. package/constellation/use-primitives/usage.mdx +0 -78
  53. package/constellation/use-primitives-text/usage.mdx +0 -35
  54. package/constellation/use-tokens-space/usage.mdx +0 -34
  55. package/constellation/use-tokens-typography/usage.mdx +0 -55
  56. package/constellation/use-visually-hidden/usage.mdx +0 -35
@@ -19,7 +19,7 @@ export const getMigrationMapObject = iconPackage => {
19
19
  * @param iconPackage The name of the legacy icon package
20
20
  * @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
21
21
  */
22
- export const getIconKey = iconPackage => {
22
+ const getIconKey = iconPackage => {
23
23
  const key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
24
24
  return key;
25
25
  };
@@ -34,36 +34,43 @@ export const canAutoMigrateNewIconBasedOnSize = guidance => {
34
34
  /**
35
35
  * Creates the written guidance for migrating a legacy icon to a new icon
36
36
  */
37
- export const createGuidance = (iconPackage, size) => {
37
+ export const createGuidance = (iconPackage, insideNewButton = false, size) => {
38
38
  const migrationMapObject = getMigrationMapObject(iconPackage);
39
39
  if (migrationMapObject) {
40
40
  const newIcon = migrationMapObject.newIcon;
41
41
  if (!newIcon) {
42
42
  return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
43
43
  }
44
+ const buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
45
+ let guidance = '';
44
46
  if (size) {
45
- let guidance = `Fix: Use ${newIcon.name} from @atlaskit/${newIcon.library}/${newIcon.type}/${newIcon.name} instead.`;
46
- if (migrationMapObject.sizeGuidance[size] in outcomeDescriptionMap) {
47
- guidance += ` Please: ${outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]}\n`;
47
+ if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
48
+ guidance += `Fix: Use ${newIcon.name} from @atlaskit/${newIcon.library}/${newIcon.type}/${newIcon.name} instead.`;
48
49
  } else {
49
- guidance += ' No migration advice given.\n';
50
+ guidance += `No equivalent icon for this size, ${size}, in new set.`;
50
51
  }
51
- return guidance;
52
+ guidance += `${migrationMapObject.sizeGuidance[size] in outcomeDescriptionMap ? ` Please: ${outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]}` : ' No migration size advice given.'}\n`;
52
53
  } else {
53
- let guidance = `Use ${newIcon.name} from @atlaskit/${newIcon.library}/${newIcon.type}/${newIcon.name} instead.\nMigration suggestions, depending on the legacy icon size:\n`;
54
+ guidance = `Use ${newIcon.name} from @atlaskit/${newIcon.library}/${newIcon.type}/${newIcon.name} instead.\nMigration suggestions, depending on the legacy icon size:\n`;
54
55
  for (const [size, value] of Object.entries(migrationMapObject.sizeGuidance)) {
55
56
  guidance += `\t- ${size}: `;
56
57
  if (!(value in outcomeDescriptionMap)) {
57
58
  guidance += 'No migration advice given.\n';
58
59
  } else {
59
- guidance += `${outcomeDescriptionMap[value]}\n`;
60
+ guidance += `${outcomeDescriptionMap[value]}.\n`;
60
61
  }
61
- guidance;
62
62
  }
63
- return guidance;
64
63
  }
64
+ if (insideNewButton) {
65
+ guidance += buttonGuidanceStr;
66
+ } else if (size && size === 'medium') {
67
+ guidance += "Setting the spacing property to 'spacious' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
68
+ } else if (size) {
69
+ guidance += "In the new icon, please use spacing='none'.\n";
70
+ }
71
+ return guidance;
65
72
  } else {
66
- return 'Migration suggestions not found\n';
73
+ return `Migration suggestions not found for "${iconPackage}".\n`;
67
74
  }
68
75
  };
69
76
 
@@ -139,13 +146,14 @@ export const createCantMigrateUnsafeProp = (node, propName, value, packageName,
139
146
  };
140
147
  pushManualError(locToString(node), errors, myError, packageName, iconName);
141
148
  };
142
- export const createCantFindSuitableReplacementError = (node, importSource, iconName, errors) => {
149
+ export const createCantFindSuitableReplacementError = (node, importSource, iconName, errors, sizeIssue) => {
143
150
  const myError = {
144
151
  node,
145
152
  messageId: 'cantFindSuitableReplacement',
146
153
  data: {
147
154
  importSource,
148
- iconName
155
+ iconName,
156
+ sizeGuidance: sizeIssue ? ' at the current size' : ''
149
157
  }
150
158
  };
151
159
  pushManualError(locToString(node), errors, myError, importSource, iconName);
@@ -188,18 +196,13 @@ export const createCantMigrateSizeUnknown = (node, errors, importSource, iconNam
188
196
  };
189
197
  pushManualError(locToString(node), errors, myError, importSource, iconName);
190
198
  };
191
- export const createAutoMigrationError = (node, importSource, iconName, newIcon, oldIconName, errors) => {
192
- const migrationKey = newIcon.name === oldIconName ? newIcon.name : `${newIcon.name}--${oldIconName}`;
193
- const newMigrationIconPackage = `@atlaskit/${newIcon.library}/${newIcon.type}/migration/${migrationKey}`;
199
+ export const createAutoMigrationError = (node, importSource, iconName, errors) => {
194
200
  const myError = {
195
201
  node,
196
202
  messageId: 'noLegacyIconsAutoMigration',
197
203
  data: {
198
204
  importSource,
199
- iconName,
200
- newIcon: newIcon.name,
201
- //TODO: provide size guidance
202
- newPackage: newMigrationIconPackage
205
+ iconName
203
206
  }
204
207
  };
205
208
  errors[locToString(node)] = myError;
@@ -27,17 +27,16 @@ const rule = createLintRule({
27
27
  additionalProperties: false
28
28
  }],
29
29
  messages: {
30
- noLegacyIconsAutoMigration: `Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible to '{{newIcon}}' from '{{newPackage}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'`,
31
- noLegacyIconsManualMigration: `Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.{{quietModeGuidance}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.`,
32
- cantFindSuitableReplacement: `No suitable replacement found for '{{iconName}}' from '{{importSource}}' at the size listed. Please manually migrate this icon.`,
30
+ noLegacyIconsAutoMigration: `Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'`,
31
+ noLegacyIconsManualMigration: `Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.`,
32
+ cantFindSuitableReplacement: `No suitable replacement found for '{{iconName}}' from '{{importSource}}'{{sizeGuidance}}. Please manually migrate this icon.`,
33
33
  cantMigrateReExport: `'{{exportName}}' is a re-export of icon from '{{packageName}}' and cannot be automatically migrated. Please utilize the export from icons directly.`,
34
34
  cantMigrateColor: `Primary Color prop has {{colorValue}} which cannot be automatically migrated to color prop in the new Icon API. Please use either an appropriate color.icon, color.link token, or currentColor (as a last resort).`,
35
35
  cantMigrateSpreadProps: `This usage of Icon uses spread props in a way that can't be automatically migrated. Please explicitly define the following props after spread: '{{missingProps}}' `,
36
36
  cantMigrateSizeUnknown: `This usage of Icon sets the size via a variable or function that can't be determined.`,
37
37
  cantMigrateFunctionUnknown: `'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.`,
38
38
  cantMigrateIdentifier: `This icon is passed to other components via a map or array, in a way that can't be automatically migrated. Please manually migrate wherever this expression is used and use the icon components directly.`,
39
- cantMigrateUnsafeProp: `Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon.`,
40
- guidance: `Guidance:\n'{{guidance}}'`
39
+ cantMigrateUnsafeProp: `Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon.`
41
40
  }
42
41
  },
43
42
  create(context) {
@@ -3,7 +3,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
3
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  import { isNodeOfType } from 'eslint-codemod-utils';
6
- import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createCantMigrateUnsafeProp, createGuidance, createHelpers, findUNSAFEProp, getIconKey, getMigrationMapObject, locToString } from './helpers';
6
+ import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createCantMigrateUnsafeProp, createGuidance, createHelpers, findUNSAFEProp, getMigrationMapObject, locToString } from './helpers';
7
7
  import { isSize } from './migration-map-temp';
8
8
  export var createChecks = function createChecks(context) {
9
9
  //create global variables to be shared by the checks
@@ -134,25 +134,36 @@ export var createChecks = function createChecks(context) {
134
134
  if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
135
135
  return moduleSource.startsWith(val);
136
136
  }) && node.specifiers.length) {
137
- createCantMigrateReExportError(node, moduleSource, node.specifiers[0].exported.name, errorsManual);
138
- guidance[locToString(node)] = createGuidance(moduleSource);
137
+ var _iterator4 = _createForOfIteratorHelper(node.specifiers),
138
+ _step4;
139
+ try {
140
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
141
+ var spec = _step4.value;
142
+ createCantMigrateReExportError(spec, moduleSource, spec.exported.name, errorsManual);
143
+ guidance[locToString(spec)] = createGuidance(moduleSource);
144
+ }
145
+ } catch (err) {
146
+ _iterator4.e(err);
147
+ } finally {
148
+ _iterator4.f();
149
+ }
139
150
  }
140
151
  } else if (node.declaration && isNodeOfType(node.declaration, 'VariableDeclaration')) {
141
152
  // export const Icon = AddIcon;
142
- var _iterator4 = _createForOfIteratorHelper(node.declaration.declarations),
143
- _step4;
153
+ var _iterator5 = _createForOfIteratorHelper(node.declaration.declarations),
154
+ _step5;
144
155
  try {
145
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
146
- var decl = _step4.value;
156
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
157
+ var decl = _step5.value;
147
158
  if (isNodeOfType(decl, 'VariableDeclarator') && 'init' in decl && decl.init && isNodeOfType(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
148
159
  createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
149
- guidance[locToString(node)] = createGuidance(createGuidance(legacyIconImports[decl.init.name].packageName));
160
+ guidance[locToString(node)] = createGuidance(legacyIconImports[decl.init.name].packageName);
150
161
  }
151
162
  }
152
163
  } catch (err) {
153
- _iterator4.e(err);
164
+ _iterator5.e(err);
154
165
  } finally {
155
- _iterator4.f();
166
+ _iterator5.f();
156
167
  }
157
168
  } else if (!node.source && node.specifiers && node.specifiers.length > 0) {
158
169
  /**
@@ -161,25 +172,25 @@ export var createChecks = function createChecks(context) {
161
172
  * const crossIcon = LegacyIcon2;
162
173
  * export { AddIcon, CrossIcon as default }
163
174
  */
164
- var _iterator5 = _createForOfIteratorHelper(node.specifiers),
165
- _step5;
175
+ var _iterator6 = _createForOfIteratorHelper(node.specifiers),
176
+ _step6;
166
177
  try {
167
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
168
- var spec = _step5.value;
169
- if (spec.local.name in legacyIconImports) {
178
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
179
+ var _spec2 = _step6.value;
180
+ if (_spec2.local.name in legacyIconImports) {
170
181
  //update legacy imports to be exported
171
- legacyIconImports[spec.local.name] = {
172
- packageName: legacyIconImports[spec.local.name].packageName,
182
+ legacyIconImports[_spec2.local.name] = {
183
+ packageName: legacyIconImports[_spec2.local.name].packageName,
173
184
  exported: true
174
185
  };
175
- createCantMigrateReExportError(spec, legacyIconImports[spec.local.name].packageName, spec.exported.name, errorsManual);
176
- guidance[locToString(spec)] = createGuidance(legacyIconImports[spec.local.name].packageName);
186
+ createCantMigrateReExportError(_spec2, legacyIconImports[_spec2.local.name].packageName, _spec2.exported.name, errorsManual);
187
+ guidance[locToString(_spec2)] = createGuidance(legacyIconImports[_spec2.local.name].packageName);
177
188
  }
178
189
  }
179
190
  } catch (err) {
180
- _iterator5.e(err);
191
+ _iterator6.e(err);
181
192
  } finally {
182
- _iterator5.f();
193
+ _iterator6.f();
183
194
  }
184
195
  }
185
196
  };
@@ -226,18 +237,17 @@ export var createChecks = function createChecks(context) {
226
237
  UNSAFE_propName = result.UNSAFE_propName;
227
238
  }
228
239
  if (newIcon && isInNewButton && isNewIconMigratable && UNSAFE_size !== 'large' && UNSAFE_size !== 'xlarge') {
229
- var iconKey = getIconKey(legacyIconImports[node.name].packageName);
230
- createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, newIcon, iconKey, errorsAuto);
231
- guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, 'medium');
240
+ createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
241
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
232
242
  } else if ((!newIcon || !isNewIconMigratable) && !UNSAFE_size) {
233
243
  createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
234
- guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
244
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
235
245
  } else if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && UNSAFE_propName) {
236
246
  createCantMigrateUnsafeProp(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[node.name].packageName, node.name, errorsManual);
237
- guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, UNSAFE_size);
247
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton, UNSAFE_size);
238
248
  } else if (!isInNewButton) {
239
249
  createCantMigrateFunctionUnknownError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
240
- guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
250
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
241
251
  }
242
252
  }
243
253
  };
@@ -280,11 +290,11 @@ export var createChecks = function createChecks(context) {
280
290
  var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
281
291
  var hasSpread = false;
282
292
  var hasPrimaryColorProp = false;
283
- var _iterator6 = _createForOfIteratorHelper(node.openingElement.attributes),
284
- _step6;
293
+ var _iterator7 = _createForOfIteratorHelper(node.openingElement.attributes),
294
+ _step7;
285
295
  try {
286
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
287
- var attr = _step6.value;
296
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
297
+ var attr = _step7.value;
288
298
  // Detect spread props
289
299
  if (isNodeOfType(attr, 'JSXSpreadAttribute')) {
290
300
  // In case there are more spread props
@@ -317,9 +327,9 @@ export var createChecks = function createChecks(context) {
317
327
  }
318
328
  }
319
329
  } catch (err) {
320
- _iterator6.e(err);
330
+ _iterator7.e(err);
321
331
  } finally {
322
- _iterator6.f();
332
+ _iterator7.f();
323
333
  }
324
334
  var hasManualMigration = false;
325
335
  if (primaryColor && !canMigrateColor(primaryColor) || hasPrimaryColorProp && !primaryColor) {
@@ -333,7 +343,6 @@ export var createChecks = function createChecks(context) {
333
343
  createCantMigrateSizeUnknown(node, errorsManual, legacyIconImports[name].packageName, name);
334
344
  hasManualMigration = true;
335
345
  }
336
- guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, size ? size : undefined);
337
346
  // Check for unsafe size
338
347
  if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && (UNSAFE_propName === 'UNSAFE_iconAfter_size' || UNSAFE_propName === 'UNSAFE_iconBefore_size' || UNSAFE_propName === 'UNSAFE_size')) {
339
348
  createCantMigrateUnsafeProp(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[name].packageName, name, errorsManual);
@@ -355,14 +364,14 @@ export var createChecks = function createChecks(context) {
355
364
  hasManualMigration = true;
356
365
  }
357
366
  var migrationMapObject = getMigrationMapObject(legacyIconImports[name].packageName);
358
- var iconKey = getIconKey(legacyIconImports[name].packageName);
359
367
  var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
360
368
  var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium']);
361
369
  if (!hasManualMigration && newIcon && isNewIconMigratable) {
362
- createAutoMigrationError(node, legacyIconImports[name].packageName, name, newIcon, iconKey, errorsAuto);
370
+ createAutoMigrationError(node, legacyIconImports[name].packageName, name, errorsAuto);
363
371
  } else if ((!newIcon || !isNewIconMigratable) && size) {
364
- createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual);
372
+ createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
365
373
  }
374
+ guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, insideNewButton, size && isSize(size) ? size : undefined);
366
375
  }
367
376
  };
368
377
 
@@ -372,20 +381,20 @@ export var createChecks = function createChecks(context) {
372
381
  */
373
382
  var checkCallExpression = function checkCallExpression(node) {
374
383
  if ('arguments' in node && node.arguments.length) {
375
- var _iterator7 = _createForOfIteratorHelper(node.arguments),
376
- _step7;
384
+ var _iterator8 = _createForOfIteratorHelper(node.arguments),
385
+ _step8;
377
386
  try {
378
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
379
- var arg = _step7.value;
387
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
388
+ var arg = _step8.value;
380
389
  if (isNodeOfType(arg, 'Identifier') && arg.name in legacyIconImports && legacyIconImports[arg.name].packageName) {
381
390
  createCantMigrateFunctionUnknownError(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
382
391
  guidance[locToString(node)] = createGuidance(legacyIconImports[arg.name].packageName);
383
392
  }
384
393
  }
385
394
  } catch (err) {
386
- _iterator7.e(err);
395
+ _iterator8.e(err);
387
396
  } finally {
388
- _iterator7.f();
397
+ _iterator8.f();
389
398
  }
390
399
  }
391
400
  };
@@ -401,36 +410,28 @@ export var createChecks = function createChecks(context) {
401
410
  errorList = _Object$entries$_i[1];
402
411
  var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
403
412
  if (node) {
413
+ var guidanceMessage = _key in guidance ? guidance[_key] : '';
404
414
  context.report({
405
415
  node: node,
406
416
  messageId: 'noLegacyIconsManualMigration',
407
417
  data: {
408
418
  iconName: errorList.iconName,
409
419
  importSource: errorList.importSource,
410
- quietModeGuidance: isQuietMode ? 'For more information see the below errors:' : ''
420
+ guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
411
421
  }
412
422
  });
413
423
  if (!isQuietMode) {
414
- var _iterator8 = _createForOfIteratorHelper(errorList.errors),
415
- _step8;
424
+ var _iterator9 = _createForOfIteratorHelper(errorList.errors),
425
+ _step9;
416
426
  try {
417
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
418
- var error = _step8.value;
427
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
428
+ var error = _step9.value;
419
429
  context.report(error);
420
430
  }
421
431
  } catch (err) {
422
- _iterator8.e(err);
432
+ _iterator9.e(err);
423
433
  } finally {
424
- _iterator8.f();
425
- }
426
- if (_key in guidance) {
427
- context.report({
428
- node: node,
429
- messageId: 'guidance',
430
- data: {
431
- guidance: guidance[_key]
432
- }
433
- });
434
+ _iterator9.f();
434
435
  }
435
436
  }
436
437
  }
@@ -449,16 +450,11 @@ export var createChecks = function createChecks(context) {
449
450
  }
450
451
  var _node = 'node' in _error ? _error.node : null;
451
452
  if (_node) {
452
- context.report(_error);
453
- if (_key2 in guidance && !isQuietMode) {
454
- context.report({
455
- node: _node,
456
- messageId: 'guidance',
457
- data: {
458
- guidance: guidance[_key2]
459
- }
460
- });
453
+ var _guidanceMessage = _key2 in guidance ? guidance[_key2] : '';
454
+ if ('data' in _error && _error.data) {
455
+ _error.data.guidance = _guidanceMessage;
461
456
  }
457
+ context.report(_error);
462
458
  }
463
459
  }
464
460
  }
@@ -20,7 +20,7 @@ export var getMigrationMapObject = function getMigrationMapObject(iconPackage) {
20
20
  * @param iconPackage The name of the legacy icon package
21
21
  * @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
22
22
  */
23
- export var getIconKey = function getIconKey(iconPackage) {
23
+ var getIconKey = function getIconKey(iconPackage) {
24
24
  var key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
25
25
  return key;
26
26
  };
@@ -35,39 +35,48 @@ export var canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBase
35
35
  /**
36
36
  * Creates the written guidance for migrating a legacy icon to a new icon
37
37
  */
38
- export var createGuidance = function createGuidance(iconPackage, size) {
38
+ export var createGuidance = function createGuidance(iconPackage) {
39
+ var insideNewButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
40
+ var size = arguments.length > 2 ? arguments[2] : undefined;
39
41
  var migrationMapObject = getMigrationMapObject(iconPackage);
40
42
  if (migrationMapObject) {
41
43
  var newIcon = migrationMapObject.newIcon;
42
44
  if (!newIcon) {
43
45
  return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
44
46
  }
47
+ var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
48
+ var guidance = '';
45
49
  if (size) {
46
- var guidance = "Fix: Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
47
- if (migrationMapObject.sizeGuidance[size] in outcomeDescriptionMap) {
48
- guidance += " Please: ".concat(outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]], "\n");
50
+ if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
51
+ guidance += "Fix: Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
49
52
  } else {
50
- guidance += ' No migration advice given.\n';
53
+ guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
51
54
  }
52
- return guidance;
55
+ guidance += "".concat(migrationMapObject.sizeGuidance[size] in outcomeDescriptionMap ? " Please: ".concat(outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
53
56
  } else {
54
- var _guidance = "Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
57
+ guidance = "Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
55
58
  for (var _i = 0, _Object$entries = Object.entries(migrationMapObject.sizeGuidance); _i < _Object$entries.length; _i++) {
56
59
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
57
60
  _size = _Object$entries$_i[0],
58
61
  value = _Object$entries$_i[1];
59
- _guidance += "\t- ".concat(_size, ": ");
62
+ guidance += "\t- ".concat(_size, ": ");
60
63
  if (!(value in outcomeDescriptionMap)) {
61
- _guidance += 'No migration advice given.\n';
64
+ guidance += 'No migration advice given.\n';
62
65
  } else {
63
- _guidance += "".concat(outcomeDescriptionMap[value], "\n");
66
+ guidance += "".concat(outcomeDescriptionMap[value], ".\n");
64
67
  }
65
- _guidance;
66
68
  }
67
- return _guidance;
68
69
  }
70
+ if (insideNewButton) {
71
+ guidance += buttonGuidanceStr;
72
+ } else if (size && size === 'medium') {
73
+ guidance += "Setting the spacing property to 'spacious' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
74
+ } else if (size) {
75
+ guidance += "In the new icon, please use spacing='none'.\n";
76
+ }
77
+ return guidance;
69
78
  } else {
70
- return 'Migration suggestions not found\n';
79
+ return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
71
80
  }
72
81
  };
73
82
 
@@ -145,13 +154,14 @@ export var createCantMigrateUnsafeProp = function createCantMigrateUnsafeProp(no
145
154
  };
146
155
  pushManualError(locToString(node), errors, myError, packageName, iconName);
147
156
  };
148
- export var createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors) {
157
+ export var createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
149
158
  var myError = {
150
159
  node: node,
151
160
  messageId: 'cantFindSuitableReplacement',
152
161
  data: {
153
162
  importSource: importSource,
154
- iconName: iconName
163
+ iconName: iconName,
164
+ sizeGuidance: sizeIssue ? ' at the current size' : ''
155
165
  }
156
166
  };
157
167
  pushManualError(locToString(node), errors, myError, importSource, iconName);
@@ -194,18 +204,13 @@ export var createCantMigrateSizeUnknown = function createCantMigrateSizeUnknown(
194
204
  };
195
205
  pushManualError(locToString(node), errors, myError, importSource, iconName);
196
206
  };
197
- export var createAutoMigrationError = function createAutoMigrationError(node, importSource, iconName, newIcon, oldIconName, errors) {
198
- var migrationKey = newIcon.name === oldIconName ? newIcon.name : "".concat(newIcon.name, "--").concat(oldIconName);
199
- var newMigrationIconPackage = "@atlaskit/".concat(newIcon.library, "/").concat(newIcon.type, "/migration/").concat(migrationKey);
207
+ export var createAutoMigrationError = function createAutoMigrationError(node, importSource, iconName, errors) {
200
208
  var myError = {
201
209
  node: node,
202
210
  messageId: 'noLegacyIconsAutoMigration',
203
211
  data: {
204
212
  importSource: importSource,
205
- iconName: iconName,
206
- newIcon: newIcon.name,
207
- //TODO: provide size guidance
208
- newPackage: newMigrationIconPackage
213
+ iconName: iconName
209
214
  }
210
215
  };
211
216
  errors[locToString(node)] = myError;
@@ -27,17 +27,16 @@ var rule = createLintRule({
27
27
  additionalProperties: false
28
28
  }],
29
29
  messages: {
30
- noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible to '{{newIcon}}' from '{{newPackage}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'",
31
- noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.{{quietModeGuidance}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.",
32
- cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}' at the size listed. Please manually migrate this icon.",
30
+ noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'",
31
+ noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.",
32
+ cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}'{{sizeGuidance}}. Please manually migrate this icon.",
33
33
  cantMigrateReExport: "'{{exportName}}' is a re-export of icon from '{{packageName}}' and cannot be automatically migrated. Please utilize the export from icons directly.",
34
34
  cantMigrateColor: "Primary Color prop has {{colorValue}} which cannot be automatically migrated to color prop in the new Icon API. Please use either an appropriate color.icon, color.link token, or currentColor (as a last resort).",
35
35
  cantMigrateSpreadProps: "This usage of Icon uses spread props in a way that can't be automatically migrated. Please explicitly define the following props after spread: '{{missingProps}}' ",
36
36
  cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
37
37
  cantMigrateFunctionUnknown: "'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.",
38
38
  cantMigrateIdentifier: "This icon is passed to other components via a map or array, in a way that can't be automatically migrated. Please manually migrate wherever this expression is used and use the icon components directly.",
39
- cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon.",
40
- guidance: "Guidance:\n'{{guidance}}'"
39
+ cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon."
41
40
  }
42
41
  },
43
42
  create: function create(context) {
@@ -33,12 +33,6 @@ export declare const getMigrationMapObject: (iconPackage: string) => {
33
33
  library: string;
34
34
  } | undefined;
35
35
  } | null;
36
- /**
37
- * Returns the key of a legacy icon
38
- * @param iconPackage The name of the legacy icon package
39
- * @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
40
- */
41
- export declare const getIconKey: (iconPackage: string) => string;
42
36
  /**
43
37
  * Checks if a new icon can be auto-migrated based on guidance from the migration map
44
38
  */
@@ -46,7 +40,7 @@ export declare const canAutoMigrateNewIconBasedOnSize: (guidance?: string) => bo
46
40
  /**
47
41
  * Creates the written guidance for migrating a legacy icon to a new icon
48
42
  */
49
- export declare const createGuidance: (iconPackage: string, size?: Size) => string;
43
+ export declare const createGuidance: (iconPackage: string, insideNewButton?: boolean, size?: Size) => string;
50
44
  /**
51
45
  * Checks if the color can be migrated
52
46
  * @param color String representing the color to check
@@ -61,16 +55,12 @@ export declare const findUNSAFEProp: (iconAttr: JSXAttribute, button: JSXOpening
61
55
  UNSAFE_propName: "UNSAFE_iconAfter_size" | "UNSAFE_iconBefore_size" | "UNSAFE_size" | null;
62
56
  };
63
57
  export declare const createCantMigrateUnsafeProp: (node: Node, propName: string, value: string, packageName: string, iconName: string, errors: errorsListManual) => void;
64
- export declare const createCantFindSuitableReplacementError: (node: Node, importSource: string, iconName: string, errors: errorsListManual) => void;
58
+ export declare const createCantFindSuitableReplacementError: (node: Node, importSource: string, iconName: string, errors: errorsListManual, sizeIssue?: boolean) => void;
65
59
  export declare const createCantMigrateFunctionUnknownError: (node: Node, importSource: string, iconName: string, errors: errorsListManual) => void;
66
60
  export declare const createCantMigrateColorError: (node: Node, colorValue: string, errors: errorsListManual, importSource: string, iconName: string) => void;
67
61
  export declare const createCantMigrateSpreadPropsError: (node: Node, missingProps: string[], errors: errorsListManual, importSource: string, iconName: string) => void;
68
62
  export declare const createCantMigrateSizeUnknown: (node: Node, errors: errorsListManual, importSource: string, iconName: string) => void;
69
- export declare const createAutoMigrationError: (node: Node, importSource: string, iconName: string, newIcon: {
70
- name: string;
71
- type: string;
72
- library: string;
73
- }, oldIconName: string, errors: errorsListAuto) => void;
63
+ export declare const createAutoMigrationError: (node: Node, importSource: string, iconName: string, errors: errorsListAuto) => void;
74
64
  export declare const getLiteralStringValue: (value: any) => string | undefined;
75
65
  export declare const createHelpers: (context: Rule.RuleContext) => {
76
66
  /**
@@ -33,12 +33,6 @@ export declare const getMigrationMapObject: (iconPackage: string) => {
33
33
  library: string;
34
34
  } | undefined;
35
35
  } | null;
36
- /**
37
- * Returns the key of a legacy icon
38
- * @param iconPackage The name of the legacy icon package
39
- * @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
40
- */
41
- export declare const getIconKey: (iconPackage: string) => string;
42
36
  /**
43
37
  * Checks if a new icon can be auto-migrated based on guidance from the migration map
44
38
  */
@@ -46,7 +40,7 @@ export declare const canAutoMigrateNewIconBasedOnSize: (guidance?: string) => bo
46
40
  /**
47
41
  * Creates the written guidance for migrating a legacy icon to a new icon
48
42
  */
49
- export declare const createGuidance: (iconPackage: string, size?: Size) => string;
43
+ export declare const createGuidance: (iconPackage: string, insideNewButton?: boolean, size?: Size) => string;
50
44
  /**
51
45
  * Checks if the color can be migrated
52
46
  * @param color String representing the color to check
@@ -61,16 +55,12 @@ export declare const findUNSAFEProp: (iconAttr: JSXAttribute, button: JSXOpening
61
55
  UNSAFE_propName: "UNSAFE_iconAfter_size" | "UNSAFE_iconBefore_size" | "UNSAFE_size" | null;
62
56
  };
63
57
  export declare const createCantMigrateUnsafeProp: (node: Node, propName: string, value: string, packageName: string, iconName: string, errors: errorsListManual) => void;
64
- export declare const createCantFindSuitableReplacementError: (node: Node, importSource: string, iconName: string, errors: errorsListManual) => void;
58
+ export declare const createCantFindSuitableReplacementError: (node: Node, importSource: string, iconName: string, errors: errorsListManual, sizeIssue?: boolean) => void;
65
59
  export declare const createCantMigrateFunctionUnknownError: (node: Node, importSource: string, iconName: string, errors: errorsListManual) => void;
66
60
  export declare const createCantMigrateColorError: (node: Node, colorValue: string, errors: errorsListManual, importSource: string, iconName: string) => void;
67
61
  export declare const createCantMigrateSpreadPropsError: (node: Node, missingProps: string[], errors: errorsListManual, importSource: string, iconName: string) => void;
68
62
  export declare const createCantMigrateSizeUnknown: (node: Node, errors: errorsListManual, importSource: string, iconName: string) => void;
69
- export declare const createAutoMigrationError: (node: Node, importSource: string, iconName: string, newIcon: {
70
- name: string;
71
- type: string;
72
- library: string;
73
- }, oldIconName: string, errors: errorsListAuto) => void;
63
+ export declare const createAutoMigrationError: (node: Node, importSource: string, iconName: string, errors: errorsListAuto) => void;
74
64
  export declare const getLiteralStringValue: (value: any) => string | undefined;
75
65
  export declare const createHelpers: (context: Rule.RuleContext) => {
76
66
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "10.10.0",
4
+ "version": "10.10.1",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -67,7 +67,7 @@
67
67
  "jscodeshift": "^0.13.0",
68
68
  "outdent": "^0.5.0",
69
69
  "react": "^16.8.0",
70
- "ts-jest": "26.5.6",
70
+ "ts-jest": "29.1.2",
71
71
  "ts-node": "^10.9.1",
72
72
  "tsconfig-paths": "^4.2.0",
73
73
  "typescript": "~5.4.2"