@atlaskit/eslint-plugin-design-system 13.20.1 → 13.21.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 (66) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/common/token-maps.partial.js +2 -2
  4. package/dist/cjs/index.codegen.js +1 -1
  5. package/dist/cjs/presets/all-flat.codegen.js +6 -3
  6. package/dist/cjs/presets/all.codegen.js +6 -3
  7. package/dist/cjs/presets/recommended-flat.codegen.js +5 -3
  8. package/dist/cjs/presets/recommended.codegen.js +5 -3
  9. package/dist/cjs/rules/ensure-design-token-usage/shape.js +5 -9
  10. package/dist/cjs/rules/index.codegen.js +3 -1
  11. package/dist/cjs/rules/use-tokens-shape/index.js +54 -0
  12. package/dist/cjs/rules/use-tokens-shape/transformers/index.js +128 -0
  13. package/dist/cjs/rules/use-tokens-shape/transformers/style-map.js +49 -0
  14. package/dist/cjs/rules/use-tokens-shape/transformers/supported.js +15 -0
  15. package/dist/cjs/rules/utils/is-node.js +2 -2
  16. package/dist/es2019/common/token-maps.partial.js +2 -2
  17. package/dist/es2019/index.codegen.js +1 -1
  18. package/dist/es2019/presets/all-flat.codegen.js +5 -3
  19. package/dist/es2019/presets/all.codegen.js +5 -3
  20. package/dist/es2019/presets/recommended-flat.codegen.js +4 -3
  21. package/dist/es2019/presets/recommended.codegen.js +4 -3
  22. package/dist/es2019/rules/ensure-design-token-usage/shape.js +5 -7
  23. package/dist/es2019/rules/index.codegen.js +4 -1
  24. package/dist/es2019/rules/use-tokens-shape/index.js +38 -0
  25. package/dist/es2019/rules/use-tokens-shape/transformers/index.js +120 -0
  26. package/dist/es2019/rules/use-tokens-shape/transformers/style-map.js +43 -0
  27. package/dist/es2019/rules/use-tokens-shape/transformers/supported.js +9 -0
  28. package/dist/es2019/rules/utils/is-node.js +2 -2
  29. package/dist/esm/common/token-maps.partial.js +2 -2
  30. package/dist/esm/index.codegen.js +1 -1
  31. package/dist/esm/presets/all-flat.codegen.js +5 -3
  32. package/dist/esm/presets/all.codegen.js +5 -3
  33. package/dist/esm/presets/recommended-flat.codegen.js +4 -3
  34. package/dist/esm/presets/recommended.codegen.js +4 -3
  35. package/dist/esm/rules/ensure-design-token-usage/shape.js +5 -9
  36. package/dist/esm/rules/index.codegen.js +4 -1
  37. package/dist/esm/rules/use-tokens-shape/index.js +48 -0
  38. package/dist/esm/rules/use-tokens-shape/transformers/index.js +119 -0
  39. package/dist/esm/rules/use-tokens-shape/transformers/style-map.js +43 -0
  40. package/dist/esm/rules/use-tokens-shape/transformers/supported.js +9 -0
  41. package/dist/esm/rules/utils/is-node.js +2 -2
  42. package/dist/types/common/token-maps.partial.d.ts +51 -51
  43. package/dist/types/index.codegen.d.ts +3 -571
  44. package/dist/types/presets/all-flat.codegen.d.ts +8 -71
  45. package/dist/types/presets/all.codegen.d.ts +8 -71
  46. package/dist/types/presets/recommended-flat.codegen.d.ts +8 -52
  47. package/dist/types/presets/recommended.codegen.d.ts +8 -52
  48. package/dist/types/rules/index.codegen.d.ts +7 -68
  49. package/dist/types/rules/use-tokens-shape/index.d.ts +3 -0
  50. package/dist/types/rules/use-tokens-shape/transformers/index.d.ts +26 -0
  51. package/dist/types/rules/use-tokens-shape/transformers/style-map.d.ts +10 -0
  52. package/dist/types/rules/use-tokens-shape/transformers/supported.d.ts +6 -0
  53. package/dist/types/rules/use-tokens-typography/utils.d.ts +24 -60
  54. package/dist/types-ts4.5/common/token-maps.partial.d.ts +51 -51
  55. package/dist/types-ts4.5/index.codegen.d.ts +3 -595
  56. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +8 -74
  57. package/dist/types-ts4.5/presets/all.codegen.d.ts +8 -74
  58. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +8 -55
  59. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +8 -55
  60. package/dist/types-ts4.5/rules/index.codegen.d.ts +7 -68
  61. package/dist/types-ts4.5/rules/use-tokens-shape/index.d.ts +3 -0
  62. package/dist/types-ts4.5/rules/use-tokens-shape/transformers/index.d.ts +26 -0
  63. package/dist/types-ts4.5/rules/use-tokens-shape/transformers/style-map.d.ts +10 -0
  64. package/dist/types-ts4.5/rules/use-tokens-shape/transformers/supported.d.ts +6 -0
  65. package/dist/types-ts4.5/rules/use-tokens-typography/utils.d.ts +24 -60
  66. package/package.json +4 -8
