@atlaskit/eslint-plugin-design-system 13.31.0 → 13.32.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 (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -2
  4. package/dist/cjs/presets/all.codegen.js +2 -2
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -2
  6. package/dist/cjs/presets/recommended.codegen.js +2 -2
  7. package/dist/cjs/rules/index.codegen.js +3 -3
  8. package/dist/cjs/rules/no-placeholder/index.js +162 -0
  9. package/dist/es2019/presets/all-flat.codegen.js +2 -2
  10. package/dist/es2019/presets/all.codegen.js +2 -2
  11. package/dist/es2019/presets/recommended-flat.codegen.js +2 -2
  12. package/dist/es2019/presets/recommended.codegen.js +2 -2
  13. package/dist/es2019/rules/index.codegen.js +3 -3
  14. package/dist/es2019/rules/no-placeholder/index.js +142 -0
  15. package/dist/esm/presets/all-flat.codegen.js +2 -2
  16. package/dist/esm/presets/all.codegen.js +2 -2
  17. package/dist/esm/presets/recommended-flat.codegen.js +2 -2
  18. package/dist/esm/presets/recommended.codegen.js +2 -2
  19. package/dist/esm/rules/index.codegen.js +3 -3
  20. package/dist/esm/rules/no-placeholder/index.js +154 -0
  21. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  22. package/dist/types/presets/all.codegen.d.ts +1 -1
  23. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
  24. package/dist/types/presets/recommended.codegen.d.ts +1 -1
  25. package/dist/types/rules/index.codegen.d.ts +1 -1
  26. package/dist/types/rules/no-placeholder/index.d.ts +6 -0
  27. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
  28. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  29. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -1
  30. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
  31. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  32. package/dist/types-ts4.5/rules/no-placeholder/index.d.ts +6 -0
  33. package/package.json +2 -2
  34. package/dist/cjs/rules/no-utility-icons/checks.js +0 -246
  35. package/dist/cjs/rules/no-utility-icons/index.js +0 -49
  36. package/dist/es2019/rules/no-utility-icons/checks.js +0 -177
  37. package/dist/es2019/rules/no-utility-icons/index.js +0 -44
  38. package/dist/esm/rules/no-utility-icons/checks.js +0 -239
  39. package/dist/esm/rules/no-utility-icons/index.js +0 -43
  40. package/dist/types/rules/no-utility-icons/checks.d.ts +0 -10
  41. package/dist/types/rules/no-utility-icons/index.d.ts +0 -3
  42. package/dist/types-ts4.5/rules/no-utility-icons/checks.d.ts +0 -10
  43. package/dist/types-ts4.5/rules/no-utility-icons/index.d.ts +0 -3
@@ -1,239 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- 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; } } }; }
3
- 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; } }
4
- 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; }
5
- import { isNodeOfType } from 'eslint-codemod-utils';
6
- var specialCases = {
7
- '@atlaskit/icon/utility/migration/cross--editor-close': '@atlaskit/icon/core/migration/cross--editor-close'
8
- };
9
- var iconPropsinNewButton = ['icon', 'iconBefore', 'iconAfter'];
10
- export var createChecks = function createChecks(context) {
11
- var importStatementsUtility = {};
12
- var importStatementsCore = {};
13
- var newButtonImports = new Set();
14
- var errors = {};
15
-
16
- /**
17
- * Gets the value of a boolean configuration flag
18
- * @param key the key of the configuration flag
19
- * @param defaultValue The default value of the configuration flag
20
- * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
21
- */
22
- var getConfigFlag = function getConfigFlag(key, defaultValue) {
23
- if (context.options && context.options.length > 0 && context.options[0] && context.options[0].hasOwnProperty(key)) {
24
- return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
25
- }
26
- return defaultValue;
27
- };
28
- var checkImportDeclarations = function checkImportDeclarations(node) {
29
- var moduleSource = node.source.value;
30
- if (typeof moduleSource !== 'string') {
31
- return;
32
- }
33
- if (moduleSource.startsWith('@atlaskit/icon/utility/')) {
34
- var _iterator = _createForOfIteratorHelper(node.specifiers),
35
- _step;
36
- try {
37
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
38
- var specifier = _step.value;
39
- if (specifier.type === 'ImportDefaultSpecifier') {
40
- importStatementsUtility[specifier.local.name] = node;
41
- }
42
- }
43
- } catch (err) {
44
- _iterator.e(err);
45
- } finally {
46
- _iterator.f();
47
- }
48
- } else if (moduleSource.startsWith('@atlaskit/icon/core/')) {
49
- var _iterator2 = _createForOfIteratorHelper(node.specifiers),
50
- _step2;
51
- try {
52
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
53
- var _specifier = _step2.value;
54
- if (_specifier.type === 'ImportDefaultSpecifier') {
55
- importStatementsCore[moduleSource] = {
56
- node: node,
57
- localName: _specifier.local.name
58
- };
59
- }
60
- }
61
- } catch (err) {
62
- _iterator2.e(err);
63
- } finally {
64
- _iterator2.f();
65
- }
66
- } else if (moduleSource.startsWith('@atlaskit/button/')) {
67
- var _iterator3 = _createForOfIteratorHelper(node.specifiers),
68
- _step3;
69
- try {
70
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
71
- var _specifier2 = _step3.value;
72
- newButtonImports.add(_specifier2.local.name);
73
- }
74
- } catch (err) {
75
- _iterator3.e(err);
76
- } finally {
77
- _iterator3.f();
78
- }
79
- }
80
- };
81
- var checkJSXElement = function checkJSXElement(node) {
82
- if (!(isNodeOfType(node, 'JSXElement') && isNodeOfType(node.openingElement.name, 'JSXIdentifier') && importStatementsUtility.hasOwnProperty(node.openingElement.name.name) && typeof importStatementsUtility[node.openingElement.name.name].source.value === 'string')) {
83
- return;
84
- }
85
- if (!errors.hasOwnProperty(node.openingElement.name.name)) {
86
- errors[node.openingElement.name.name] = [];
87
- }
88
- errors[node.openingElement.name.name].push({
89
- node: node,
90
- messageId: 'noUtilityIconsJSXElement',
91
- localName: node.openingElement.name.name,
92
- fixable: true,
93
- inNewButton: false
94
- });
95
- };
96
-
97
- // Cases: As Props, In Function Calls, In Arrays, In Maps, In Exports
98
- var checkIconReference = function checkIconReference(node) {
99
- //if this is an import statement then exit early
100
- if (node.parent && (isNodeOfType(node.parent, 'ImportSpecifier') || isNodeOfType(node.parent, 'ImportDefaultSpecifier'))) {
101
- return;
102
- }
103
-
104
- //check the reference to see if it's a utility icon, if not exit early
105
- if (!importStatementsUtility.hasOwnProperty(node.name)) {
106
- return;
107
- }
108
-
109
- // if it is in new Button then we can fix it
110
- if (node.parent && node.parent.parent && node.parent.parent.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && isNodeOfType(node.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && iconPropsinNewButton.includes(node.parent.parent.name.name) && isNodeOfType(node.parent.parent.parent, 'JSXOpeningElement') && isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name)) {
111
- // if it is in new Button then we can fix it
112
- if (!errors.hasOwnProperty(node.name)) {
113
- errors[node.name] = [];
114
- }
115
- errors[node.name].push({
116
- node: node,
117
- messageId: 'noUtilityIconsReference',
118
- localName: node.name,
119
- fixable: true,
120
- inNewButton: true
121
- });
122
- return;
123
- }
124
-
125
- // manually error
126
- if (!errors.hasOwnProperty(node.name)) {
127
- errors[node.name] = [];
128
- }
129
- errors[node.name].push({
130
- node: node,
131
- messageId: 'noUtilityIconsReference',
132
- localName: node.name,
133
- fixable: false,
134
- inNewButton: false
135
- });
136
- };
137
-
138
- /**
139
- * Throws the relevant errors in the correct order.
140
- */
141
- var throwErrors = function throwErrors() {
142
- var shouldAutoFix = getConfigFlag('enableAutoFixer', false);
143
- var _loop = function _loop() {
144
- var utilityIcon = _Object$keys[_i];
145
- var allFixable = errors[utilityIcon].every(function (x) {
146
- return x.fixable;
147
- }); // Check if ALL errors for a giving import are fixable
148
- var originalImportNode = importStatementsUtility[utilityIcon];
149
- var oldImportName = importStatementsUtility[utilityIcon].source.value;
150
- var newImportName = specialCases.hasOwnProperty(oldImportName) ? specialCases[oldImportName] : oldImportName.replace('@atlaskit/icon/utility/', '@atlaskit/icon/core/');
151
- var existingImport = importStatementsCore.hasOwnProperty(newImportName) ? importStatementsCore[newImportName].localName : null;
152
- var replacementImportName = existingImport ? existingImport : allFixable ? utilityIcon : "".concat(utilityIcon, "Core");
153
- var importFixAdded = false;
154
- var _iterator4 = _createForOfIteratorHelper(errors[utilityIcon].entries()),
155
- _step4;
156
- try {
157
- var _loop2 = function _loop2() {
158
- var _step4$value = _slicedToArray(_step4.value, 2),
159
- index = _step4$value[0],
160
- error = _step4$value[1];
161
- if (error.fixable && shouldAutoFix) {
162
- context.report({
163
- node: error.node,
164
- messageId: error.messageId,
165
- fix: function fix(fixer) {
166
- var fixes = [];
167
-
168
- // Add a new import statement if it doesn't already exist
169
- if (!existingImport && !importFixAdded) {
170
- importFixAdded = true;
171
- fixes.push(fixer.insertTextBefore(originalImportNode, "import ".concat(replacementImportName, " from '").concat(newImportName, "';\n")));
172
- }
173
-
174
- // Handle JSX elements differently if they are in a "new Button"
175
- if (error.inNewButton) {
176
- // Replace the icon with a function that wraps it with iconProps and size="small"
177
- var wrappedIcon = "(iconProps) => <".concat(replacementImportName, " {...iconProps} size=\"small\" />");
178
- fixes.push(fixer.replaceText(error.node, wrappedIcon));
179
- } else if (isNodeOfType(error.node, 'JSXElement') && isNodeOfType(error.node.openingElement.name, 'JSXIdentifier')) {
180
- // Replace the JSX element's closing tag with size="small"
181
- var newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, " size=\"small\"/>").replace(new RegExp('<s*' + error.node.openingElement.name.name), "<".concat(replacementImportName));
182
- fixes.push(fixer.replaceText(error.node.openingElement, newOpeningElementText));
183
- }
184
-
185
- // Handle the first fixable error for import removal if all fixable for this import
186
- if (index === 0 && allFixable) {
187
- fixes.push(fixer.remove(originalImportNode));
188
- }
189
- return fixes;
190
- }
191
- });
192
- } else {
193
- // Report non-fixable errors
194
- context.report({
195
- node: error.node,
196
- messageId: error.messageId
197
- });
198
- }
199
- };
200
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
201
- _loop2();
202
- }
203
- } catch (err) {
204
- _iterator4.e(err);
205
- } finally {
206
- _iterator4.f();
207
- }
208
- };
209
- for (var _i = 0, _Object$keys = Object.keys(errors); _i < _Object$keys.length; _i++) {
210
- _loop();
211
- }
212
-
213
- // If other utility icons are imported but there were no errors for them - (this should only be unused imports but good to have as a backup), report them
214
- var otherUtilityImportsWithoutErrors = Object.keys(importStatementsUtility).filter(function (utilityIcon) {
215
- return !errors.hasOwnProperty(utilityIcon);
216
- });
217
- var _iterator5 = _createForOfIteratorHelper(otherUtilityImportsWithoutErrors),
218
- _step5;
219
- try {
220
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
221
- var utilityIcon = _step5.value;
222
- context.report({
223
- node: importStatementsUtility[utilityIcon],
224
- messageId: 'noUtilityIconsImport'
225
- });
226
- }
227
- } catch (err) {
228
- _iterator5.e(err);
229
- } finally {
230
- _iterator5.f();
231
- }
232
- };
233
- return {
234
- checkImportDeclarations: checkImportDeclarations,
235
- checkJSXElement: checkJSXElement,
236
- checkIconReference: checkIconReference,
237
- throwErrors: throwErrors
238
- };
239
- };
@@ -1,43 +0,0 @@
1
- import { createLintRule } from '../utils/create-rule';
2
- import { createChecks } from './checks';
3
- var rule = createLintRule({
4
- meta: {
5
- name: 'no-utility-icons',
6
- fixable: 'code',
7
- hasSuggestions: true,
8
- type: 'problem',
9
- schema: [{
10
- type: 'object',
11
- properties: {
12
- enableAutoFixer: {
13
- type: 'boolean'
14
- }
15
- },
16
- additionalProperties: false
17
- }],
18
- docs: {
19
- description: 'Disallow use of deprecated utility icons, in favor of core icons with `size="small"`.',
20
- recommended: true,
21
- severity: 'warn'
22
- },
23
- messages: {
24
- noUtilityIconsJSXElement: "Utility icons are deprecated. Please use core icons instead with the size prop set to small.",
25
- noUtilityIconsImport: "Utility icons are deprecated. Please do not import them, use core icons instead.",
26
- noUtilityIconsReference: "Utility icons are deprecated. To replace them, please use core icons with the size prop set to small instead."
27
- }
28
- },
29
- create: function create(context) {
30
- var _createChecks = createChecks(context),
31
- checkImportDeclarations = _createChecks.checkImportDeclarations,
32
- checkJSXElement = _createChecks.checkJSXElement,
33
- checkIconReference = _createChecks.checkIconReference,
34
- throwErrors = _createChecks.throwErrors;
35
- return {
36
- ImportDeclaration: checkImportDeclarations,
37
- JSXElement: checkJSXElement,
38
- Identifier: checkIconReference,
39
- 'Program:exit': throwErrors
40
- };
41
- }
42
- });
43
- export default rule;
@@ -1,10 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { type Identifier, type ImportDeclaration } from 'eslint-codemod-utils';
3
- type ReturnObject = {
4
- checkImportDeclarations: (node: ImportDeclaration) => void;
5
- checkJSXElement: (node: Rule.Node) => void;
6
- checkIconReference: (node: Identifier & Rule.NodeParentExtension) => void;
7
- throwErrors: () => void;
8
- };
9
- export declare const createChecks: (context: Rule.RuleContext) => ReturnObject;
10
- export {};
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- declare const rule: Rule.RuleModule;
3
- export default rule;
@@ -1,10 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { type Identifier, type ImportDeclaration } from 'eslint-codemod-utils';
3
- type ReturnObject = {
4
- checkImportDeclarations: (node: ImportDeclaration) => void;
5
- checkJSXElement: (node: Rule.Node) => void;
6
- checkIconReference: (node: Identifier & Rule.NodeParentExtension) => void;
7
- throwErrors: () => void;
8
- };
9
- export declare const createChecks: (context: Rule.RuleContext) => ReturnObject;
10
- export {};
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- declare const rule: Rule.RuleModule;
3
- export default rule;