@atlaskit/eslint-plugin-design-system 10.24.1 → 10.26.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 +23 -0
- package/README.md +2 -1
- package/dist/cjs/ast-nodes/jsx-attribute.js +8 -0
- package/dist/cjs/presets/all-flat.codegen.js +2 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-deprecated-imports/checks.js +201 -0
- package/dist/cjs/rules/no-deprecated-imports/constants.js +8 -0
- package/dist/cjs/rules/no-deprecated-imports/handlers/icon.js +204 -0
- package/dist/cjs/rules/no-deprecated-imports/index.js +25 -118
- package/dist/cjs/rules/use-datetime-picker-calendar-button/index.js +187 -0
- package/dist/cjs/rules/utils/get-deprecated-config.js +9 -1
- package/dist/es2019/ast-nodes/jsx-attribute.js +8 -0
- package/dist/es2019/presets/all-flat.codegen.js +2 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-deprecated-imports/checks.js +175 -0
- package/dist/es2019/rules/no-deprecated-imports/constants.js +2 -0
- package/dist/es2019/rules/no-deprecated-imports/handlers/icon.js +153 -0
- package/dist/es2019/rules/no-deprecated-imports/index.js +23 -103
- package/dist/es2019/rules/use-datetime-picker-calendar-button/index.js +173 -0
- package/dist/es2019/rules/utils/get-deprecated-config.js +12 -1
- package/dist/esm/ast-nodes/jsx-attribute.js +8 -0
- package/dist/esm/presets/all-flat.codegen.js +2 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended-flat.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-deprecated-imports/checks.js +195 -0
- package/dist/esm/rules/no-deprecated-imports/constants.js +2 -0
- package/dist/esm/rules/no-deprecated-imports/handlers/icon.js +197 -0
- package/dist/esm/rules/no-deprecated-imports/index.js +23 -117
- package/dist/esm/rules/use-datetime-picker-calendar-button/index.js +181 -0
- package/dist/esm/rules/utils/get-deprecated-config.js +9 -1
- package/dist/types/ast-nodes/jsx-attribute.d.ts +3 -0
- package/dist/types/index.codegen.d.ts +14 -9
- package/dist/types/presets/all-flat.codegen.d.ts +2 -1
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended-flat.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +2 -3
- package/dist/types/rules/no-deprecated-imports/checks.d.ts +11 -0
- package/dist/types/rules/no-deprecated-imports/constants.d.ts +2 -0
- package/dist/types/rules/no-deprecated-imports/handlers/icon.d.ts +38 -0
- package/dist/types/rules/no-deprecated-imports/index.d.ts +1 -7
- package/dist/types/rules/use-datetime-picker-calendar-button/index.d.ts +7 -0
- package/dist/types/rules/utils/types.d.ts +1 -0
- package/dist/types-ts4.5/ast-nodes/jsx-attribute.d.ts +3 -0
- package/dist/types-ts4.5/index.codegen.d.ts +14 -15
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -5
- package/dist/types-ts4.5/rules/no-deprecated-imports/checks.d.ts +11 -0
- package/dist/types-ts4.5/rules/no-deprecated-imports/constants.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-deprecated-imports/handlers/icon.d.ts +38 -0
- package/dist/types-ts4.5/rules/no-deprecated-imports/index.d.ts +1 -9
- package/dist/types-ts4.5/rules/use-datetime-picker-calendar-button/index.d.ts +7 -0
- package/dist/types-ts4.5/rules/utils/types.d.ts +1 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 10.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#162725](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162725)
|
|
8
|
+
[`b2449424247a3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b2449424247a3) -
|
|
9
|
+
Updated `no-deprecated-icons` lint rule to include deprecated icons and auto fix for icons that
|
|
10
|
+
have a replacement
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
16
|
+
## 10.25.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- [#165487](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/165487)
|
|
21
|
+
[`0e99fc2e1f211`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0e99fc2e1f211) -
|
|
22
|
+
Add new rule for `@atlaskit/datetime-picker`. Ensures that the calendar button is used when
|
|
23
|
+
possible to ensure the picker is accessible. Part of AUTOMAT campaign to migrate all AFM instances
|
|
24
|
+
of date picker and date time picker to use new `shouldShowCalendarButton` prop.
|
|
25
|
+
|
|
3
26
|
## 10.24.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ module.exports = {
|
|
|
60
60
|
| <a href="./src/rules/no-dark-theme-vr-tests/README.md">no-dark-theme-vr-tests</a> | Disallow using dark colorScheme in VR tests. | | Yes | |
|
|
61
61
|
| <a href="./src/rules/no-deprecated-apis/README.md">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
|
|
62
62
|
| <a href="./src/rules/no-deprecated-design-token-usage/README.md">no-deprecated-design-token-usage</a> | Disallow using deprecated design tokens. | Yes | Yes | |
|
|
63
|
-
| <a href="./src/rules/no-deprecated-imports/README.md">no-deprecated-imports</a> | Disallow importing deprecated modules. | Yes | |
|
|
63
|
+
| <a href="./src/rules/no-deprecated-imports/README.md">no-deprecated-imports</a> | Disallow importing deprecated modules. | Yes | Yes | Yes |
|
|
64
64
|
| <a href="./src/rules/no-direct-use-of-web-platform-drag-and-drop/README.md">no-direct-use-of-web-platform-drag-and-drop</a> | Disallow using direct use of native drag and drop (please use Pragmatic drag and drop) | Yes | | |
|
|
65
65
|
| <a href="./src/rules/no-empty-styled-expression/README.md">no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | | | |
|
|
66
66
|
| <a href="./src/rules/no-exported-css/README.md">no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | | | |
|
|
@@ -80,6 +80,7 @@ module.exports = {
|
|
|
80
80
|
| <a href="./src/rules/no-unsupported-drag-and-drop-libraries/README.md">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
|
|
81
81
|
| <a href="./src/rules/prefer-primitives/README.md">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
|
|
82
82
|
| <a href="./src/rules/use-button-group-label/README.md">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
|
|
83
|
+
| <a href="./src/rules/use-datetime-picker-calendar-button/README.md">use-datetime-picker-calendar-button</a> | Encourages makers to use calendar button in Atlassian Design System's date picker and datetime picker components. | Yes | Yes | Yes |
|
|
83
84
|
| <a href="./src/rules/use-drawer-label/README.md">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
|
|
84
85
|
| <a href="./src/rules/use-heading/README.md">use-heading</a> | Encourage the usage of heading components. | | Yes | Yes |
|
|
85
86
|
| <a href="./src/rules/use-heading-level-in-spotlight-card/README.md">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
|
|
@@ -52,6 +52,14 @@ var HelperJSXAttribute = exports.JSXAttribute = {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// handle `css={true}`
|
|
56
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(node.value.expression, 'Literal')) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'ExpressionStatement Literal',
|
|
59
|
+
value: node.value.expression.value
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
// handle `css='myStyles'`
|
|
56
64
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && node.value.value) {
|
|
57
65
|
var _node$value$value;
|
|
@@ -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::72c978e91d268fe1463898bd263385bc>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -43,6 +43,7 @@ var _default = exports.default = {
|
|
|
43
43
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
44
44
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
45
45
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
46
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
46
47
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
47
48
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
48
49
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
@@ -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::5bfdac53d9eb0cc8f885ce996861719e>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -42,6 +42,7 @@ var _default = exports.default = {
|
|
|
42
42
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
43
43
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
44
44
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
45
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
45
46
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
46
47
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
47
48
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
@@ -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::2c1f5cd2494143a83d590243d7ebf539>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -32,6 +32,7 @@ var _default = exports.default = {
|
|
|
32
32
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
33
33
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
34
34
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
35
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
35
36
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
36
37
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
37
38
|
'@atlaskit/design-system/use-href-in-link-item': 'warn',
|
|
@@ -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::9aeb2fd0b5bde21f6ef61b407d0d32ab>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -31,6 +31,7 @@ var _default = exports.default = {
|
|
|
31
31
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
32
32
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
33
33
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
34
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
34
35
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
35
36
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
36
37
|
'@atlaskit/design-system/use-href-in-link-item': 'warn',
|
|
@@ -36,6 +36,7 @@ var _noUnsafeStyleOverrides = _interopRequireDefault(require("./no-unsafe-style-
|
|
|
36
36
|
var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-unsupported-drag-and-drop-libraries"));
|
|
37
37
|
var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
|
|
38
38
|
var _useButtonGroupLabel = _interopRequireDefault(require("./use-button-group-label"));
|
|
39
|
+
var _useDatetimePickerCalendarButton = _interopRequireDefault(require("./use-datetime-picker-calendar-button"));
|
|
39
40
|
var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
|
|
40
41
|
var _useHeading = _interopRequireDefault(require("./use-heading"));
|
|
41
42
|
var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-heading-level-in-spotlight-card"));
|
|
@@ -53,7 +54,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
|
|
|
53
54
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
54
55
|
/**
|
|
55
56
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
56
|
-
* @codegen <<SignedSource::
|
|
57
|
+
* @codegen <<SignedSource::50c700a7a1e85949b0e5136a8c576c72>>
|
|
57
58
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
58
59
|
*/
|
|
59
60
|
|
|
@@ -89,6 +90,7 @@ var rules = exports.rules = {
|
|
|
89
90
|
'no-unsupported-drag-and-drop-libraries': _noUnsupportedDragAndDropLibraries.default,
|
|
90
91
|
'prefer-primitives': _preferPrimitives.default,
|
|
91
92
|
'use-button-group-label': _useButtonGroupLabel.default,
|
|
93
|
+
'use-datetime-picker-calendar-button': _useDatetimePickerCalendarButton.default,
|
|
92
94
|
'use-drawer-label': _useDrawerLabel.default,
|
|
93
95
|
'use-heading': _useHeading.default,
|
|
94
96
|
'use-heading-level-in-spotlight-card': _useHeadingLevelInSpotlightCard.default,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createChecks = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var _getDeprecatedConfig = require("../utils/get-deprecated-config");
|
|
9
|
+
var _types = require("../utils/types");
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
var _icon = require("./handlers/icon");
|
|
12
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
var createChecks = exports.createChecks = function createChecks(context) {
|
|
16
|
+
var deprecatedIconHandler = (0, _icon.getDeprecationIconHandler)(context);
|
|
17
|
+
var throwErrors = function throwErrors() {
|
|
18
|
+
deprecatedIconHandler.throwErrors();
|
|
19
|
+
};
|
|
20
|
+
var getHandler = function getHandler(importSource) {
|
|
21
|
+
if (importSource.startsWith('@atlaskit/icon')) {
|
|
22
|
+
return deprecatedIconHandler;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Report a restricted path.
|
|
28
|
+
* @param {string} importSource path of the import
|
|
29
|
+
* @param {string} type whether the node is an import or export
|
|
30
|
+
* @param {node} node representing the restricted path reference
|
|
31
|
+
* @param {Map<string,TSESTree.Node>} importNames Map of import names that are being imported
|
|
32
|
+
* @returns {void}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
function checkRestrictedPathAndReport(_ref) {
|
|
36
|
+
var _context$options$;
|
|
37
|
+
var importSource = _ref.importSource,
|
|
38
|
+
type = _ref.type,
|
|
39
|
+
node = _ref.node,
|
|
40
|
+
importNames = _ref.importNames;
|
|
41
|
+
var restrictedPathMessages = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.deprecatedConfig) || (0, _getDeprecatedConfig.getConfig)('imports');
|
|
42
|
+
if (!(0, _types.isDeprecatedImportConfig)(restrictedPathMessages)) {
|
|
43
|
+
throw new Error('Config is invalid for deprecated imports');
|
|
44
|
+
}
|
|
45
|
+
if (!Object.prototype.hasOwnProperty.call(restrictedPathMessages, importSource)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var config = restrictedPathMessages[importSource];
|
|
49
|
+
var handler = getHandler(importSource);
|
|
50
|
+
if (handler) {
|
|
51
|
+
if (type === 'import') {
|
|
52
|
+
handler.createImportError({
|
|
53
|
+
node: node,
|
|
54
|
+
importSource: importSource,
|
|
55
|
+
config: config
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
handler.createExportError({
|
|
59
|
+
node: node,
|
|
60
|
+
importSource: importSource,
|
|
61
|
+
config: config
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// Default behaviour
|
|
66
|
+
// The message will only exist if the import is completely banned,
|
|
67
|
+
// eg a deprecated package
|
|
68
|
+
if ('message' in config) {
|
|
69
|
+
context.report({
|
|
70
|
+
node: node,
|
|
71
|
+
messageId: _constants.pathWithCustomMessageId,
|
|
72
|
+
data: {
|
|
73
|
+
importSource: importSource,
|
|
74
|
+
customMessage: config.message
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// if there are specific named exports that are banned,
|
|
80
|
+
// iterate through and check if they're being imported
|
|
81
|
+
if ('importSpecifiers' in config) {
|
|
82
|
+
var _config$importSpecifi;
|
|
83
|
+
(_config$importSpecifi = config.importSpecifiers) === null || _config$importSpecifi === void 0 || _config$importSpecifi.forEach(function (restrictedImport) {
|
|
84
|
+
if (importNames.has(restrictedImport.importName)) {
|
|
85
|
+
context.report({
|
|
86
|
+
node: importNames.get(restrictedImport.importName),
|
|
87
|
+
messageId: _constants.importNameWithCustomMessageId,
|
|
88
|
+
data: {
|
|
89
|
+
importName: restrictedImport.importName,
|
|
90
|
+
importSource: importSource,
|
|
91
|
+
customMessage: restrictedImport.message
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Checks a node to see if any problems should be reported.
|
|
102
|
+
* @param {ASTNode} node The node to check.
|
|
103
|
+
* @returns {void}
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
var checkImportNode = function checkImportNode(node) {
|
|
107
|
+
var importSource = node.source.value.trim();
|
|
108
|
+
var importNames = new Map();
|
|
109
|
+
if ('specifiers' in node) {
|
|
110
|
+
var _iterator = _createForOfIteratorHelper(node.specifiers),
|
|
111
|
+
_step;
|
|
112
|
+
try {
|
|
113
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
114
|
+
var specifier = _step.value;
|
|
115
|
+
var name = void 0;
|
|
116
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
117
|
+
name = 'default';
|
|
118
|
+
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
119
|
+
name = '*';
|
|
120
|
+
} else if (specifier.type === 'ImportSpecifier') {
|
|
121
|
+
name = specifier.imported.name;
|
|
122
|
+
}
|
|
123
|
+
if (name) {
|
|
124
|
+
importNames.set(name, specifier);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
_iterator.e(err);
|
|
129
|
+
} finally {
|
|
130
|
+
_iterator.f();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
checkRestrictedPathAndReport({
|
|
134
|
+
importSource: importSource,
|
|
135
|
+
type: 'import',
|
|
136
|
+
node: node,
|
|
137
|
+
importNames: importNames
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Checks a node to see if any problems should be reported.
|
|
143
|
+
* @param {ASTNode} node The node to check.
|
|
144
|
+
* @returns {void}
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
var checkExportNode = function checkExportNode(node) {
|
|
148
|
+
if (!node.source || !node.source.value) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
var importSource = node.source.value.trim();
|
|
152
|
+
var importNames = new Map();
|
|
153
|
+
if ('specifiers' in node) {
|
|
154
|
+
var _iterator2 = _createForOfIteratorHelper(node.specifiers),
|
|
155
|
+
_step2;
|
|
156
|
+
try {
|
|
157
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
158
|
+
var specifier = _step2.value;
|
|
159
|
+
var name = void 0;
|
|
160
|
+
if (specifier.local) {
|
|
161
|
+
name = specifier.local.name;
|
|
162
|
+
}
|
|
163
|
+
if (name) {
|
|
164
|
+
importNames.set(name, specifier);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} catch (err) {
|
|
168
|
+
_iterator2.e(err);
|
|
169
|
+
} finally {
|
|
170
|
+
_iterator2.f();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
checkRestrictedPathAndReport({
|
|
174
|
+
importSource: importSource,
|
|
175
|
+
type: 'export',
|
|
176
|
+
node: node,
|
|
177
|
+
importNames: importNames
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Create a mapping of JSX elements by their name so they can be processed later.
|
|
183
|
+
* @param node The JSX node found by ESLint
|
|
184
|
+
*/
|
|
185
|
+
var checkJSXElement = function checkJSXElement(node) {
|
|
186
|
+
if (!('openingElement' in node) || !(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
deprecatedIconHandler.checkJSXElement(node);
|
|
190
|
+
};
|
|
191
|
+
var checkIdentifier = function checkIdentifier(node) {
|
|
192
|
+
deprecatedIconHandler.checkIdentifier(node);
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
checkImportNode: checkImportNode,
|
|
196
|
+
checkExportNode: checkExportNode,
|
|
197
|
+
checkJSXElement: checkJSXElement,
|
|
198
|
+
checkIdentifier: checkIdentifier,
|
|
199
|
+
throwErrors: throwErrors
|
|
200
|
+
};
|
|
201
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pathWithCustomMessageId = exports.importNameWithCustomMessageId = void 0;
|
|
7
|
+
var importNameWithCustomMessageId = exports.importNameWithCustomMessageId = 'importNameWithCustomMessage';
|
|
8
|
+
var pathWithCustomMessageId = exports.pathWithCustomMessageId = 'pathWithCustomMessage';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getDeprecationIconHandler = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
|
+
var _metadata3 = _interopRequireDefault(require("@atlaskit/icon-lab/metadata"));
|
|
11
|
+
var _metadata4 = require("@atlaskit/icon/metadata");
|
|
12
|
+
var _constants = require("../constants");
|
|
13
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
/**
|
|
17
|
+
* __Deprecation icon handler__
|
|
18
|
+
*
|
|
19
|
+
* A deprecation icon handler which is responsible for displaying an error for deprecated icons.
|
|
20
|
+
* It also includes a fixer to replace the deprecated icon with the new icon if a replacement exists.
|
|
21
|
+
*/
|
|
22
|
+
var getDeprecationIconHandler = exports.getDeprecationIconHandler = function getDeprecationIconHandler(context) {
|
|
23
|
+
var jsxElements = new Map();
|
|
24
|
+
var identifiers = new Map();
|
|
25
|
+
var importErrors = {};
|
|
26
|
+
var exportErrors = {};
|
|
27
|
+
var getIconComponentName = function getIconComponentName(name) {
|
|
28
|
+
return name.split(/\W/).map(function (part) {
|
|
29
|
+
return "".concat(part[0].toUpperCase()).concat(part.slice(1));
|
|
30
|
+
}).join('').concat('Icon');
|
|
31
|
+
};
|
|
32
|
+
var createImportError = function createImportError(_ref) {
|
|
33
|
+
var node = _ref.node,
|
|
34
|
+
importSource = _ref.importSource,
|
|
35
|
+
config = _ref.config;
|
|
36
|
+
if (config.message) {
|
|
37
|
+
var myError = {
|
|
38
|
+
node: node,
|
|
39
|
+
messageId: _constants.pathWithCustomMessageId,
|
|
40
|
+
data: {
|
|
41
|
+
importSource: importSource,
|
|
42
|
+
customMessage: config.message,
|
|
43
|
+
unfixable: config.unfixable ? 'true' : 'false'
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
importErrors[node.source.value] = myError;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var createExportError = function createExportError(_ref2) {
|
|
50
|
+
var node = _ref2.node,
|
|
51
|
+
importSource = _ref2.importSource,
|
|
52
|
+
config = _ref2.config;
|
|
53
|
+
if (config.message) {
|
|
54
|
+
var myError = {
|
|
55
|
+
node: node,
|
|
56
|
+
messageId: _constants.pathWithCustomMessageId,
|
|
57
|
+
data: {
|
|
58
|
+
importSource: importSource,
|
|
59
|
+
customMessage: config.message
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exportErrors[importSource] = myError;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var throwErrors = function throwErrors() {
|
|
66
|
+
for (var _i = 0, _Object$entries = Object.entries(importErrors); _i < _Object$entries.length; _i++) {
|
|
67
|
+
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
68
|
+
importSource = _Object$entries$_i[0],
|
|
69
|
+
error = _Object$entries$_i[1];
|
|
70
|
+
if (importSource.includes('/migration/')) {
|
|
71
|
+
var _metadata$deprecatedI, _error$data;
|
|
72
|
+
var _importSource$split$s = importSource.split('/').slice(1),
|
|
73
|
+
_importSource$split$s2 = (0, _slicedToArray2.default)(_importSource$split$s, 4),
|
|
74
|
+
_location = _importSource$split$s2[0],
|
|
75
|
+
type = _importSource$split$s2[1],
|
|
76
|
+
_migration = _importSource$split$s2[2],
|
|
77
|
+
name = _importSource$split$s2[3];
|
|
78
|
+
var metadata = type === 'core' ? _metadata4.coreIconMetadata : _metadata4.utilityIconMetadata;
|
|
79
|
+
var _name$split = name.split('--'),
|
|
80
|
+
_name$split2 = (0, _slicedToArray2.default)(_name$split, 2),
|
|
81
|
+
deprecatedIconName = _name$split2[0],
|
|
82
|
+
legacyIconName = _name$split2[1];
|
|
83
|
+
var replacement = metadata === null || metadata === void 0 || (_metadata$deprecatedI = metadata[deprecatedIconName]) === null || _metadata$deprecatedI === void 0 ? void 0 : _metadata$deprecatedI.replacement;
|
|
84
|
+
if (replacement && ((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.unfixable) === 'false') {
|
|
85
|
+
var newIconName = getIconComponentName(replacement.name);
|
|
86
|
+
addAutoFix(error, importSource, "".concat(replacement.location, "/").concat(replacement.type, "/migration/").concat(replacement.name, "--").concat(legacyIconName), newIconName);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
var _metadata2;
|
|
90
|
+
var _importSource$split$s3 = importSource.split('/').slice(1),
|
|
91
|
+
_importSource$split$s4 = (0, _slicedToArray2.default)(_importSource$split$s3, 3),
|
|
92
|
+
location = _importSource$split$s4[0],
|
|
93
|
+
_type = _importSource$split$s4[1],
|
|
94
|
+
_name = _importSource$split$s4[2];
|
|
95
|
+
var _metadata = void 0;
|
|
96
|
+
if (location === 'icon') {
|
|
97
|
+
_metadata = _type === 'core' ? _metadata4.coreIconMetadata : _metadata4.utilityIconMetadata;
|
|
98
|
+
} else if (location === 'icon-lab') {
|
|
99
|
+
_metadata = _metadata3.default;
|
|
100
|
+
}
|
|
101
|
+
var _replacement = (_metadata2 = _metadata) === null || _metadata2 === void 0 || (_metadata2 = _metadata2[_name]) === null || _metadata2 === void 0 ? void 0 : _metadata2.replacement;
|
|
102
|
+
if (_replacement) {
|
|
103
|
+
var _newIconName = getIconComponentName(_replacement.name);
|
|
104
|
+
addAutoFix(error, importSource, "".concat(_replacement.location, "/").concat(_replacement.type, "/").concat(_replacement.name), _newIconName);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
context.report(error);
|
|
108
|
+
}
|
|
109
|
+
for (var _i2 = 0, _Object$values = Object.values(exportErrors); _i2 < _Object$values.length; _i2++) {
|
|
110
|
+
var _error = _Object$values[_i2];
|
|
111
|
+
context.report(_error);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var addAutoFix = function addAutoFix(error, importSource, newImportSource, newIconName) {
|
|
115
|
+
error.fix = function (fixer) {
|
|
116
|
+
var fixes = [];
|
|
117
|
+
|
|
118
|
+
//Find and update all usages of this icon in JSX with the replacement icon
|
|
119
|
+
var jsxUsageNodes = jsxElements.get(importSource);
|
|
120
|
+
if (jsxUsageNodes) {
|
|
121
|
+
var _iterator = _createForOfIteratorHelper(jsxUsageNodes),
|
|
122
|
+
_step;
|
|
123
|
+
try {
|
|
124
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
125
|
+
var usageNode = _step.value;
|
|
126
|
+
fixes.push(fixer.replaceText(usageNode.openingElement.name, newIconName));
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
_iterator.e(err);
|
|
130
|
+
} finally {
|
|
131
|
+
_iterator.f();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//Find and update all usages of this icon in identifiers with the replacement icon
|
|
136
|
+
var usageNodes = identifiers.get(importSource);
|
|
137
|
+
if (usageNodes) {
|
|
138
|
+
var _iterator2 = _createForOfIteratorHelper(usageNodes),
|
|
139
|
+
_step2;
|
|
140
|
+
try {
|
|
141
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
142
|
+
var _usageNode = _step2.value;
|
|
143
|
+
fixes.push(fixer.replaceText(_usageNode.parent, "{".concat(newIconName, "}")));
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
_iterator2.e(err);
|
|
147
|
+
} finally {
|
|
148
|
+
_iterator2.f();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
fixes.push(fixer.replaceText(error.node, "".concat((0, _eslintCodemodUtils.literal)("import ".concat(newIconName, " from '").concat(newImportSource, "'")), ";")));
|
|
152
|
+
return fixes;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
var checkJSXElement = function checkJSXElement(node) {
|
|
156
|
+
if (!('openingElement' in node) || !(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
for (var _i3 = 0, _Object$entries2 = Object.entries(importErrors); _i3 < _Object$entries2.length; _i3++) {
|
|
160
|
+
var _Object$entries2$_i = (0, _slicedToArray2.default)(_Object$entries2[_i3], 2),
|
|
161
|
+
importSource = _Object$entries2$_i[0],
|
|
162
|
+
error = _Object$entries2$_i[1];
|
|
163
|
+
var importIconName = error.node.specifiers[0].local.name;
|
|
164
|
+
var iconName = node.openingElement.name.name;
|
|
165
|
+
if (iconName === importIconName) {
|
|
166
|
+
if (jsxElements.has(importSource)) {
|
|
167
|
+
var _jsxElements$get;
|
|
168
|
+
(_jsxElements$get = jsxElements.get(importSource)) === null || _jsxElements$get === void 0 || _jsxElements$get.push(node);
|
|
169
|
+
} else {
|
|
170
|
+
jsxElements.set(importSource, [node]);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var checkIdentifier = function checkIdentifier(node) {
|
|
177
|
+
if (node.type !== 'Identifier' || node.parent.type !== 'JSXExpressionContainer') {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
for (var _i4 = 0, _Object$entries3 = Object.entries(importErrors); _i4 < _Object$entries3.length; _i4++) {
|
|
181
|
+
var _Object$entries3$_i = (0, _slicedToArray2.default)(_Object$entries3[_i4], 2),
|
|
182
|
+
importSource = _Object$entries3$_i[0],
|
|
183
|
+
error = _Object$entries3$_i[1];
|
|
184
|
+
var importIconName = error.node.specifiers[0].local.name;
|
|
185
|
+
var iconName = node.name;
|
|
186
|
+
if (iconName === importIconName) {
|
|
187
|
+
if (identifiers.has(importSource)) {
|
|
188
|
+
var _identifiers$get;
|
|
189
|
+
(_identifiers$get = identifiers.get(importSource)) === null || _identifiers$get === void 0 || _identifiers$get.push(node);
|
|
190
|
+
} else {
|
|
191
|
+
identifiers.set(importSource, [node]);
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
createImportError: createImportError,
|
|
199
|
+
createExportError: createExportError,
|
|
200
|
+
checkJSXElement: checkJSXElement,
|
|
201
|
+
checkIdentifier: checkIdentifier,
|
|
202
|
+
throwErrors: throwErrors
|
|
203
|
+
};
|
|
204
|
+
};
|