@atlaskit/eslint-plugin-design-system 10.9.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 (101) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/presets/all.codegen.js +2 -1
  4. package/dist/cjs/rules/ensure-design-token-usage/index.js +199 -227
  5. package/dist/cjs/rules/index.codegen.js +3 -1
  6. package/dist/cjs/rules/no-custom-icons/checks/has-prop.js +12 -0
  7. package/dist/cjs/rules/no-custom-icons/checks/is-from-import-source.js +42 -0
  8. package/dist/cjs/rules/no-custom-icons/checks/is-imported-jsx-element.js +10 -0
  9. package/dist/cjs/rules/no-custom-icons/index.js +67 -0
  10. package/dist/cjs/rules/no-legacy-icons/checks.js +63 -67
  11. package/dist/cjs/rules/no-legacy-icons/helpers.js +29 -24
  12. package/dist/cjs/rules/no-legacy-icons/index.js +15 -88
  13. package/dist/cjs/rules/use-tokens-typography/index.js +4 -8
  14. package/dist/cjs/rules/utils/error-boundary.js +58 -11
  15. package/dist/es2019/presets/all.codegen.js +2 -1
  16. package/dist/es2019/rules/ensure-design-token-usage/index.js +16 -30
  17. package/dist/es2019/rules/index.codegen.js +3 -1
  18. package/dist/es2019/rules/no-custom-icons/checks/has-prop.js +4 -0
  19. package/dist/es2019/rules/no-custom-icons/checks/is-from-import-source.js +23 -0
  20. package/dist/es2019/rules/no-custom-icons/checks/is-imported-jsx-element.js +4 -0
  21. package/dist/es2019/rules/no-custom-icons/index.js +61 -0
  22. package/dist/es2019/rules/no-legacy-icons/checks.js +20 -33
  23. package/dist/es2019/rules/no-legacy-icons/helpers.js +24 -21
  24. package/dist/es2019/rules/no-legacy-icons/index.js +15 -70
  25. package/dist/es2019/rules/use-tokens-typography/index.js +3 -7
  26. package/dist/es2019/rules/utils/error-boundary.js +55 -11
  27. package/dist/esm/presets/all.codegen.js +2 -1
  28. package/dist/esm/rules/ensure-design-token-usage/index.js +199 -227
  29. package/dist/esm/rules/index.codegen.js +3 -1
  30. package/dist/esm/rules/no-custom-icons/checks/has-prop.js +6 -0
  31. package/dist/esm/rules/no-custom-icons/checks/is-from-import-source.js +36 -0
  32. package/dist/esm/rules/no-custom-icons/checks/is-imported-jsx-element.js +4 -0
  33. package/dist/esm/rules/no-custom-icons/index.js +61 -0
  34. package/dist/esm/rules/no-legacy-icons/checks.js +64 -68
  35. package/dist/esm/rules/no-legacy-icons/helpers.js +28 -23
  36. package/dist/esm/rules/no-legacy-icons/index.js +15 -88
  37. package/dist/esm/rules/use-tokens-typography/index.js +4 -8
  38. package/dist/esm/rules/utils/error-boundary.js +56 -10
  39. package/dist/types/index.codegen.d.ts +1 -0
  40. package/dist/types/presets/all.codegen.d.ts +2 -1
  41. package/dist/types/rules/index.codegen.d.ts +1 -0
  42. package/dist/types/rules/no-custom-icons/checks/has-prop.d.ts +2 -0
  43. package/dist/types/rules/no-custom-icons/checks/is-from-import-source.d.ts +8 -0
  44. package/dist/types/rules/no-custom-icons/checks/is-imported-jsx-element.d.ts +8 -0
  45. package/dist/types/rules/no-custom-icons/index.d.ts +3 -0
  46. package/dist/types/rules/no-legacy-icons/helpers.d.ts +3 -13
  47. package/dist/types/rules/no-legacy-icons/index.d.ts +1 -2
  48. package/dist/types/rules/utils/error-boundary.d.ts +8 -5
  49. package/dist/types-ts4.5/index.codegen.d.ts +1 -0
  50. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  51. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  52. package/dist/types-ts4.5/rules/no-custom-icons/checks/has-prop.d.ts +2 -0
  53. package/dist/types-ts4.5/rules/no-custom-icons/checks/is-from-import-source.d.ts +8 -0
  54. package/dist/types-ts4.5/rules/no-custom-icons/checks/is-imported-jsx-element.d.ts +8 -0
  55. package/dist/types-ts4.5/rules/no-custom-icons/index.d.ts +3 -0
  56. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +3 -13
  57. package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +1 -2
  58. package/dist/types-ts4.5/rules/utils/error-boundary.d.ts +8 -5
  59. package/package.json +2 -2
  60. package/constellation/consistent-css-prop-usage/usage.mdx +0 -210
  61. package/constellation/ensure-design-token-usage/usage.mdx +0 -77
  62. package/constellation/ensure-design-token-usage-preview/usage.mdx +0 -6
  63. package/constellation/icon-label/usage.mdx +0 -41
  64. package/constellation/index/props.mdx +0 -30
  65. package/constellation/index/usage.mdx +0 -56
  66. package/constellation/no-banned-imports/usage.mdx +0 -19
  67. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -71
  68. package/constellation/no-deprecated-apis/usage.mdx +0 -82
  69. package/constellation/no-deprecated-design-token-usage/usage.mdx +0 -30
  70. package/constellation/no-deprecated-imports/usage.mdx +0 -66
  71. package/constellation/no-direct-use-of-web-platform-drag-and-drop/usage.mdx +0 -149
  72. package/constellation/no-empty-styled-expression/usage.mdx +0 -82
  73. package/constellation/no-exported-css/usage.mdx +0 -55
  74. package/constellation/no-exported-keyframes/usage.mdx +0 -55
  75. package/constellation/no-html-anchor/usage.mdx +0 -46
  76. package/constellation/no-html-button/usage.mdx +0 -52
  77. package/constellation/no-invalid-css-map/usage.mdx +0 -210
  78. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -80
  79. package/constellation/no-legacy-icons/usage.mdx +0 -42
  80. package/constellation/no-margin/usage.mdx +0 -21
  81. package/constellation/no-nested-styles/usage.mdx +0 -47
  82. package/constellation/no-physical-properties/usage.mdx +0 -53
  83. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -135
  84. package/constellation/no-unsafe-design-token-usage/usage.mdx +0 -50
  85. package/constellation/no-unsafe-style-overrides/usage.mdx +0 -52
  86. package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +0 -23
  87. package/constellation/prefer-primitives/usage.mdx +0 -32
  88. package/constellation/use-button-group-label/usage.mdx +0 -60
  89. package/constellation/use-drawer-label/usage.mdx +0 -55
  90. package/constellation/use-heading/usage.mdx +0 -31
  91. package/constellation/use-heading-level-in-spotlight-card/usage.mdx +0 -21
  92. package/constellation/use-href-in-link-item/usage.mdx +0 -19
  93. package/constellation/use-latest-xcss-syntax/usage.mdx +0 -33
  94. package/constellation/use-latest-xcss-syntax-typography/usage.mdx +0 -34
  95. package/constellation/use-menu-section-title/usage.mdx +0 -55
  96. package/constellation/use-popup-label/usage.mdx +0 -56
  97. package/constellation/use-primitives/usage.mdx +0 -78
  98. package/constellation/use-primitives-text/usage.mdx +0 -35
  99. package/constellation/use-tokens-space/usage.mdx +0 -34
  100. package/constellation/use-tokens-typography/usage.mdx +0 -55
  101. package/constellation/use-visually-hidden/usage.mdx +0 -35
