@atlaskit/eslint-plugin-design-system 10.25.0 → 11.0.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 (38) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/rules/no-deprecated-imports/checks.js +201 -0
  4. package/dist/cjs/rules/no-deprecated-imports/constants.js +8 -0
  5. package/dist/cjs/rules/no-deprecated-imports/handlers/icon.js +204 -0
  6. package/dist/cjs/rules/no-deprecated-imports/index.js +25 -118
  7. package/dist/cjs/rules/use-tokens-typography/config/index.js +3 -1
  8. package/dist/cjs/rules/utils/create-no-tagged-template-expression-rule/index.js +3 -0
  9. package/dist/cjs/rules/utils/get-deprecated-config.js +9 -1
  10. package/dist/es2019/rules/no-deprecated-imports/checks.js +175 -0
  11. package/dist/es2019/rules/no-deprecated-imports/constants.js +2 -0
  12. package/dist/es2019/rules/no-deprecated-imports/handlers/icon.js +153 -0
  13. package/dist/es2019/rules/no-deprecated-imports/index.js +23 -103
  14. package/dist/es2019/rules/use-tokens-typography/config/index.js +3 -1
  15. package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/index.js +3 -0
  16. package/dist/es2019/rules/utils/get-deprecated-config.js +12 -1
  17. package/dist/esm/rules/no-deprecated-imports/checks.js +195 -0
  18. package/dist/esm/rules/no-deprecated-imports/constants.js +2 -0
  19. package/dist/esm/rules/no-deprecated-imports/handlers/icon.js +197 -0
  20. package/dist/esm/rules/no-deprecated-imports/index.js +23 -117
  21. package/dist/esm/rules/use-tokens-typography/config/index.js +3 -1
  22. package/dist/esm/rules/utils/create-no-tagged-template-expression-rule/index.js +3 -0
  23. package/dist/esm/rules/utils/get-deprecated-config.js +9 -1
  24. package/dist/types/index.codegen.d.ts +3 -9
  25. package/dist/types/rules/index.codegen.d.ts +1 -3
  26. package/dist/types/rules/no-deprecated-imports/checks.d.ts +11 -0
  27. package/dist/types/rules/no-deprecated-imports/constants.d.ts +2 -0
  28. package/dist/types/rules/no-deprecated-imports/handlers/icon.d.ts +38 -0
  29. package/dist/types/rules/no-deprecated-imports/index.d.ts +1 -7
  30. package/dist/types/rules/utils/types.d.ts +1 -0
  31. package/dist/types-ts4.5/index.codegen.d.ts +3 -15
  32. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -5
  33. package/dist/types-ts4.5/rules/no-deprecated-imports/checks.d.ts +11 -0
  34. package/dist/types-ts4.5/rules/no-deprecated-imports/constants.d.ts +2 -0
  35. package/dist/types-ts4.5/rules/no-deprecated-imports/handlers/icon.d.ts +38 -0
  36. package/dist/types-ts4.5/rules/no-deprecated-imports/index.d.ts +1 -9
  37. package/dist/types-ts4.5/rules/utils/types.d.ts +1 -0
  38. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 11.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#168980](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/168980)