@@ -0,0 +1,38 @@
1
+ import { createLintRule } from '../utils/create-rule';
2
+ import { StyleProperty } from './transformers';
3
+ const rule = createLintRule({
4
+ meta: {
5
+ name: 'use-tokens-shape',
6
+ type: 'problem',
7
+ fixable: 'code',
8
+ hasSuggestions: true,
9
+ docs: {
10
+ description: 'Enforces usage of shape design tokens rather than hard-coded values.',
11
+ recommended: false,
12
+ severity: 'error'
13
+ },
14
+ messages: {
15
+ noRawShapeValues: 'The use of shape tokens is preferred over the direct application of border radius and border width properties.'
16
+ }
17
+ },
18
+ create(context) {
19
+ return {
20
+ 'CallExpression[callee.name="css"] ObjectExpression Property': node => StyleProperty.lint(node, {
21
+ context
22
+ }),
23
+ 'CallExpression[callee.name="keyframes"] ObjectExpression Property': node => StyleProperty.lint(node, {
24
+ context
25
+ }),
26
+ 'CallExpression[callee.name="cssMap"] ObjectExpression Property': node => StyleProperty.lint(node, {
27
+ context
28
+ }),
29
+ 'CallExpression[callee.object.name=styled] ObjectExpression Property': node => StyleProperty.lint(node, {
30
+ context
31
+ }),
32
+ 'CallExpression[callee.object.name=styled2] ObjectExpression Property': node => StyleProperty.lint(node, {
33
+ context
34
+ })
35
+ };
36
+ }
37
+ });
38
+ export default rule;
@@ -0,0 +1,120 @@
1
+ /* eslint-disable @repo/internal/react/require-jsdoc */
2
+
3
+ import { isNodeOfType } from 'eslint-codemod-utils';
4
+ import * as ast from '../../../ast-nodes';
5
+ import { isStringOrNumber } from '../../use-tokens-space/utils';
6
+ import { styleMap } from './style-map';
7
+ import supported from './supported';
8
+ const messageId = 'noRawShapeValues';
9
+ export const StyleProperty = {
10
+ lint(node, {
11
+ context
12
+ }) {
13
+ // Check whether all criteria needed to make a transformation are met
14
+ const {
15
+ success,
16
+ ref
17
+ } = StyleProperty._check(node);
18
+ if (!success) {
19
+ return;
20
+ }
21
+ context.report({
22
+ node: ref.node.value,
23
+ messageId,
24
+ fix: ref.token ? StyleProperty._fix(ref, context) : undefined
25
+ });
26
+ },
27
+ _check(node) {
28
+ if (!isNodeOfType(node, 'Property')) {
29
+ return {
30
+ success: false,
31
+ ref: undefined
32
+ };
33
+ }
34
+
35
+ /**
36
+ * Currently, we support values like:
37
+ * ```
38
+ * {
39
+ * borderRadius: '8px', // value.type is Literal
40
+ * borderWidth: 2, // value.type is UnaryExpression
41
+ * }
42
+ * ```
43
+ */
44
+ if (!(isNodeOfType(node.value, 'Literal') || isNodeOfType(node.value, 'UnaryExpression'))) {
45
+ return {
46
+ success: false,
47
+ ref: undefined
48
+ };
49
+ }
50
+ const {
51
+ value: property
52
+ } = ast.ObjectEntry.getProperty(node);
53
+
54
+ // Bail if the property is not `borderRadius`, `borderWidth`, etc
55
+ if (!property || !styleMap[property]) {
56
+ return {
57
+ success: false,
58
+ ref: undefined
59
+ };
60
+ }
61
+ const value = ast.ObjectEntry.getValue(node);
62
+
63
+ // This is mainly useful as a type guard, so the checks after don't have to have duplicate checks for other types.
64
+ if (!isStringOrNumber(value)) {
65
+ return {
66
+ success: false,
67
+ ref: undefined
68
+ };
69
+ }
70
+
71
+ // ignore CSS vars. See: https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/74844/overview?commentId=6741571
72
+ if (value.toString().startsWith('var(')) {
73
+ return {
74
+ success: false,
75
+ ref: undefined
76
+ };
77
+ }
78
+
79
+ // There are valid values to ignore, such as `margin: auto`
80
+ if (supported.values.ignore.includes(value)) {
81
+ return {
82
+ success: false,
83
+ ref: undefined
84
+ };
85
+ }
86
+
87
+ // Don't report on stuff like `borderRadius: '3px 8px'`.
88
+ // We may iterate to handle values like this in future.
89
+ if (value.toString().includes(' ')) {
90
+ return {
91
+ success: false,
92
+ ref: undefined
93
+ };
94
+ }
95
+ const ref = {
96
+ node,
97
+ token: styleMap[property][value],
98
+ fallback: value
99
+ };
100
+ return {
101
+ success: true,
102
+ ref
103
+ };
104
+ },
105
+ /**
106
+ * All required validation steps have been taken care of before this
107
+ * transformer is called, so it just goes ahead providing all necessary fixes
108
+ */
109
+ _fix(ref, context) {
110
+ return fixer => {
111
+ const importFix = ast.Root.upsertNamedImportDeclaration({
112
+ module: '@atlaskit/tokens',
113
+ specifiers: ['token']
114
+ }, context, fixer);
115
+ const tokenCall = `token('${ref.token}')`;
116
+ const tokenFix = fixer.replaceText(ref.node.value, tokenCall);
117
+ return [importFix, tokenFix].filter(fix => Boolean(fix)); // Some of the transformers can return arrays with undefined, so filter them out
118
+ };
119
+ }
120
+ };
@@ -0,0 +1,43 @@
1
+ const radiusTokenMap = {
2
+ '2px': 'radius.xsmall',
3
+ '3px': 'radius.small',
4
+ '4px': 'radius.small',
5
+ '6px': 'radius.medium',
6
+ '8px': 'radius.large',
7
+ '12px': 'radius.xlarge',
8
+ '50%': 'radius.full',
9
+ '100%': 'radius.full',
10
+ 2: 'radius.xsmall',
11
+ 3: 'radius.small',
12
+ 4: 'radius.small',
13
+ 6: 'radius.medium',
14
+ 8: 'radius.large',
15
+ 12: 'radius.xlarge',
16
+ '0.125rem': 'radius.xsmall',
17
+ '0.25rem': 'radius.small',
18
+ '0.375rem': 'radius.medium',
19
+ '0.5rem': 'radius.large',
20
+ '0.75rem': 'radius.xlarge'
21
+ };
22
+ const borderWidthTokenMap = {
23
+ '1px': 'border.width'
24
+ };
25
+ export const styleMap = {
26
+ borderRadius: radiusTokenMap,
27
+ borderTopLeftRadius: radiusTokenMap,
28
+ borderTopRightRadius: radiusTokenMap,
29
+ borderBottomRightRadius: radiusTokenMap,
30
+ borderBottomLeftRadius: radiusTokenMap,
31
+ borderStartStartRadius: radiusTokenMap,
32
+ borderStartEndRadius: radiusTokenMap,
33
+ borderEndStartRadius: radiusTokenMap,
34
+ borderEndEndRadius: radiusTokenMap,
35
+ borderWidth: borderWidthTokenMap,
36
+ borderBottomWidth: borderWidthTokenMap,
37
+ borderLeftWidth: borderWidthTokenMap,
38
+ borderRightWidth: borderWidthTokenMap,
39
+ borderTopWidth: borderWidthTokenMap,
40
+ borderBlockWidth: borderWidthTokenMap,
41
+ borderInlineWidth: borderWidthTokenMap,
42
+ outlineWidth: borderWidthTokenMap
43
+ };
@@ -0,0 +1,9 @@
1
+ const supported = {
2
+ values: {
3
+ ignore: ['initial', 'inherit', 'unset', 'revert', 'revert-layer', 'none',
4
+ // outline-offset can be set to none
5
+ // Currently the DST opinion is that 0 is valid.
6
+ 0, '0', '0px', '0em', '0rem']
7
+ }
8
+ };
9
+ export default supported;
@@ -49,11 +49,11 @@ export const isDecendantOfSvgElement = node => {
49
49
  return false;
50
50
  };