@@ -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) {
@@ -56,77 +55,23 @@ const rule = createLintRule({
56
55
  checkCallExpression,
57
56
  throwErrors
58
57
  } = createChecks(context);
59
- return {
58
+ return errorBoundary({
60
59
  // Track imports of relevant components
61
- ImportDeclaration(node) {
62
- errorBoundary(() => checkImportDeclarations(node), {
63
- config: {
64
- failSilently
65
- }
66
- });
67
- },
60
+ ImportDeclaration: checkImportDeclarations,
68
61
  // Keep track of the relevant variable declarations and renames
69
- VariableDeclaration(node) {
70
- errorBoundary(() => checkVariableDeclarations(node), {
71
- config: {
72
- failSilently
73
- }
74
- });
75
- },
62
+ VariableDeclaration: checkVariableDeclarations,
76
63
  // Case: default re-exports. Can't be auto-migrated
77
- ExportDefaultDeclaration(node) {
78
- errorBoundary(() => checkExportDefaultDeclaration(node), {
79
- config: {
80
- failSilently
81
- }
82
- });
83
- },
84
- ExportNamedDeclaration(node) {
85
- errorBoundary(() => checkExportNamedVariables(node), {
86
- config: {
87
- failSilently
88
- }
89
- });
90
- },
64
+ ExportDefaultDeclaration: checkExportDefaultDeclaration,
65
+ ExportNamedDeclaration: checkExportNamedVariables,
91
66
  // Legacy icons found in arrays/objects
92
- 'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ': node => {
93
- errorBoundary(() => checkArrayOrMap(node), {
94
- config: {
95
- failSilently
96
- }
97
- });
98
- },
67
+ 'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ': checkArrayOrMap,
99
68
  // Legacy icons passed in via props, as JSX identifier (i.e. icon={AddIcon})
100
- 'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier': node => {
101
- errorBoundary(() => checkIconAsProp(node), {
102
- config: {
103
- failSilently
104
- }
105
- });
106
- },
107
- JSXElement(node) {
108
- errorBoundary(() => checkJSXElement(node), {
109
- config: {
110
- failSilently
111
- }
112
- });
113
- },
69
+ 'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier': checkIconAsProp,
70
+ JSXElement: checkJSXElement,
114
71
  // Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
115
- CallExpression: node => {
116
- errorBoundary(() => checkCallExpression(node), {
117
- config: {
118
- failSilently
119
- }
120
- });
121
- },
122
- 'Program:exit': () => {
123
- errorBoundary(() => throwErrors(), {
124
- config: {
125
- failSilently
126
- }
127
- });
128
- }
129
- };
72
+ CallExpression: checkCallExpression,
73
+ 'Program:exit': throwErrors
74
+ }, failSilently);
130
75
  }
131
76
  });