8
+ [`d9aae425eae69`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d9aae425eae69) -
9
+ `use-tokens-typography` defaults not adding token fallbacks anymore. Automatic fallbacks can still
10
+ be enabled by setting the `shouldEnforceFallbacks: true` config option.
11
+
12
+ ## 10.26.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#162725](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162725)
17
+ [`b2449424247a3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b2449424247a3) -
18
+ Updated `no-deprecated-icons` lint rule to include deprecated icons and auto fix for icons that
19
+ have a replacement
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+
3
25
  ## 10.25.0
4
26
 
5
27
  ### Minor 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. | | | |
@@ -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
+ };
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.pathWithCustomMessageId = exports.name = exports.importNameWithCustomMessageId = exports.default = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
6
+ exports.name = exports.default = void 0;
9
7
  var _createRule = require("../utils/create-rule");
10
- var _getDeprecatedConfig = require("../utils/get-deprecated-config");
11
- var _types = require("../utils/types");
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; } /**
8
+ var _errorBoundary = require("../utils/error-boundary");
9
+ var _checks = require("./checks");
10
+ /**
15
11
  * Forked from original `no-restricted-imports` although the source has been substantially changed.
16
12
  *
17
13
  * To ensure compliance the license from eslint has been included and the original attribution.
@@ -37,19 +33,18 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
37
33
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38
34
  * THE SOFTWARE.
39
35
  */
36
+
40
37
  var name = exports.name = 'no-deprecated-imports';
41
- var importNameWithCustomMessageId = exports.importNameWithCustomMessageId = 'importNameWithCustomMessage';
42
- var pathWithCustomMessageId = exports.pathWithCustomMessageId = 'pathWithCustomMessage';
43
- var rule = (0, _createRule.createRule)({
44
- name: name,
45
- defaultOptions: [{
46
- deprecatedConfig: (0, _getDeprecatedConfig.getConfig)('imports')
47
- }],
38
+ var rule = (0, _createRule.createLintRule)({
48
39
  meta: {
40
+ name: name,
41
+ fixable: 'code',
42
+ hasSuggestions: true,
49
43
  type: 'suggestion',
50
44
  docs: {
51
45
  description: 'Disallow importing deprecated modules.',
52
- recommended: 'error'
46
+ recommended: true,
47
+ severity: 'error'
53
48
  },
54
49
  messages: {
55
50
  pathWithCustomMessage: "'{{importSource}}' import is restricted from being used. {{customMessage}}",
@@ -89,108 +84,20 @@ var rule = (0, _createRule.createRule)({
89
84
  }
90
85
  }]
91
86
  },
92
- create: function create(context, _ref) {
93
- var _context$options$;
94
- var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
95
- options = _ref2[0];
96
- var defaultDeprecatedConfig = options.deprecatedConfig;
97
- var restrictedPathMessages = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.deprecatedConfig) || defaultDeprecatedConfig;
98
- if (!(0, _types.isDeprecatedImportConfig)(restrictedPathMessages)) {
99
- throw new Error('Config is invalid for deprecated imports');
100
- }
101
-
102
- /**
103
- * Report a restricted path.
104
- * @param {string} importSource path of the import
105
- * @param {node} node representing the restricted path reference
106
- * @param {Map<string,TSESTree.Node>} importNames Map of import names that are being imported
107
- * @returns {void}
108
- * @private
109
- */
110
- function checkRestrictedPathAndReport(importSource, node, importNames) {
111
- if (!Object.prototype.hasOwnProperty.call(restrictedPathMessages, importSource)) {
112
- return;
113
- }
114
- var config = restrictedPathMessages[importSource];
115
-
116
- // The message will only exist if the import is completely banned,
117
- // eg a deprecated package
118
- if ('message' in config) {
119
- context.report({
120
- node: node,
121
- messageId: pathWithCustomMessageId,
122
- data: {
123
- importSource: importSource,
124
- customMessage: config.message
125
- }
126
- });
127
- }
128
-
129
- // if there are specific named exports that are banned,
130
- // iterate through and check if they're being imported
131
- if ('importSpecifiers' in config) {
132
- var _config$importSpecifi;
133
- (_config$importSpecifi = config.importSpecifiers) === null || _config$importSpecifi === void 0 || _config$importSpecifi.forEach(function (restrictedImport) {
134
- if (importNames.has(restrictedImport.importName)) {
135
- context.report({
136
- node: importNames.get(restrictedImport.importName),
137
- messageId: importNameWithCustomMessageId,
138
- data: {
139
- importName: restrictedImport.importName,
140
- importSource: importSource,
141
- customMessage: restrictedImport.message
142
- }
143
- });
144
- }
145
- });
146
- }
147
- }
148
-
149
- /**
150
- * Checks a node to see if any problems should be reported.
151
- * @param {ASTNode} node The node to check.
152
- * @returns {void}
153
- * @private
154
- */
155
- var checkNode = function checkNode(node) {
156
- var importSource = node.source.value.trim();
157
- var importNames = new Map();
158
- if ('specifiers' in node) {
159
- var _iterator = _createForOfIteratorHelper(node.specifiers),
160
- _step;
161
- try {
162
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
163
- var specifier = _step.value;
164
- var _name = void 0;
165
- if (specifier.type === 'ImportDefaultSpecifier') {
166
- _name = 'default';
167
- } else if (specifier.type === 'ImportNamespaceSpecifier') {
168
- _name = '*';
169
- } else if (specifier.type === 'ImportSpecifier') {
170
- _name = specifier.imported.name;
171
- } else if (specifier.local) {
172
- _name = specifier.local.name;
173
- }
174
- if (_name) {
175
- importNames.set(_name, specifier);
176
- }
177
- }
178
- } catch (err) {
179
- _iterator.e(err);
180
- } finally {
181
- _iterator.f();
182
- }
183
- }
184
- checkRestrictedPathAndReport(importSource, node, importNames);
185
- };
186
- return {
187
- ImportDeclaration: checkNode,
188
- ExportNamedDeclaration: function ExportNamedDeclaration(node) {
189
- if (node.source) {
190
- checkNode(node);
191
- }
192
- }
193
- };
87
+ create: function create(context) {
88
+ var _createChecks = (0, _checks.createChecks)(context),
89
+ checkImportNode = _createChecks.checkImportNode,
90
+ checkExportNode = _createChecks.checkExportNode,
91
+ checkJSXElement = _createChecks.checkJSXElement,
92
+ checkIdentifier = _createChecks.checkIdentifier,
93
+ throwErrors = _createChecks.throwErrors;
94
+ return (0, _errorBoundary.errorBoundary)({
95
+ ImportDeclaration: checkImportNode,
96
+ ExportNamedDeclaration: checkExportNode,
97
+ JSXElement: checkJSXElement,
98
+ Identifier: checkIdentifier,
99
+ 'Program:exit': throwErrors
100
+ });
194
101
  }
195
102
  });
196
103
  var _default = exports.default = rule;
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ruleSchema = exports.getConfig = void 0;
7
+ /* eslint-disable @atlassian/tangerine/import/entry-points */
8
+
7
9
  var ruleSchema = exports.ruleSchema = {
8
10
  type: 'array',
9
11
  items: {
@@ -23,7 +25,7 @@ var ruleSchema = exports.ruleSchema = {
23
25
  };
24
26
  var defaultConfig = {
25
27
  failSilently: false,
26
- shouldEnforceFallbacks: true,
28
+ shouldEnforceFallbacks: false,
27
29
  enableUnsafeAutofix: false
28
30
  };
29
31
  var getConfig = exports.getConfig = function getConfig(overrides) {
@@ -11,7 +11,10 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
11
11
  var _generate = require("./generate");
12
12
  var _getTaggedTemplateExpressionOffset = require("./get-tagged-template-expression-offset");
13
13
  var _toArguments = require("./to-arguments");
14
+ /* eslint-disable @atlassian/tangerine/import/entry-points */
15
+
14
16
  // Original source from Compiled https://github.com/atlassian-labs/compiled/blob/master/packages/eslint-plugin/src/utils/create-no-tagged-template-expression-rule/index.ts
17
+
15
18
  // eslint-disable-next-line import/no-extraneous-dependencies
16
19
 
17
20
  var noTaggedTemplateExpressionRuleSchema = exports.noTaggedTemplateExpressionRuleSchema = [{