51
51
  export const isDecendantOfPrimitive = (node, context) => {
52
- const primitivesToCheck = ['Box', 'Text'];
52
+ const primitivesToCheck = ['Box', 'Text', 'Tile'];
53
53
  if (isNodeOfType(node, 'JSXElement')) {
54
54
  // @ts-ignore
55
55
  if (primitivesToCheck.includes(node.openingElement.name.name)) {
56
- const importDeclaration = Root.findImportsByModule(getSourceCode(context).ast.body, ['@atlaskit/primitives', '@atlaskit/primitives/box', '@atlaskit/primitives/text', '@atlaskit/primitives/compiled']);
56
+ const importDeclaration = Root.findImportsByModule(getSourceCode(context).ast.body, ['@atlaskit/primitives', '@atlaskit/primitives/box', '@atlaskit/primitives/text', '@atlaskit/primitives/compiled', '@atlaskit/tile']);
57
57
  if (importDeclaration.length) {
58
58
  return true;
59
59
  }
@@ -3,10 +3,10 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  /**
5
5
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
6
- * @codegen <<SignedSource::a9fbd091c8b53fd9515afc7cdd793c6b>>
6
+ * @codegen <<SignedSource::f302f98104caa39f6137b6e8690eb7a8>>
7
7
  * @codegenId spacing
8
8
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen-token-maps
9
- * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::55622b91aca9b3afac4bce440f222b71>>
9
+ * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::07b9c29f8d9f95e43d59a7b7ad4ce7a2>>
10
10
  */
11
11
  export var positiveSpaceMap = {
12
12
  '0px': 'space.0',
@@ -3,7 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  /**
5
5
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
6
- * @codegen <<SignedSource::1ca7a384145f3bf3577ede9b88907a52>>
6
+ * @codegen <<SignedSource::891a7e1d667de46cfe89cad670005f2c>>
7
7
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
8
8
  */
9
9
 
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::e075ab709ebd382d6f5e39fd78de9d6d>>
3
+ * @codegen <<SignedSource::6210f09c70f4d44befb986dfd548ed3e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
7
- export default {
7
+ var rules = {
8
8
  // NOTE: The reference to this plugin is inserted dynamically while creating the plugin in `index.codegen.tsx`
9
9
  plugins: {},
10
10
  rules: {
@@ -70,8 +70,10 @@ export default {
70
70
  '@atlaskit/design-system/use-primitives-text': 'warn',
71
71
  '@atlaskit/design-system/use-should-render-to-parent': 'warn',
72
72
  '@atlaskit/design-system/use-tag-group-label': 'warn',
73
+ '@atlaskit/design-system/use-tokens-shape': 'error',
73
74
  '@atlaskit/design-system/use-tokens-space': 'error',
74
75
  '@atlaskit/design-system/use-tokens-typography': 'warn',
75
76
  '@atlaskit/design-system/use-visually-hidden': 'error'
76
77
  }
77
- };
78
+ };
79
+ export default rules;
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::d78f5649534c2e153e3ce48063649a8a>>
3
+ * @codegen <<SignedSource::daf4a5893d65c7a1592f8bc6e51920c6>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
7
- export default {
7
+ var rules = {
8
8
  plugins: ['@atlaskit/design-system'],
9
9
  rules: {
10
10
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
@@ -69,8 +69,10 @@ export default {
69
69
  '@atlaskit/design-system/use-primitives-text': 'warn',
70
70
  '@atlaskit/design-system/use-should-render-to-parent': 'warn',
71
71
  '@atlaskit/design-system/use-tag-group-label': 'warn',
72
+ '@atlaskit/design-system/use-tokens-shape': 'error',
72
73
  '@atlaskit/design-system/use-tokens-space': 'error',
73
74
  '@atlaskit/design-system/use-tokens-typography': 'warn',
74
75
  '@atlaskit/design-system/use-visually-hidden': 'error'
75
76
  }
76
- };
77
+ };
78
+ export default rules;
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::310988af3dc2559509bf99f2110134b8>>
3
+ * @codegen <<SignedSource::3328b9c675a0d09876dcfbc5d29bc63f>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
7
- export default {
7
+ var rules = {
8
8
  // NOTE: The reference to this plugin is inserted dynamically while creating the plugin in `index.codegen.tsx`
9
9
  plugins: {},
10
10
  rules: {
@@ -55,4 +55,5 @@ export default {
55
55
  '@atlaskit/design-system/use-tag-group-label': 'warn',
56
56
  '@atlaskit/design-system/use-visually-hidden': 'error'
57
57
  }
58
- };
58
+ };
59
+ export default rules;
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::ce9d9b39fba8bb67d218e48398271109>>
3
+ * @codegen <<SignedSource::b28f895280627b7a35f059f90783644a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
7
- export default {
7
+ var rules = {
8
8
  plugins: ['@atlaskit/design-system'],
9
9
  rules: {
10
10
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
@@ -54,4 +54,5 @@ export default {
54
54
  '@atlaskit/design-system/use-tag-group-label': 'warn',
55
55
  '@atlaskit/design-system/use-visually-hidden': 'error'
56
56
  }
57
- };
57
+ };
58
+ export default rules;
@@ -1,18 +1,14 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { shape as shapeTokens } from '@atlaskit/tokens/tokens-raw';
3
- var shapeProperties = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'borderRadius'];
3
+ var shapeProperties = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'borderRadius', 'borderStartStartRadius', 'borderStartEndRadius', 'borderEndStartRadius', 'borderEndEndRadius'];
4
4
  var borderSizeProperties = ['borderWidth', 'outlineWidth', 'borderRightWidth', 'borderLeftWidth', 'borderTopWidth', 'borderBottomWidth', 'borderInlineWidth', 'borderBlockWidth'];
5
5
  export var radiusValueToToken = Object.fromEntries(shapeTokens.filter(function (t) {
6
- return t.name.startsWith('border.radius');
7
- })
8
- // we prefer using the default (border.radius) over its aliases
9
- .filter(function (t) {
10
- return !t.name.startsWith('border.radius.100');
6
+ return t.name.startsWith('radius');
11
7
  }).map(function (t) {
12
8
  return [t.value, t.cleanName];
13
- }).concat([['3px', 'border.radius']]) // add in an extra entry to resolve 3px to border.radius (normally 4px)
14
- .concat([['50%', 'border.radius.circle']]) // add in an extra entry to resolve 50% to border.radius.circle (normally 2002rem)
15
- );
9
+ })
10
+ // add in extra entries to resolve 3px, 50%, and 100% to tokens
11
+ .concat([['3px', 'radius.small'], ['50%', 'radius.full'], ['100%', 'radius.full']]));
16
12
  export var borderWidthValueToToken = Object.fromEntries(shapeTokens.filter(function (t) {
17
13
  return t.name.startsWith('border.width');
18
14
  }).map(function (t) {
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::53ad66d79f989ce9beb46ee0186685b2>>
3
+ * @codegen <<SignedSource::4693db80b637ac078521dd6e0591f75b>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
+
6
7
  import consistentCssPropUsage from './consistent-css-prop-usage';
7
8
  import enforceInlineStylesInSelect from './enforce-inline-styles-in-select';
8
9
  import ensureDesignTokenUsage from './ensure-design-token-usage';
@@ -66,6 +67,7 @@ import usePrimitives from './use-primitives';
66
67
  import usePrimitivesText from './use-primitives-text';
67
68
  import useShouldRenderToParent from './use-should-render-to-parent';
68
69
  import useTagGroupLabel from './use-tag-group-label';
70
+ import useTokensShape from './use-tokens-shape';
69
71
  import useTokensSpace from './use-tokens-space';
70
72
  import useTokensTypography from './use-tokens-typography';
71
73
  import useVisuallyHidden from './use-visually-hidden';
@@ -133,6 +135,7 @@ export var rules = {
133
135
  'use-primitives-text': usePrimitivesText,
134
136
  'use-should-render-to-parent': useShouldRenderToParent,
135
137
  'use-tag-group-label': useTagGroupLabel,
138
+ 'use-tokens-shape': useTokensShape,
136
139
  'use-tokens-space': useTokensSpace,
137
140
  'use-tokens-typography': useTokensTypography,
138
141
  'use-visually-hidden': useVisuallyHidden
@@ -0,0 +1,48 @@
1
+ import { createLintRule } from '../utils/create-rule';
2
+ import { StyleProperty } from './transformers';
3
+ var rule = createLintRule({
4
+ meta: {
5
+ name: 'use-tokens-shape',
6
+ type: 'problem',
7
+ fixable: 'code',
8
+ hasSuggestions: true,
9
+ docs: {
10
+ description: 'Enforces usage of shape design tokens rather than hard-coded values.',
11
+ recommended: false,
12
+ severity: 'error'
13
+ },
14
+ messages: {
15
+ noRawShapeValues: 'The use of shape tokens is preferred over the direct application of border radius and border width properties.'
16
+ }
17
+ },
18
+ create: function create(context) {
19
+ return {
20
+ 'CallExpression[callee.name="css"] ObjectExpression Property': function CallExpressionCalleeNameCss_ObjectExpression_Property(node) {
21
+ return StyleProperty.lint(node, {
22
+ context: context
23
+ });
24
+ },
25
+ 'CallExpression[callee.name="keyframes"] ObjectExpression Property': function CallExpressionCalleeNameKeyframes_ObjectExpression_Property(node) {
26
+ return StyleProperty.lint(node, {
27
+ context: context
28
+ });
29
+ },
30
+ 'CallExpression[callee.name="cssMap"] ObjectExpression Property': function CallExpressionCalleeNameCssMap_ObjectExpression_Property(node) {
31
+ return StyleProperty.lint(node, {
32
+ context: context
33
+ });
34
+ },
35
+ 'CallExpression[callee.object.name=styled] ObjectExpression Property': function CallExpressionCalleeObjectNameStyled_ObjectExpression_Property(node) {
36
+ return StyleProperty.lint(node, {
37
+ context: context
38
+ });
39
+ },
40
+ 'CallExpression[callee.object.name=styled2] ObjectExpression Property': function CallExpressionCalleeObjectNameStyled2_ObjectExpression_Property(node) {
41
+ return StyleProperty.lint(node, {
42
+ context: context
43
+ });
44
+ }
45
+ };
46
+ }
47
+ });
48
+ export default rule;
@@ -0,0 +1,119 @@
1
+ /* eslint-disable @repo/internal/react/require-jsdoc */
2
+
3
+ import { isNodeOfType } from 'eslint-codemod-utils';
4
+ import * as ast from '../../../ast-nodes';
5
+ import { isStringOrNumber } from '../../use-tokens-space/utils';
6
+ import { styleMap } from './style-map';
7
+ import supported from './supported';
8
+ var messageId = 'noRawShapeValues';
9
+ export var StyleProperty = {
10
+ lint: function lint(node, _ref) {
11
+ var context = _ref.context;
12
+ // Check whether all criteria needed to make a transformation are met
13
+ var _StyleProperty$_check = StyleProperty._check(node),
14
+ success = _StyleProperty$_check.success,
15
+ ref = _StyleProperty$_check.ref;
16
+ if (!success) {
17
+ return;
18
+ }
19
+ context.report({
20
+ node: ref.node.value,
21
+ messageId: messageId,
22
+ fix: ref.token ? StyleProperty._fix(ref, context) : undefined
23
+ });
24
+ },
25
+ _check: function _check(node) {
26
+ if (!isNodeOfType(node, 'Property')) {
27
+ return {
28
+ success: false,
29
+ ref: undefined
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Currently, we support values like:
35
+ * ```
36
+ * {
37
+ * borderRadius: '8px', // value.type is Literal
38
+ * borderWidth: 2, // value.type is UnaryExpression
39
+ * }
40
+ * ```
41
+ */
42
+ if (!(isNodeOfType(node.value, 'Literal') || isNodeOfType(node.value, 'UnaryExpression'))) {
43
+ return {
44
+ success: false,
45
+ ref: undefined
46
+ };
47
+ }
48
+ var _ast$ObjectEntry$getP = ast.ObjectEntry.getProperty(node),
49
+ property = _ast$ObjectEntry$getP.value;
50
+
51
+ // Bail if the property is not `borderRadius`, `borderWidth`, etc
52
+ if (!property || !styleMap[property]) {
53
+ return {
54
+ success: false,
55
+ ref: undefined
56
+ };
57
+ }
58
+ var value = ast.ObjectEntry.getValue(node);
59
+
60
+ // This is mainly useful as a type guard, so the checks after don't have to have duplicate checks for other types.
61
+ if (!isStringOrNumber(value)) {
62
+ return {
63
+ success: false,
64
+ ref: undefined
65
+ };
66
+ }
67
+
68
+ // ignore CSS vars. See: https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/74844/overview?commentId=6741571
69
+ if (value.toString().startsWith('var(')) {
70
+ return {
71
+ success: false,
72
+ ref: undefined
73
+ };
74
+ }
75
+
76
+ // There are valid values to ignore, such as `margin: auto`
77
+ if (supported.values.ignore.includes(value)) {
78
+ return {
79
+ success: false,
80
+ ref: undefined
81
+ };
82
+ }
83
+
84
+ // Don't report on stuff like `borderRadius: '3px 8px'`.
85
+ // We may iterate to handle values like this in future.
86
+ if (value.toString().includes(' ')) {
87
+ return {
88
+ success: false,
89
+ ref: undefined
90
+ };
91
+ }
92
+ var ref = {
93
+ node: node,
94
+ token: styleMap[property][value],
95
+ fallback: value
96
+ };
97
+ return {
98
+ success: true,
99
+ ref: ref
100
+ };
101
+ },
102
+ /**
103
+ * All required validation steps have been taken care of before this
104
+ * transformer is called, so it just goes ahead providing all necessary fixes
105
+ */
106
+ _fix: function _fix(ref, context) {
107
+ return function (fixer) {
108
+ var importFix = ast.Root.upsertNamedImportDeclaration({
109
+ module: '@atlaskit/tokens',
110
+ specifiers: ['token']
111
+ }, context, fixer);
112
+ var tokenCall = "token('".concat(ref.token, "')");
113
+ var tokenFix = fixer.replaceText(ref.node.value, tokenCall);
114
+ return [importFix, tokenFix].filter(function (fix) {
115
+ return Boolean(fix);
116
+ }); // Some of the transformers can return arrays with undefined, so filter them out
117
+ };
118
+ }
119
+ };
@@ -0,0 +1,43 @@
1
+ var radiusTokenMap = {
2
+ '2px': 'radius.xsmall',
3
+ '3px': 'radius.small',
4
+ '4px': 'radius.small',
5
+ '6px': 'radius.medium',
6
+ '8px': 'radius.large',
7
+ '12px': 'radius.xlarge',
8
+ '50%': 'radius.full',
9
+ '100%': 'radius.full',
10
+ 2: 'radius.xsmall',
11
+ 3: 'radius.small',
12
+ 4: 'radius.small',
13
+ 6: 'radius.medium',
14
+ 8: 'radius.large',
15
+ 12: 'radius.xlarge',
16
+ '0.125rem': 'radius.xsmall',
17
+ '0.25rem': 'radius.small',
18
+ '0.375rem': 'radius.medium',
19
+ '0.5rem': 'radius.large',
20
+ '0.75rem': 'radius.xlarge'
21
+ };
22
+ var borderWidthTokenMap = {
23
+ '1px': 'border.width'
24
+ };
25
+ export var styleMap = {
26
+ borderRadius: radiusTokenMap,
27
+ borderTopLeftRadius: radiusTokenMap,
28
+ borderTopRightRadius: radiusTokenMap,
29
+ borderBottomRightRadius: radiusTokenMap,
30
+ borderBottomLeftRadius: radiusTokenMap,
31
+ borderStartStartRadius: radiusTokenMap,
32
+ borderStartEndRadius: radiusTokenMap,
33
+ borderEndStartRadius: radiusTokenMap,
34
+ borderEndEndRadius: radiusTokenMap,
35
+ borderWidth: borderWidthTokenMap,
36
+ borderBottomWidth: borderWidthTokenMap,
37
+ borderLeftWidth: borderWidthTokenMap,
38
+ borderRightWidth: borderWidthTokenMap,
39
+ borderTopWidth: borderWidthTokenMap,
40
+ borderBlockWidth: borderWidthTokenMap,
41
+ borderInlineWidth: borderWidthTokenMap,
42
+ outlineWidth: borderWidthTokenMap
43
+ };
@@ -0,0 +1,9 @@
1
+ var supported = {
2
+ values: {
3
+ ignore: ['initial', 'inherit', 'unset', 'revert', 'revert-layer', 'none',
4
+ // outline-offset can be set to none
5
+ // Currently the DST opinion is that 0 is valid.
6
+ 0, '0', '0px', '0em', '0rem']
7
+ }
8
+ };
9
+ export default supported;
@@ -54,11 +54,11 @@ var _isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
54
54
  };
55
55
  export { _isDecendantOfSvgElement as isDecendantOfSvgElement };
56
56
  var _isDecendantOfPrimitive = function isDecendantOfPrimitive(node, context) {
57
- var primitivesToCheck = ['Box', 'Text'];
57
+ var primitivesToCheck = ['Box', 'Text', 'Tile'];
58
58
  if (isNodeOfType(node, 'JSXElement')) {
59
59
  // @ts-ignore
60
60
  if (primitivesToCheck.includes(node.openingElement.name.name)) {
61
- var importDeclaration = Root.findImportsByModule(getSourceCode(context).ast.body, ['@atlaskit/primitives', '@atlaskit/primitives/box', '@atlaskit/primitives/text', '@atlaskit/primitives/compiled']);
61
+ var importDeclaration = Root.findImportsByModule(getSourceCode(context).ast.body, ['@atlaskit/primitives', '@atlaskit/primitives/box', '@atlaskit/primitives/text', '@atlaskit/primitives/compiled', '@atlaskit/tile']);
62
62
  if (importDeclaration.length) {
63
63
  return true;
64
64
  }