132
77
  export default rule;
@@ -6,14 +6,10 @@ const create = context => {
6
6
  const config = getConfig(context.options[0]);
7
7
  return {
8
8
  // const styles = css({ fontSize: '14px, ... }), styled.div({ fontSize: 14, ... })
9
- ObjectExpression: node => errorBoundary(() => {
10
- return StyleObject.lint(node, {
11
- context,
12
- config
13
- });
14
- }, {
9
+ ObjectExpression: errorBoundary(node => StyleObject.lint(node, {
10
+ context,
15
11
  config
16
- })
12
+ }), config)
17
13
  };
18
14
  };
19
15
  const rule = createLintRule({
@@ -1,3 +1,9 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+
3
+ // Need to intersect type RuleListener with a generic function to allow use of Parameters<...> to be used
4
+
5
+ // Allow config to be to be easily passed from rules
6
+
1
7
  /**
2
8
  * ESLint rules should NEVER throw exceptions, because that breaks the VSCode ESLint server
3
9
  * (and probably the IntelliJ one too), which causes linting to fail in a file.
@@ -5,15 +11,53 @@
5
11
  * It also breaks CI, which was the reason this error boundary was added. It's a final
6
12
  * catch all.
7
13
  */
8
- export const errorBoundary = (func, {
9
- config
10
- }) => {
11
- try {
12
- func();
13
- } catch (err) {
14
- if (!config.failSilently) {
15
- // eslint-disable-next-line no-console
16
- console.warn(err);
17
- }
14
+ export function errorBoundary(ruleOrRules, config = false) {
15
+ const failSilently = failSilentlyFromConfig(config);
16
+ if (isSingleRuleListener(ruleOrRules)) {
17
+ return wrapSingleRuleListener(ruleOrRules, failSilently);
18
+ }
19
+ return wrapRuleListener(ruleOrRules, failSilently);
20
+ }
21
+ function isSingleRuleListener(rule) {
22
+ return typeof rule === 'function';
23
+ }
24
+ function failSilentlyFromConfig(c) {
25
+ switch (typeof c) {
26
+ case 'undefined':
27
+ return false;
28
+ case 'boolean':
29
+ return c;
30
+ case 'object':
31
+ if ('failSilently' in c) {
32
+ var _c$failSilently;
33
+ return (_c$failSilently = c.failSilently) !== null && _c$failSilently !== void 0 ? _c$failSilently : false;
34
+ } else if ('config' in c) {
35
+ var _c$config$failSilentl;
36
+ return (_c$config$failSilentl = c.config.failSilently) !== null && _c$config$failSilentl !== void 0 ? _c$config$failSilentl : false;
37
+ }
38
+ return false;
39
+ default:
40
+ throw new Error('Invalid config');
18
41
  }
19
- };
42
+ }
43
+ function wrapSingleRuleListener(rule, failSilently) {
44
+ return (...args) => {
45
+ try {
46
+ rule(...args);
47
+ } catch (err) {
48
+ if (!failSilently) {
49
+ // eslint-disable-next-line no-console
50
+ console.warn(err);
51
+ }
52
+ }
53
+ };
54
+ }
55
+ function wrapRuleListener(ruleListener, failSilently) {
56
+ return Object.entries(ruleListener).reduce((wrappedRuleListener, e) => {
57
+ const ruleName = e[0];
58
+ const rule = e[1];
59
+ return Object.assign(wrappedRuleListener, {
60
+ [ruleName]: wrapSingleRuleListener(rule, failSilently)
61
+ });
62
+ }, {});
63
+ }
@@ -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::9bb5329713677543f16019954484ae2f>>
3
+ * @codegen <<SignedSource::ab43b6e1a867d07b9a27eae78d48834a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -12,6 +12,7 @@ export default {
12
12
  '@atlaskit/design-system/icon-label': 'warn',
13
13
  '@atlaskit/design-system/no-banned-imports': 'error',
14
14
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
15
+ '@atlaskit/design-system/no-custom-icons': 'warn',
15
16
  '@atlaskit/design-system/no-deprecated-apis': 'error',
16
17
  '@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
17
18
  '@atlaskit/design-system/no-deprecated-imports': 'error',