@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.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -0
- package/dist/cjs/presets/all-flat.codegen.js +2 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/rules/ensure-design-token-usage/shape.js +5 -9
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-custom-icons/index.js +17 -5
- package/dist/cjs/rules/use-tokens-shape/index.js +54 -0
- package/dist/cjs/rules/use-tokens-shape/transformers/index.js +128 -0
- package/dist/cjs/rules/use-tokens-shape/transformers/style-map.js +49 -0
- package/dist/cjs/rules/use-tokens-shape/transformers/supported.js +15 -0
- package/dist/es2019/presets/all-flat.codegen.js +2 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/rules/ensure-design-token-usage/shape.js +5 -7
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-custom-icons/index.js +17 -5
- package/dist/es2019/rules/use-tokens-shape/index.js +38 -0
- package/dist/es2019/rules/use-tokens-shape/transformers/index.js +120 -0
- package/dist/es2019/rules/use-tokens-shape/transformers/style-map.js +43 -0
- package/dist/es2019/rules/use-tokens-shape/transformers/supported.js +9 -0
- package/dist/esm/presets/all-flat.codegen.js +2 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/rules/ensure-design-token-usage/shape.js +5 -9
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-custom-icons/index.js +17 -5
- package/dist/esm/rules/use-tokens-shape/index.js +48 -0
- package/dist/esm/rules/use-tokens-shape/transformers/index.js +119 -0
- package/dist/esm/rules/use-tokens-shape/transformers/style-map.js +43 -0
- package/dist/esm/rules/use-tokens-shape/transformers/supported.js +9 -0
- package/dist/types/index.codegen.d.ts +5 -0
- package/dist/types/presets/all-flat.codegen.d.ts +1 -0
- package/dist/types/presets/all.codegen.d.ts +1 -0
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/use-tokens-shape/index.d.ts +3 -0
- package/dist/types/rules/use-tokens-shape/transformers/index.d.ts +26 -0
- package/dist/types/rules/use-tokens-shape/transformers/style-map.d.ts +10 -0
- package/dist/types/rules/use-tokens-shape/transformers/supported.d.ts +6 -0
- package/dist/types-ts4.5/index.codegen.d.ts +5 -0
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-tokens-shape/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-tokens-shape/transformers/index.d.ts +26 -0
- package/dist/types-ts4.5/rules/use-tokens-shape/transformers/style-map.d.ts +10 -0
- package/dist/types-ts4.5/rules/use-tokens-shape/transformers/supported.d.ts +6 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 13.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`8a95abe487d79`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8a95abe487d79) - -
|
|
8
|
+
Added `use-tokens-shape` rule to enforce borderRadius and borderWidth values.
|
|
9
|
+
- Updated `ensure-design-token-usage` rule to apply correct shape tokens. Note this rule should
|
|
10
|
+
not be used for shape - instead use the `use-tokens-shape` rule instead.
|
|
11
|
+
|
|
12
|
+
## 13.20.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`2896429aaa267`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2896429aaa267) -
|
|
17
|
+
Update the no-custom-icons eslint rule to include checking for custom svg usage
|
|
18
|
+
|
|
3
19
|
## 13.20.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -112,6 +112,7 @@ module.exports = {
|
|
|
112
112
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-primitives-text/README.md">use-primitives-text</a> | Encourage the usage of text components. | | Yes | Yes |
|
|
113
113
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-should-render-to-parent/README.md">use-should-render-to-parent</a> | Encourages makers to use the `shouldRenderToParent` where possible in Atlassian Design System `Popup` and `DropdownMenu` components. | Yes | | Yes |
|
|
114
114
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-tag-group-label/README.md">use-tag-group-label</a> | Ensures tag groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
|
|
115
|
+
| <a href="./packages/design-system/eslint-plugin/src/rules/use-tokens-shape/README.md">use-tokens-shape</a> | Enforces usage of shape design tokens rather than hard-coded values. | | Yes | Yes |
|
|
115
116
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-tokens-space/README.md">use-tokens-space</a> | Enforces usage of space design tokens rather than hard-coded values. | | Yes | Yes |
|
|
116
117
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-tokens-typography/README.md">use-tokens-typography</a> | Enforces usage of design tokens for typography properties rather than hard-coded values. | | Yes | Yes |
|
|
117
118
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-visually-hidden/README.md">use-visually-hidden</a> | Enforce usage of the visually hidden component. | Yes | Yes | |
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::c8428e53319286fb2b37a107968f2be8>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -75,6 +75,7 @@ var _default = exports.default = {
|
|
|
75
75
|
'@atlaskit/design-system/use-primitives-text': 'warn',
|
|
76
76
|
'@atlaskit/design-system/use-should-render-to-parent': 'warn',
|
|
77
77
|
'@atlaskit/design-system/use-tag-group-label': 'warn',
|
|
78
|
+
'@atlaskit/design-system/use-tokens-shape': 'error',
|
|
78
79
|
'@atlaskit/design-system/use-tokens-space': 'error',
|
|
79
80
|
'@atlaskit/design-system/use-tokens-typography': 'warn',
|
|
80
81
|
'@atlaskit/design-system/use-visually-hidden': 'error'
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::a739ba6d63b1aa39d462906ee1876ce6>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -74,6 +74,7 @@ var _default = exports.default = {
|
|
|
74
74
|
'@atlaskit/design-system/use-primitives-text': 'warn',
|
|
75
75
|
'@atlaskit/design-system/use-should-render-to-parent': 'warn',
|
|
76
76
|
'@atlaskit/design-system/use-tag-group-label': 'warn',
|
|
77
|
+
'@atlaskit/design-system/use-tokens-shape': 'error',
|
|
77
78
|
'@atlaskit/design-system/use-tokens-space': 'error',
|
|
78
79
|
'@atlaskit/design-system/use-tokens-typography': 'warn',
|
|
79
80
|
'@atlaskit/design-system/use-visually-hidden': 'error'
|
|
@@ -11,19 +11,15 @@ exports.isShapeProperty = isShapeProperty;
|
|
|
11
11
|
exports.radiusValueToToken = void 0;
|
|
12
12
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
13
13
|
var _tokensRaw = require("@atlaskit/tokens/tokens-raw");
|
|
14
|
-
var shapeProperties = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'borderRadius'];
|
|
14
|
+
var shapeProperties = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'borderRadius', 'borderStartStartRadius', 'borderStartEndRadius', 'borderEndStartRadius', 'borderEndEndRadius'];
|
|
15
15
|
var borderSizeProperties = ['borderWidth', 'outlineWidth', 'borderRightWidth', 'borderLeftWidth', 'borderTopWidth', 'borderBottomWidth', 'borderInlineWidth', 'borderBlockWidth'];
|
|
16
16
|
var radiusValueToToken = exports.radiusValueToToken = Object.fromEntries(_tokensRaw.shape.filter(function (t) {
|
|
17
|
-
return t.name.startsWith('
|
|
18
|
-
})
|
|
19
|
-
// we prefer using the default (border.radius) over its aliases
|
|
20
|
-
.filter(function (t) {
|
|
21
|
-
return !t.name.startsWith('border.radius.100');
|
|
17
|
+
return t.name.startsWith('radius');
|
|
22
18
|
}).map(function (t) {
|
|
23
19
|
return [t.value, t.cleanName];
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
);
|
|
20
|
+
})
|
|
21
|
+
// add in extra entries to resolve 3px, 50%, and 100% to tokens
|
|
22
|
+
.concat([['3px', 'radius.small'], ['50%', 'radius.full'], ['100%', 'radius.full']]));
|
|
27
23
|
var borderWidthValueToToken = exports.borderWidthValueToToken = Object.fromEntries(_tokensRaw.shape.filter(function (t) {
|
|
28
24
|
return t.name.startsWith('border.width');
|
|
29
25
|
}).map(function (t) {
|
|
@@ -68,12 +68,13 @@ var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
|
|
|
68
68
|
var _usePrimitivesText = _interopRequireDefault(require("./use-primitives-text"));
|
|
69
69
|
var _useShouldRenderToParent = _interopRequireDefault(require("./use-should-render-to-parent"));
|
|
70
70
|
var _useTagGroupLabel = _interopRequireDefault(require("./use-tag-group-label"));
|
|
71
|
+
var _useTokensShape = _interopRequireDefault(require("./use-tokens-shape"));
|
|
71
72
|
var _useTokensSpace = _interopRequireDefault(require("./use-tokens-space"));
|
|
72
73
|
var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typography"));
|
|
73
74
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
74
75
|
/**
|
|
75
76
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
76
|
-
* @codegen <<SignedSource::
|
|
77
|
+
* @codegen <<SignedSource::5fbd59fcd3fd6cb0602821de4a0a32aa>>
|
|
77
78
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
78
79
|
*/
|
|
79
80
|
|
|
@@ -141,6 +142,7 @@ var rules = exports.rules = {
|
|
|
141
142
|
'use-primitives-text': _usePrimitivesText.default,
|
|
142
143
|
'use-should-render-to-parent': _useShouldRenderToParent.default,
|
|
143
144
|
'use-tag-group-label': _useTagGroupLabel.default,
|
|
145
|
+
'use-tokens-shape': _useTokensShape.default,
|
|
144
146
|
'use-tokens-space': _useTokensSpace.default,
|
|
145
147
|
'use-tokens-typography': _useTokensTypography.default,
|
|
146
148
|
'use-visually-hidden': _useVisuallyHidden.default
|
|
@@ -30,11 +30,12 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
30
30
|
additionalProperties: false
|
|
31
31
|
}],
|
|
32
32
|
messages: {
|
|
33
|
-
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)."
|
|
33
|
+
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)."
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
create: function create(context) {
|
|
37
37
|
var _context$options$;
|
|
38
|
+
var isIconSvg = (0, _isFromImportSource.createIsFromImportSourceFor)('@atlaskit/icon/svg');
|
|
38
39
|
var isIconBase = (0, _isFromImportSource.createIsFromImportSourceFor)('@atlaskit/icon', '@atlaskit/icon/base');
|
|
39
40
|
|
|
40
41
|
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
|
|
@@ -43,14 +44,25 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
43
44
|
centralLocation = _ref$centralLocation === void 0 ? '' : _ref$centralLocation,
|
|
44
45
|
_ref$failSilently = _ref.failSilently,
|
|
45
46
|
failSilently = _ref$failSilently === void 0 ? false : _ref$failSilently;
|
|
47
|
+
function checkNode(node) {
|
|
48
|
+
isIconBase.importDeclarationHook(node);
|
|
49
|
+
isIconSvg.importDeclarationHook(node);
|
|
50
|
+
}
|
|
46
51
|
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`.") : '';
|
|
47
52
|
return (0, _errorBoundary.errorBoundary)({
|
|
48
53
|
JSXElement: function JSXElement(node) {
|
|
49
|
-
var
|
|
50
|
-
|
|
54
|
+
var isSvg = isIconSvg(node);
|
|
55
|
+
var isBase = isIconBase(node);
|
|
56
|
+
// Not an icon import
|
|
57
|
+
if (!isSvg && (!isBase || !(0, _hasProp.hasProp)(node, 'glyph'))) {
|
|
51
58
|
return;
|
|
52
59
|
}
|
|
53
|
-
var importSource =
|
|
60
|
+
var importSource = '';
|
|
61
|
+
if (isSvg) {
|
|
62
|
+
importSource = isIconSvg.getImportSource(node);
|
|
63
|
+
} else if (isBase) {
|
|
64
|
+
importSource = isIconBase.getImportSource(node);
|
|
65
|
+
}
|
|
54
66
|
context.report({
|
|
55
67
|
node: node.openingElement,
|
|
56
68
|
messageId: 'noCustomIcons',
|
|
@@ -60,7 +72,7 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
60
72
|
}
|
|
61
73
|
});
|
|
62
74
|
},
|
|
63
|
-
ImportDeclaration:
|
|
75
|
+
ImportDeclaration: checkNode
|
|
64
76
|
}, failSilently);
|
|
65
77
|
}
|
|
66
78
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _transformers = require("./transformers");
|
|
9
|
+
var rule = (0, _createRule.createLintRule)({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'use-tokens-shape',
|
|
12
|
+
type: 'problem',
|
|
13
|
+
fixable: 'code',
|
|
14
|
+
hasSuggestions: true,
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Enforces usage of shape design tokens rather than hard-coded values.',
|
|
17
|
+
recommended: false,
|
|
18
|
+
severity: 'error'
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
noRawShapeValues: 'The use of shape tokens is preferred over the direct application of border radius and border width properties.'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
create: function create(context) {
|
|
25
|
+
return {
|
|
26
|
+
'CallExpression[callee.name="css"] ObjectExpression Property': function CallExpressionCalleeNameCss_ObjectExpression_Property(node) {
|
|
27
|
+
return _transformers.StyleProperty.lint(node, {
|
|
28
|
+
context: context
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
'CallExpression[callee.name="keyframes"] ObjectExpression Property': function CallExpressionCalleeNameKeyframes_ObjectExpression_Property(node) {
|
|
32
|
+
return _transformers.StyleProperty.lint(node, {
|
|
33
|
+
context: context
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
'CallExpression[callee.name="cssMap"] ObjectExpression Property': function CallExpressionCalleeNameCssMap_ObjectExpression_Property(node) {
|
|
37
|
+
return _transformers.StyleProperty.lint(node, {
|
|
38
|
+
context: context
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
'CallExpression[callee.object.name=styled] ObjectExpression Property': function CallExpressionCalleeObjectNameStyled_ObjectExpression_Property(node) {
|
|
42
|
+
return _transformers.StyleProperty.lint(node, {
|
|
43
|
+
context: context
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
'CallExpression[callee.object.name=styled2] ObjectExpression Property': function CallExpressionCalleeObjectNameStyled2_ObjectExpression_Property(node) {
|
|
47
|
+
return _transformers.StyleProperty.lint(node, {
|
|
48
|
+
context: context
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.StyleProperty = void 0;
|
|
9
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
|
+
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
11
|
+
var _utils = require("../../use-tokens-space/utils");
|
|
12
|
+
var _styleMap = require("./style-map");
|
|
13
|
+
var _supported = _interopRequireDefault(require("./supported"));
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
15
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
16
|
+
|
|
17
|
+
var messageId = 'noRawShapeValues';
|
|
18
|
+
var StyleProperty = exports.StyleProperty = {
|
|
19
|
+
lint: function lint(node, _ref) {
|
|
20
|
+
var context = _ref.context;
|
|
21
|
+
// Check whether all criteria needed to make a transformation are met
|
|
22
|
+
var _StyleProperty$_check = StyleProperty._check(node),
|
|
23
|
+
success = _StyleProperty$_check.success,
|
|
24
|
+
ref = _StyleProperty$_check.ref;
|
|
25
|
+
if (!success) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
context.report({
|
|
29
|
+
node: ref.node.value,
|
|
30
|
+
messageId: messageId,
|
|
31
|
+
fix: ref.token ? StyleProperty._fix(ref, context) : undefined
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
_check: function _check(node) {
|
|
35
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Property')) {
|
|
36
|
+
return {
|
|
37
|
+
success: false,
|
|
38
|
+
ref: undefined
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Currently, we support values like:
|
|
44
|
+
* ```
|
|
45
|
+
* {
|
|
46
|
+
* borderRadius: '8px', // value.type is Literal
|
|
47
|
+
* borderWidth: 2, // value.type is UnaryExpression
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
if (!((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') || (0, _eslintCodemodUtils.isNodeOfType)(node.value, 'UnaryExpression'))) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
ref: undefined
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var _ast$ObjectEntry$getP = ast.ObjectEntry.getProperty(node),
|
|
58
|
+
property = _ast$ObjectEntry$getP.value;
|
|
59
|
+
|
|
60
|
+
// Bail if the property is not `borderRadius`, `borderWidth`, etc
|
|
61
|
+
if (!property || !_styleMap.styleMap[property]) {
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
ref: undefined
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var value = ast.ObjectEntry.getValue(node);
|
|
68
|
+
|
|
69
|
+
// This is mainly useful as a type guard, so the checks after don't have to have duplicate checks for other types.
|
|
70
|
+
if (!(0, _utils.isStringOrNumber)(value)) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
ref: undefined
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ignore CSS vars. See: https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/74844/overview?commentId=6741571
|
|
78
|
+
if (value.toString().startsWith('var(')) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
ref: undefined
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// There are valid values to ignore, such as `margin: auto`
|
|
86
|
+
if (_supported.default.values.ignore.includes(value)) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
ref: undefined
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Don't report on stuff like `borderRadius: '3px 8px'`.
|
|
94
|
+
// We may iterate to handle values like this in future.
|
|
95
|
+
if (value.toString().includes(' ')) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
ref: undefined
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
var ref = {
|
|
102
|
+
node: node,
|
|
103
|
+
token: _styleMap.styleMap[property][value],
|
|
104
|
+
fallback: value
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
success: true,
|
|
108
|
+
ref: ref
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* All required validation steps have been taken care of before this
|
|
113
|
+
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
114
|
+
*/
|
|
115
|
+
_fix: function _fix(ref, context) {
|
|
116
|
+
return function (fixer) {
|
|
117
|
+
var importFix = ast.Root.upsertNamedImportDeclaration({
|
|
118
|
+
module: '@atlaskit/tokens',
|
|
119
|
+
specifiers: ['token']
|
|
120
|
+
}, context, fixer);
|
|
121
|
+
var tokenCall = "token('".concat(ref.token, "')");
|
|
122
|
+
var tokenFix = fixer.replaceText(ref.node.value, tokenCall);
|
|
123
|
+
return [importFix, tokenFix].filter(function (fix) {
|
|
124
|
+
return Boolean(fix);
|
|
125
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.styleMap = void 0;
|
|
7
|
+
var radiusTokenMap = {
|
|
8
|
+
'2px': 'radius.xsmall',
|
|
9
|
+
'3px': 'radius.small',
|
|
10
|
+
'4px': 'radius.small',
|
|
11
|
+
'6px': 'radius.medium',
|
|
12
|
+
'8px': 'radius.large',
|
|
13
|
+
'12px': 'radius.xlarge',
|
|
14
|
+
'50%': 'radius.full',
|
|
15
|
+
'100%': 'radius.full',
|
|
16
|
+
2: 'radius.xsmall',
|
|
17
|
+
3: 'radius.small',
|
|
18
|
+
4: 'radius.small',
|
|
19
|
+
6: 'radius.medium',
|
|
20
|
+
8: 'radius.large',
|
|
21
|
+
12: 'radius.xlarge',
|
|
22
|
+
'0.125rem': 'radius.xsmall',
|
|
23
|
+
'0.25rem': 'radius.small',
|
|
24
|
+
'0.375rem': 'radius.medium',
|
|
25
|
+
'0.5rem': 'radius.large',
|
|
26
|
+
'0.75rem': 'radius.xlarge'
|
|
27
|
+
};
|
|
28
|
+
var borderWidthTokenMap = {
|
|
29
|
+
'1px': 'border.width'
|
|
30
|
+
};
|
|
31
|
+
var styleMap = exports.styleMap = {
|
|
32
|
+
borderRadius: radiusTokenMap,
|
|
33
|
+
borderTopLeftRadius: radiusTokenMap,
|
|
34
|
+
borderTopRightRadius: radiusTokenMap,
|
|
35
|
+
borderBottomRightRadius: radiusTokenMap,
|
|
36
|
+
borderBottomLeftRadius: radiusTokenMap,
|
|
37
|
+
borderStartStartRadius: radiusTokenMap,
|
|
38
|
+
borderStartEndRadius: radiusTokenMap,
|
|
39
|
+
borderEndStartRadius: radiusTokenMap,
|
|
40
|
+
borderEndEndRadius: radiusTokenMap,
|
|
41
|
+
borderWidth: borderWidthTokenMap,
|
|
42
|
+
borderBottomWidth: borderWidthTokenMap,
|
|
43
|
+
borderLeftWidth: borderWidthTokenMap,
|
|
44
|
+
borderRightWidth: borderWidthTokenMap,
|
|
45
|
+
borderTopWidth: borderWidthTokenMap,
|
|
46
|
+
borderBlockWidth: borderWidthTokenMap,
|
|
47
|
+
borderInlineWidth: borderWidthTokenMap,
|
|
48
|
+
outlineWidth: borderWidthTokenMap
|
|
49
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var supported = {
|
|
8
|
+
values: {
|
|
9
|
+
ignore: ['initial', 'inherit', 'unset', 'revert', 'revert-layer', 'none',
|
|
10
|
+
// outline-offset can be set to none
|
|
11
|
+
// Currently the DST opinion is that 0 is valid.
|
|
12
|
+
0, '0', '0px', '0em', '0rem']
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var _default = exports.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::
|
|
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::
|
|
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,14 +1,12 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { shape as shapeTokens } from '@atlaskit/tokens/tokens-raw';
|
|
3
|
-
const shapeProperties = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'borderRadius'];
|
|
3
|
+
const shapeProperties = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius', 'borderRadius', 'borderStartStartRadius', 'borderStartEndRadius', 'borderEndStartRadius', 'borderEndEndRadius'];
|
|
4
4
|
const borderSizeProperties = ['borderWidth', 'outlineWidth', 'borderRightWidth', 'borderLeftWidth', 'borderTopWidth', 'borderBottomWidth', 'borderInlineWidth', 'borderBlockWidth'];
|
|
5
|
-
export const radiusValueToToken = Object.fromEntries(shapeTokens.filter(t => t.name.startsWith('
|
|
6
|
-
// we prefer using the default (border.radius) over its aliases
|
|
7
|
-
.filter(t => !t.name.startsWith('border.radius.100')).map(t => {
|
|
5
|
+
export const radiusValueToToken = Object.fromEntries(shapeTokens.filter(t => t.name.startsWith('radius')).map(t => {
|
|
8
6
|
return [t.value, t.cleanName];
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
);
|
|
7
|
+
})
|
|
8
|
+
// add in extra entries to resolve 3px, 50%, and 100% to tokens
|
|
9
|
+
.concat([['3px', 'radius.small'], ['50%', 'radius.full'], ['100%', 'radius.full']]));
|
|
12
10
|
export const borderWidthValueToToken = Object.fromEntries(shapeTokens.filter(t => t.name.startsWith('border.width')).map(t => [t.value, t.cleanName]).concat([['2px', 'border.width']]));
|
|
13
11
|
export function isRadiusProperty(propertyName) {
|
|
14
12
|
return shapeProperties.includes(propertyName);
|
|
@@ -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::
|
|
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 const 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,12 +24,13 @@ const 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}}.
|
|
27
|
+
noCustomIcons: `Custom icons/svgs from {{importSource}} are no longer supported. Migrate to an icon from '@atlaskit/(icon-labs|icon/core|icon/utility)'{{locationMessage}}.
|
|
28
28
|
[Migration guide](https://hello.atlassian.net/wiki/spaces/DST/pages/3748692796/New+ADS+iconography+-+Code+migration+guide).`
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
create(context) {
|
|
32
32
|
var _context$options$;
|
|
33
|
+
const isIconSvg = createIsFromImportSourceFor('@atlaskit/icon/svg');
|
|
33
34
|
const isIconBase = createIsFromImportSourceFor('@atlaskit/icon', '@atlaskit/icon/base');
|
|
34
35
|
|
|
35
36
|
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
|
|
@@ -37,14 +38,25 @@ const rule = createLintRule({
|
|
|
37
38
|
centralLocation = '',
|
|
38
39
|
failSilently = false
|
|
39
40
|
} = (_context$options$ = context.options[0]) !== null && _context$options$ !== void 0 ? _context$options$ : {};
|
|
41
|
+
function checkNode(node) {
|
|
42
|
+
isIconBase.importDeclarationHook(node);
|
|
43
|
+
isIconSvg.importDeclarationHook(node);
|
|
44
|
+
}
|
|
40
45
|
const locationMessage = centralLocation ? `, move the icon to '${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(node) {
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
const isSvg = isIconSvg(node);
|
|
49
|
+
const isBase = isIconBase(node);
|
|
50
|
+
// Not an icon import
|
|
51
|
+
if (!isSvg && (!isBase || !hasProp(node, 'glyph'))) {
|
|
45
52
|
return;
|
|
46
53
|
}
|
|
47
|
-
|
|
54
|
+
let 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 @@ const rule = createLintRule({
|
|
|
54
66
|
}
|
|
55
67
|
});
|
|
56
68
|
},
|
|
57
|
-
ImportDeclaration:
|
|
69
|
+
ImportDeclaration: checkNode
|
|
58
70
|
}, failSilently);
|
|
59
71
|
}
|
|
60
72
|
});
|
|
@@ -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;
|