@atlaskit/eslint-plugin-design-system 13.20.0 → 13.21.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 (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -1
  4. package/dist/cjs/presets/all.codegen.js +2 -1
  5. package/dist/cjs/rules/ensure-design-token-usage/shape.js +5 -9
  6. package/dist/cjs/rules/index.codegen.js +3 -1
  7. package/dist/cjs/rules/no-custom-icons/index.js +17 -5
  8. package/dist/cjs/rules/use-tokens-shape/index.js +54 -0
  9. package/dist/cjs/rules/use-tokens-shape/transformers/index.js +128 -0
  10. package/dist/cjs/rules/use-tokens-shape/transformers/style-map.js +49 -0
  11. package/dist/cjs/rules/use-tokens-shape/transformers/supported.js +15 -0
  12. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  13. package/dist/es2019/presets/all.codegen.js +2 -1
  14. package/dist/es2019/rules/ensure-design-token-usage/shape.js +5 -7
  15. package/dist/es2019/rules/index.codegen.js +3 -1
  16. package/dist/es2019/rules/no-custom-icons/index.js +17 -5
  17. package/dist/es2019/rules/use-tokens-shape/index.js +38 -0
  18. package/dist/es2019/rules/use-tokens-shape/transformers/index.js +120 -0
  19. package/dist/es2019/rules/use-tokens-shape/transformers/style-map.js +43 -0
  20. package/dist/es2019/rules/use-tokens-shape/transformers/supported.js +9 -0
  21. package/dist/esm/presets/all-flat.codegen.js +2 -1
  22. package/dist/esm/presets/all.codegen.js +2 -1
  23. package/dist/esm/rules/ensure-design-token-usage/shape.js +5 -9
  24. package/dist/esm/rules/index.codegen.js +3 -1
  25. package/dist/esm/rules/no-custom-icons/index.js +17 -5
  26. package/dist/esm/rules/use-tokens-shape/index.js +48 -0
  27. package/dist/esm/rules/use-tokens-shape/transformers/index.js +119 -0
  28. package/dist/esm/rules/use-tokens-shape/transformers/style-map.js +43 -0
  29. package/dist/esm/rules/use-tokens-shape/transformers/supported.js +9 -0
  30. package/dist/types/index.codegen.d.ts +5 -0
  31. package/dist/types/presets/all-flat.codegen.d.ts +1 -0
  32. package/dist/types/presets/all.codegen.d.ts +1 -0
  33. package/dist/types/rules/index.codegen.d.ts +1 -0
  34. package/dist/types/rules/use-tokens-shape/index.d.ts +3 -0
  35. package/dist/types/rules/use-tokens-shape/transformers/index.d.ts +26 -0
  36. package/dist/types/rules/use-tokens-shape/transformers/style-map.d.ts +10 -0
  37. package/dist/types/rules/use-tokens-shape/transformers/supported.d.ts +6 -0
  38. package/dist/types-ts4.5/index.codegen.d.ts +5 -0
  39. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
  40. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
  41. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  42. package/dist/types-ts4.5/rules/use-tokens-shape/index.d.ts +3 -0
  43. package/dist/types-ts4.5/rules/use-tokens-shape/transformers/index.d.ts +26 -0
  44. package/dist/types-ts4.5/rules/use-tokens-shape/transformers/style-map.d.ts +10 -0
  45. package/dist/types-ts4.5/rules/use-tokens-shape/transformers/supported.d.ts +6 -0
  46. package/package.json +4 -4
@@ -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;
@@ -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::e075ab709ebd382d6f5e39fd78de9d6d>>
3
+ * @codegen <<SignedSource::c8428e53319286fb2b37a107968f2be8>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -70,6 +70,7 @@ 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'
@@ -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::d78f5649534c2e153e3ce48063649a8a>>
3
+ * @codegen <<SignedSource::a739ba6d63b1aa39d462906ee1876ce6>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -69,6 +69,7 @@ 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'
@@ -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,6 +1,6 @@
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::5fbd59fcd3fd6cb0602821de4a0a32aa>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -66,6 +66,7 @@ import usePrimitives from './use-primitives';
66
66
  import usePrimitivesText from './use-primitives-text';
67
67
  import useShouldRenderToParent from './use-should-render-to-parent';
68
68
  import useTagGroupLabel from './use-tag-group-label';
69
+ import useTokensShape from './use-tokens-shape';
69
70
  import useTokensSpace from './use-tokens-space';
70
71
  import useTokensTypography from './use-tokens-typography';
71
72
  import useVisuallyHidden from './use-visually-hidden';
@@ -133,6 +134,7 @@ export var rules = {
133
134
  'use-primitives-text': usePrimitivesText,
134
135
  'use-should-render-to-parent': useShouldRenderToParent,
135
136
  'use-tag-group-label': useTagGroupLabel,
137
+ 'use-tokens-shape': useTokensShape,
136
138
  'use-tokens-space': useTokensSpace,
137
139
  'use-tokens-typography': useTokensTypography,
138
140
  'use-visually-hidden': useVisuallyHidden
@@ -24,11 +24,12 @@ var rule = createLintRule({
24
24
  additionalProperties: false
25
25
  }],
26
26
  messages: {
27
- noCustomIcons: "Custom icons from {{importSource}} are no longer supported. Migrate to an icon from '@atlaskit/(icon-labs|icon/core|icon/utility)'{{locationMessage}}.\n[Migration guide](https://hello.atlassian.net/wiki/spaces/DST/pages/3748692796/New+ADS+iconography+-+Code+migration+guide)."
27
+ noCustomIcons: "Custom icons/svgs from {{importSource}} are no longer supported. Migrate to an icon from '@atlaskit/(icon-labs|icon/core|icon/utility)'{{locationMessage}}.\n[Migration guide](https://hello.atlassian.net/wiki/spaces/DST/pages/3748692796/New+ADS+iconography+-+Code+migration+guide)."
28
28
  }
29
29
  },
30
30
  create: function create(context) {
31
31
  var _context$options$;
32
+ var isIconSvg = createIsFromImportSourceFor('@atlaskit/icon/svg');
32
33
  var isIconBase = createIsFromImportSourceFor('@atlaskit/icon', '@atlaskit/icon/base');
33
34
 
34
35
  // TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
@@ -37,14 +38,25 @@ var rule = createLintRule({
37
38
  centralLocation = _ref$centralLocation === void 0 ? '' : _ref$centralLocation,
38
39
  _ref$failSilently = _ref.failSilently,
39
40
  failSilently = _ref$failSilently === void 0 ? false : _ref$failSilently;
41
+ function checkNode(node) {
42
+ isIconBase.importDeclarationHook(node);
43
+ isIconSvg.importDeclarationHook(node);
44
+ }
40
45
  var locationMessage = centralLocation ? ", move the icon to '".concat(centralLocation, "', or, if it's a third party logo, migrate to a standard <svg> element with a `label`.") : '';
41
46
  return errorBoundary({
42
47
  JSXElement: function JSXElement(node) {
43
- var _isIconBase$getImport;
44
- if (!isIconBase(node) || !hasProp(node, 'glyph')) {
48
+ var isSvg = isIconSvg(node);
49
+ var isBase = isIconBase(node);
50
+ // Not an icon import
51
+ if (!isSvg && (!isBase || !hasProp(node, 'glyph'))) {
45
52
  return;
46
53
  }
47
- var importSource = (_isIconBase$getImport = isIconBase.getImportSource(node)) !== null && _isIconBase$getImport !== void 0 ? _isIconBase$getImport : '';
54
+ var importSource = '';
55
+ if (isSvg) {
56
+ importSource = isIconSvg.getImportSource(node);
57
+ } else if (isBase) {
58
+ importSource = isIconBase.getImportSource(node);
59
+ }
48
60
  context.report({
49
61
  node: node.openingElement,
50
62
  messageId: 'noCustomIcons',
@@ -54,7 +66,7 @@ var rule = createLintRule({
54
66
  }
55
67
  });
56
68
  },
57
- ImportDeclaration: isIconBase.importDeclarationHook
69
+ ImportDeclaration: checkNode
58
70
  }, failSilently);
59
71
  }
60
72
  });
@@ -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;
@@ -78,6 +78,7 @@ export declare const plugin: {
78
78
  'use-primitives-text': import("eslint").Rule.RuleModule;
79
79
  'use-should-render-to-parent': import("eslint").Rule.RuleModule;
80
80
  'use-tag-group-label': import("eslint").Rule.RuleModule;
81
+ 'use-tokens-shape': import("eslint").Rule.RuleModule;
81
82
  'use-tokens-space': import("eslint").Rule.RuleModule;
82
83
  'use-tokens-typography': import("eslint").Rule.RuleModule;
83
84
  'use-visually-hidden': import("eslint").Rule.RuleModule;
@@ -148,6 +149,7 @@ export declare const plugin: {
148
149
  '@atlaskit/design-system/use-primitives-text': "warn";
149
150
  '@atlaskit/design-system/use-should-render-to-parent': "warn";
150
151
  '@atlaskit/design-system/use-tag-group-label': "warn";
152
+ '@atlaskit/design-system/use-tokens-shape': "error";
151
153
  '@atlaskit/design-system/use-tokens-space': "error";
152
154
  '@atlaskit/design-system/use-tokens-typography': "warn";
153
155
  '@atlaskit/design-system/use-visually-hidden': "error";
@@ -220,6 +222,7 @@ export declare const plugin: {
220
222
  '@atlaskit/design-system/use-primitives-text': "warn";
221
223
  '@atlaskit/design-system/use-should-render-to-parent': "warn";
222
224
  '@atlaskit/design-system/use-tag-group-label': "warn";
225
+ '@atlaskit/design-system/use-tokens-shape': "error";
223
226
  '@atlaskit/design-system/use-tokens-space': "error";
224
227
  '@atlaskit/design-system/use-tokens-typography': "warn";
225
228
  '@atlaskit/design-system/use-visually-hidden': "error";
@@ -397,6 +400,7 @@ declare const configs: {
397
400
  '@atlaskit/design-system/use-primitives-text': "warn";
398
401
  '@atlaskit/design-system/use-should-render-to-parent': "warn";
399
402
  '@atlaskit/design-system/use-tag-group-label': "warn";
403
+ '@atlaskit/design-system/use-tokens-shape': "error";
400
404
  '@atlaskit/design-system/use-tokens-space': "error";
401
405
  '@atlaskit/design-system/use-tokens-typography': "warn";
402
406
  '@atlaskit/design-system/use-visually-hidden': "error";
@@ -469,6 +473,7 @@ declare const configs: {
469
473
  '@atlaskit/design-system/use-primitives-text': "warn";
470
474
  '@atlaskit/design-system/use-should-render-to-parent': "warn";
471
475
  '@atlaskit/design-system/use-tag-group-label': "warn";
476
+ '@atlaskit/design-system/use-tokens-shape': "error";
472
477
  '@atlaskit/design-system/use-tokens-space': "error";
473
478
  '@atlaskit/design-system/use-tokens-typography': "warn";
474
479
  '@atlaskit/design-system/use-visually-hidden': "error";
@@ -63,6 +63,7 @@ declare const _default: {
63
63
  '@atlaskit/design-system/use-primitives-text': "warn";
64
64
  '@atlaskit/design-system/use-should-render-to-parent': "warn";
65
65
  '@atlaskit/design-system/use-tag-group-label': "warn";
66
+ '@atlaskit/design-system/use-tokens-shape': "error";
66
67
  '@atlaskit/design-system/use-tokens-space': "error";
67
68
  '@atlaskit/design-system/use-tokens-typography': "warn";
68
69
  '@atlaskit/design-system/use-visually-hidden': "error";
@@ -63,6 +63,7 @@ declare const _default: {
63
63
  '@atlaskit/design-system/use-primitives-text': "warn";
64
64
  '@atlaskit/design-system/use-should-render-to-parent': "warn";
65
65
  '@atlaskit/design-system/use-tag-group-label': "warn";
66
+ '@atlaskit/design-system/use-tokens-shape': "error";
66
67
  '@atlaskit/design-system/use-tokens-space': "error";
67
68
  '@atlaskit/design-system/use-tokens-typography': "warn";
68
69
  '@atlaskit/design-system/use-visually-hidden': "error";
@@ -62,6 +62,7 @@ export declare const rules: {
62
62
  'use-primitives-text': import("eslint").Rule.RuleModule;
63
63
  'use-should-render-to-parent': import("eslint").Rule.RuleModule;
64
64
  'use-tag-group-label': import("eslint").Rule.RuleModule;
65
+ 'use-tokens-shape': import("eslint").Rule.RuleModule;
65
66
  'use-tokens-space': import("eslint").Rule.RuleModule;
66
67
  'use-tokens-typography': import("eslint").Rule.RuleModule;
67
68
  'use-visually-hidden': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,26 @@
1
+ import type { Rule } from 'eslint';
2
+ import { type Property } from 'eslint-codemod-utils';
3
+ type Ref = {
4
+ node: Property;
5
+ token?: string;
6
+ fallback?: string | number;
7
+ };
8
+ type Check = {
9
+ success: false;
10
+ ref: undefined;
11
+ } | {
12
+ success: true;
13
+ ref: Ref;
14
+ };
15
+ export declare const StyleProperty: {
16
+ lint(node: Rule.Node, { context }: {
17
+ context: Rule.RuleContext;
18
+ }): void;
19
+ _check(node: Rule.Node): Check;
20
+ /**
21
+ * All required validation steps have been taken care of before this
22
+ * transformer is called, so it just goes ahead providing all necessary fixes
23
+ */
24
+ _fix(ref: Ref, context: Rule.RuleContext): (fixer: Rule.RuleFixer) => Rule.Fix[];
25
+ };
26
+ export {};
@@ -0,0 +1,10 @@
1
+ declare const radiusTokenMap: {
2
+ [key: string]: string;
3
+ };
4
+ declare const borderWidthTokenMap: {
5
+ [key: string]: string;
6
+ };
7
+ export declare const styleMap: {
8
+ [key: string]: typeof radiusTokenMap | typeof borderWidthTokenMap;
9
+ };
10
+ export {};
@@ -0,0 +1,6 @@
1
+ declare const supported: {
2
+ values: {
3
+ ignore: (string | number)[];
4
+ };
5
+ };
6
+ export default supported;