@atlaskit/eslint-plugin-design-system 8.15.5 → 8.16.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 (99) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/constellation/index/usage.mdx +62 -16
  3. package/dist/cjs/rules/prefer-primitives/index.js +2 -3
  4. package/dist/cjs/rules/prefer-primitives/utils.js +16 -5
  5. package/dist/cjs/rules/use-primitives/index.js +89 -58
  6. package/dist/cjs/rules/use-primitives/transformers/css-to-xcss.js +95 -0
  7. package/dist/cjs/rules/use-primitives/transformers/index.js +31 -0
  8. package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +26 -0
  9. package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +19 -0
  10. package/dist/cjs/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +31 -0
  11. package/dist/cjs/rules/use-primitives/utils/get-attribute-value-identifier.js +37 -0
  12. package/dist/cjs/rules/use-primitives/utils/get-function-argument-at-pos.js +10 -0
  13. package/dist/cjs/rules/use-primitives/utils/get-jsx-attribute-by-name.js +16 -0
  14. package/dist/cjs/rules/use-primitives/utils/get-variable-definition-value.js +29 -0
  15. package/dist/cjs/rules/use-primitives/utils/get-variable-usage-count.js +21 -0
  16. package/dist/cjs/rules/use-primitives/utils/index.js +89 -0
  17. package/dist/cjs/rules/use-primitives/utils/is-function-named.js +19 -0
  18. package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +13 -0
  19. package/dist/cjs/rules/use-primitives/utils/update-jsx-attribute-by-name.js +31 -0
  20. package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +16 -0
  21. package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +80 -0
  22. package/dist/es2019/rules/prefer-primitives/index.js +1 -2
  23. package/dist/es2019/rules/prefer-primitives/utils.js +11 -2
  24. package/dist/es2019/rules/use-primitives/index.js +91 -60
  25. package/dist/es2019/rules/use-primitives/transformers/css-to-xcss.js +91 -0
  26. package/dist/es2019/rules/use-primitives/transformers/index.js +2 -0
  27. package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +16 -0
  28. package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +13 -0
  29. package/dist/es2019/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +26 -0
  30. package/dist/es2019/rules/use-primitives/utils/get-attribute-value-identifier.js +32 -0
  31. package/dist/es2019/rules/use-primitives/utils/get-function-argument-at-pos.js +4 -0
  32. package/dist/es2019/rules/use-primitives/utils/get-jsx-attribute-by-name.js +10 -0
  33. package/dist/es2019/rules/use-primitives/utils/get-variable-definition-value.js +23 -0
  34. package/dist/es2019/rules/use-primitives/utils/get-variable-usage-count.js +15 -0
  35. package/dist/es2019/rules/use-primitives/utils/index.js +12 -0
  36. package/dist/es2019/rules/use-primitives/utils/is-function-named.js +13 -0
  37. package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +7 -0
  38. package/dist/es2019/rules/use-primitives/utils/update-jsx-attribute-by-name.js +26 -0
  39. package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +12 -0
  40. package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +76 -0
  41. package/dist/esm/rules/prefer-primitives/index.js +1 -2
  42. package/dist/esm/rules/prefer-primitives/utils.js +13 -2
  43. package/dist/esm/rules/use-primitives/index.js +91 -60
  44. package/dist/esm/rules/use-primitives/transformers/css-to-xcss.js +88 -0
  45. package/dist/esm/rules/use-primitives/transformers/index.js +2 -0
  46. package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +19 -0
  47. package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +13 -0
  48. package/dist/esm/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +26 -0
  49. package/dist/esm/rules/use-primitives/utils/get-attribute-value-identifier.js +32 -0
  50. package/dist/esm/rules/use-primitives/utils/get-function-argument-at-pos.js +4 -0
  51. package/dist/esm/rules/use-primitives/utils/get-jsx-attribute-by-name.js +10 -0
  52. package/dist/esm/rules/use-primitives/utils/get-variable-definition-value.js +23 -0
  53. package/dist/esm/rules/use-primitives/utils/get-variable-usage-count.js +15 -0
  54. package/dist/esm/rules/use-primitives/utils/index.js +12 -0
  55. package/dist/esm/rules/use-primitives/utils/is-function-named.js +13 -0
  56. package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +7 -0
  57. package/dist/esm/rules/use-primitives/utils/update-jsx-attribute-by-name.js +24 -0
  58. package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +10 -0
  59. package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +75 -0
  60. package/dist/types/rules/prefer-primitives/utils.d.ts +2 -1
  61. package/dist/types/rules/use-primitives/transformers/css-to-xcss.d.ts +9 -0
  62. package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -0
  63. package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +3 -0
  64. package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +2 -0
  65. package/dist/types/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +9 -0
  66. package/dist/types/rules/use-primitives/utils/get-attribute-value-identifier.d.ts +14 -0
  67. package/dist/types/rules/use-primitives/utils/get-function-argument-at-pos.d.ts +2 -0
  68. package/dist/types/rules/use-primitives/utils/get-jsx-attribute-by-name.d.ts +2 -0
  69. package/dist/types/rules/use-primitives/utils/get-variable-definition-value.d.ts +2 -0
  70. package/dist/types/rules/use-primitives/utils/get-variable-usage-count.d.ts +6 -0
  71. package/dist/types/rules/use-primitives/utils/index.d.ts +12 -0
  72. package/dist/types/rules/use-primitives/utils/is-function-named.d.ts +2 -0
  73. package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +2 -0
  74. package/dist/types/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +3 -0
  75. package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +3 -0
  76. package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +11 -0
  77. package/dist/types-ts4.5/rules/prefer-primitives/utils.d.ts +2 -1
  78. package/dist/types-ts4.5/rules/use-primitives/transformers/css-to-xcss.d.ts +9 -0
  79. package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -0
  80. package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +3 -0
  81. package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +2 -0
  82. package/dist/types-ts4.5/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +9 -0
  83. package/dist/types-ts4.5/rules/use-primitives/utils/get-attribute-value-identifier.d.ts +14 -0
  84. package/dist/types-ts4.5/rules/use-primitives/utils/get-function-argument-at-pos.d.ts +2 -0
  85. package/dist/types-ts4.5/rules/use-primitives/utils/get-jsx-attribute-by-name.d.ts +2 -0
  86. package/dist/types-ts4.5/rules/use-primitives/utils/get-variable-definition-value.d.ts +2 -0
  87. package/dist/types-ts4.5/rules/use-primitives/utils/get-variable-usage-count.d.ts +6 -0
  88. package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +12 -0
  89. package/dist/types-ts4.5/rules/use-primitives/utils/is-function-named.d.ts +2 -0
  90. package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +2 -0
  91. package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +3 -0
  92. package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +3 -0
  93. package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +11 -0
  94. package/package.json +3 -1
  95. package/dist/cjs/rules/use-primitives/utils.js +0 -364
  96. package/dist/es2019/rules/use-primitives/utils.js +0 -353
  97. package/dist/esm/rules/use-primitives/utils.js +0 -359
  98. package/dist/types/rules/use-primitives/utils.d.ts +0 -13
  99. package/dist/types-ts4.5/rules/use-primitives/utils.d.ts +0 -13
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Using Regex here because otherwise we'd need to traverse the entire AST
3
+ * We should harden this logic as we go.
4
+ */
5
+ export var getVariableUsagesCount = function getVariableUsagesCount(variableName, context) {
6
+ if (!variableName) {
7
+ return 0;
8
+ }
9
+ var source = context.getSourceCode().text;
10
+ var matches = Array.from(source.matchAll(new RegExp("[^a-z]".concat(variableName, "[^a-z]"), 'g')));
11
+
12
+ // subtract 1 because one of the matches is the variable definition:
13
+ // e.g. a regex will find two `beep`s in this: `const beep = 'hello'; console.log(beep)`
14
+ return matches.length - 1;
15
+ };
@@ -0,0 +1,12 @@
1
+ export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
+ export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
+ export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
4
+ export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
5
+ export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
6
+ export { getVariableDefinitionValue } from './get-variable-definition-value';
7
+ export { getVariableUsagesCount } from './get-variable-usage-count';
8
+ export { isFunctionNamed } from './is-function-named';
9
+ export { isValidTagName } from './is-valid-tag-name';
10
+ export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
11
+ export { updateJSXElementName } from './update-jsx-element-name';
12
+ export { upsertImportDeclaration } from './upsert-import-declaration';
@@ -0,0 +1,13 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ export var isFunctionNamed = function isFunctionNamed(node, name) {
3
+ if (!node) {
4
+ return false;
5
+ }
6
+ if (!isNodeOfType(node.node.init, 'CallExpression')) {
7
+ return false;
8
+ }
9
+ if (!isNodeOfType(node.node.init.callee, 'Identifier')) {
10
+ return false;
11
+ }
12
+ return node.node.init.callee.name === name;
13
+ };
@@ -0,0 +1,7 @@
1
+ var validPrimitiveElements = new Set(['div']);
2
+ export var isValidTagName = function isValidTagName(node) {
3
+ if (node.openingElement.name.type !== 'JSXIdentifier') {
4
+ return false;
5
+ }
6
+ return validPrimitiveElements.has(node.openingElement.name.name);
7
+ };
@@ -0,0 +1,24 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { jsxAttribute, jsxIdentifier } from 'eslint-codemod-utils';
5
+ export var updateJSXAttributeByName = function updateJSXAttributeByName(oldName, newName, node, fixer) {
6
+ var openingElement = node.openingElement;
7
+ var attributes = openingElement.attributes;
8
+ var existingAttribute = attributes.find(function (attr) {
9
+ if (attr.type !== 'JSXAttribute') {
10
+ return false;
11
+ }
12
+ if (attr.name.type !== 'JSXIdentifier') {
13
+ return false;
14
+ }
15
+ return attr.name.name === oldName;
16
+ });
17
+ if (!existingAttribute || existingAttribute.type !== 'JSXAttribute') {
18
+ return [];
19
+ }
20
+ var newAttribute = jsxAttribute(_objectSpread(_objectSpread({}, existingAttribute), {}, {
21
+ name: jsxIdentifier(newName)
22
+ }));
23
+ return fixer.replaceText(existingAttribute, newAttribute.toString());
24
+ };
@@ -0,0 +1,10 @@
1
+ import { jsxIdentifier } from 'eslint-codemod-utils';
2
+ export var updateJSXElementName = function updateJSXElementName(node, newName, fixer) {
3
+ var openingElement = node.openingElement,
4
+ closingElement = node.closingElement;
5
+ var newOpeningElement = fixer.replaceText(openingElement.name, jsxIdentifier(newName).toString());
6
+ var newClosingElement = closingElement &&
7
+ // Self closing tags, like `<div />` don't need to have the closing tag updated
8
+ fixer.replaceText(closingElement.name, jsxIdentifier(newName).toString());
9
+ return [newOpeningElement, newClosingElement];
10
+ };
@@ -0,0 +1,75 @@
1
+ import { hasImportDeclaration, insertImportDeclaration, insertImportSpecifier, isNodeOfType } from 'eslint-codemod-utils';
2
+
3
+ /**
4
+ * Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
5
+ * Add that functionality when needed.
6
+ *
7
+ * However, does handle duplicate identifiers.
8
+ */
9
+ export var upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
10
+ var packageName = _ref.packageName,
11
+ specifiers = _ref.specifiers;
12
+ // Find any imports that match the packageName
13
+ var body = context.getSourceCode().ast.body;
14
+ var existingImports = body.filter(function (node) {
15
+ if (!isNodeOfType(node, 'ImportDeclaration')) {
16
+ return false;
17
+ }
18
+ if (!hasImportDeclaration(node, packageName)) {
19
+ return false;
20
+ }
21
+ return true;
22
+ });
23
+
24
+ /**
25
+ * This can happen for cases like:
26
+ * ```
27
+ * import { Stack } from '@atlaskit/primitives'
28
+ * import type { StackProps } from '@atlaskit/primitives'
29
+ * ```
30
+ *
31
+ * Ignore these cases for now to reduce scope creep
32
+ *
33
+ * TODO: Support multiple imports
34
+ */
35
+ if (existingImports.length > 1) {
36
+ return;
37
+ }
38
+
39
+ // The import doesn't exist yet, we can just insert a whole new one
40
+ if (existingImports.length === 0) {
41
+ return fixer.insertTextBefore(body[0], "".concat(insertImportDeclaration(packageName, specifiers), ";\n"));
42
+ }
43
+
44
+ // The import exists so, modify the existing one
45
+ var existingImport = existingImports[0]; // We have already validated that only one exists
46
+
47
+ /**
48
+ * `insertImportSpecifier()` has the unfortunate implementation detail of naively adding duplicate specifiers.
49
+ * e.g. calling
50
+ * `insertImportSpecifier(importDecl, 'xcss')`
51
+ * on
52
+ * `import { Inline, xcss } from '@atlaskit/primitives'`
53
+ * will result in:
54
+ * `import { Inline, xcss, xcss } from '@atlaskit/primitives'`.
55
+ * So, we need to filter out specifiers that are already imported.
56
+ */
57
+ var uniqueImportSpecifiers = specifiers.filter(function (specifier) {
58
+ return !existingImport.specifiers.find(function (existingSpecifier) {
59
+ if (existingSpecifier.type !== 'ImportSpecifier') {
60
+ return false;
61
+ }
62
+ return existingSpecifier.imported.name === specifier;
63
+ });
64
+ });
65
+
66
+ // Ensures the import doesn't end up like: `import { Box, xcss, } from '@atlaskit/primitives';`
67
+ // which can happen if the import decl already contains all import specifiers
68
+ if (uniqueImportSpecifiers.length === 0) {
69
+ return;
70
+ }
71
+ return fixer.replaceText(existingImport, "".concat(insertImportSpecifier(existingImport,
72
+ // `insertImportSpecifier` only accepts one specifier, and we can't call it multiple times on the same import, because fixes can't overlap
73
+ // So, join the array into a string literal, and hope for the best 🤞
74
+ uniqueImportSpecifiers.join(', ')), ";\n"));
75
+ };
@@ -1,2 +1,3 @@
1
- import type { JSXElement } from 'eslint-codemod-utils';
1
+ import { type JSXElement } from 'eslint-codemod-utils';
2
+ export declare const validPrimitiveElements: Set<string>;
2
3
  export declare const shouldSuggest: (node: JSXElement) => boolean;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const cssToXcssTransformer: (node: JSXElement, context: Rule.RuleContext, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
4
+ export declare const spaceTokenMap: {
5
+ [key: string]: string;
6
+ };
7
+ export declare const supportedStylesMap: {
8
+ [key: string]: typeof spaceTokenMap;
9
+ };
@@ -0,0 +1,2 @@
1
+ export { cssToXcssTransformer, supportedStylesMap, spaceTokenMap, } from './css-to-xcss';
2
+ export { jsxElementToBoxTransformer } from './jsx-element-to-box';
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const jsxElementToBoxTransformer: (node: JSXElement, context: Rule.RuleContext) => (fixer: Rule.RuleFixer) => Rule.Fix[];
@@ -0,0 +1,2 @@
1
+ import { type JSXElement } from 'eslint-codemod-utils';
2
+ export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import { ObjectExpression } from 'eslint-codemod-utils';
3
+ export type CSSPropStyleObject = {
4
+ [key: string]: string | number;
5
+ };
6
+ /**
7
+ * Note: Not recursive. Only handles top level key/value pairs
8
+ */
9
+ export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject;
@@ -0,0 +1,14 @@
1
+ import { JSXAttribute } from 'eslint-codemod-utils';
2
+ /**
3
+ * Bit of a weird name, but the functionality is quite specific, so this is the best I could do.
4
+ * This function looks at a JSXAttribute, and returns the string representation
5
+ * of the value if it's an identifier, e.g. `css={someStyles}` would return `'someStyles'`
6
+ *
7
+ * It returns undefined if it finds anything else, like:
8
+ * - `css={[styles1, styles2]}`
9
+ * - `css={...styles}`
10
+ * - `css={styleMap[key]}`
11
+ * - `css='what even is this'`
12
+ * - etc
13
+ */
14
+ export declare const getAttributeValueIdentifier: (attr: JSXAttribute | undefined) => string | undefined;
@@ -0,0 +1,2 @@
1
+ import type { Scope } from 'eslint';
2
+ export declare const getFunctionArgumentAtPos: (node: Scope.Definition | undefined, pos: number) => any;
@@ -0,0 +1,2 @@
1
+ import { JSXAttribute, JSXOpeningElement } from 'eslint-codemod-utils';
2
+ export declare const getJSXAttributeByName: (node: JSXOpeningElement, attrName: string) => JSXAttribute | undefined;
@@ -0,0 +1,2 @@
1
+ import type { Scope } from 'eslint';
2
+ export declare const getVariableDefinitionValue: (variableDefinition: Scope.Variable | null) => Scope.Definition | undefined;
@@ -0,0 +1,6 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Using Regex here because otherwise we'd need to traverse the entire AST
4
+ * We should harden this logic as we go.
5
+ */
6
+ export declare const getVariableUsagesCount: (variableName: string | undefined, context: Rule.RuleContext) => number;
@@ -0,0 +1,12 @@
1
+ export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
+ export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
+ export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
4
+ export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
5
+ export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
6
+ export { getVariableDefinitionValue } from './get-variable-definition-value';
7
+ export { getVariableUsagesCount } from './get-variable-usage-count';
8
+ export { isFunctionNamed } from './is-function-named';
9
+ export { isValidTagName } from './is-valid-tag-name';
10
+ export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
11
+ export { updateJSXElementName } from './update-jsx-element-name';
12
+ export { upsertImportDeclaration } from './upsert-import-declaration';
@@ -0,0 +1,2 @@
1
+ import type { Scope } from 'eslint';
2
+ export declare const isFunctionNamed: (node: Scope.Definition | undefined, name: string) => boolean;
@@ -0,0 +1,2 @@
1
+ import { JSXElement } from 'eslint-codemod-utils';
2
+ export declare const isValidTagName: (node: JSXElement) => boolean;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => never[] | Rule.Fix;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const updateJSXElementName: (node: JSXElement, newName: string, fixer: Rule.RuleFixer) => (Rule.Fix | null)[];
@@ -0,0 +1,11 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
4
+ * Add that functionality when needed.
5
+ *
6
+ * However, does handle duplicate identifiers.
7
+ */
8
+ export declare const upsertImportDeclaration: ({ packageName, specifiers, }: {
9
+ packageName: string;
10
+ specifiers: string[];
11
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
@@ -1,2 +1,3 @@
1
- import type { JSXElement } from 'eslint-codemod-utils';
1
+ import { type JSXElement } from 'eslint-codemod-utils';
2
+ export declare const validPrimitiveElements: Set<string>;
2
3
  export declare const shouldSuggest: (node: JSXElement) => boolean;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const cssToXcssTransformer: (node: JSXElement, context: Rule.RuleContext, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
4
+ export declare const spaceTokenMap: {
5
+ [key: string]: string;
6
+ };
7
+ export declare const supportedStylesMap: {
8
+ [key: string]: typeof spaceTokenMap;
9
+ };
@@ -0,0 +1,2 @@
1
+ export { cssToXcssTransformer, supportedStylesMap, spaceTokenMap, } from './css-to-xcss';
2
+ export { jsxElementToBoxTransformer } from './jsx-element-to-box';
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const jsxElementToBoxTransformer: (node: JSXElement, context: Rule.RuleContext) => (fixer: Rule.RuleFixer) => Rule.Fix[];
@@ -0,0 +1,2 @@
1
+ import { type JSXElement } from 'eslint-codemod-utils';
2
+ export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import { ObjectExpression } from 'eslint-codemod-utils';
3
+ export type CSSPropStyleObject = {
4
+ [key: string]: string | number;
5
+ };
6
+ /**
7
+ * Note: Not recursive. Only handles top level key/value pairs
8
+ */
9
+ export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject;
@@ -0,0 +1,14 @@
1
+ import { JSXAttribute } from 'eslint-codemod-utils';
2
+ /**
3
+ * Bit of a weird name, but the functionality is quite specific, so this is the best I could do.
4
+ * This function looks at a JSXAttribute, and returns the string representation
5
+ * of the value if it's an identifier, e.g. `css={someStyles}` would return `'someStyles'`
6
+ *
7
+ * It returns undefined if it finds anything else, like:
8
+ * - `css={[styles1, styles2]}`
9
+ * - `css={...styles}`
10
+ * - `css={styleMap[key]}`
11
+ * - `css='what even is this'`
12
+ * - etc
13
+ */
14
+ export declare const getAttributeValueIdentifier: (attr: JSXAttribute | undefined) => string | undefined;
@@ -0,0 +1,2 @@
1
+ import type { Scope } from 'eslint';
2
+ export declare const getFunctionArgumentAtPos: (node: Scope.Definition | undefined, pos: number) => any;
@@ -0,0 +1,2 @@
1
+ import { JSXAttribute, JSXOpeningElement } from 'eslint-codemod-utils';
2
+ export declare const getJSXAttributeByName: (node: JSXOpeningElement, attrName: string) => JSXAttribute | undefined;
@@ -0,0 +1,2 @@
1
+ import type { Scope } from 'eslint';
2
+ export declare const getVariableDefinitionValue: (variableDefinition: Scope.Variable | null) => Scope.Definition | undefined;
@@ -0,0 +1,6 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Using Regex here because otherwise we'd need to traverse the entire AST
4
+ * We should harden this logic as we go.
5
+ */
6
+ export declare const getVariableUsagesCount: (variableName: string | undefined, context: Rule.RuleContext) => number;
@@ -0,0 +1,12 @@
1
+ export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
+ export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
+ export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
4
+ export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
5
+ export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
6
+ export { getVariableDefinitionValue } from './get-variable-definition-value';
7
+ export { getVariableUsagesCount } from './get-variable-usage-count';
8
+ export { isFunctionNamed } from './is-function-named';
9
+ export { isValidTagName } from './is-valid-tag-name';
10
+ export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
11
+ export { updateJSXElementName } from './update-jsx-element-name';
12
+ export { upsertImportDeclaration } from './upsert-import-declaration';
@@ -0,0 +1,2 @@
1
+ import type { Scope } from 'eslint';
2
+ export declare const isFunctionNamed: (node: Scope.Definition | undefined, name: string) => boolean;
@@ -0,0 +1,2 @@
1
+ import { JSXElement } from 'eslint-codemod-utils';
2
+ export declare const isValidTagName: (node: JSXElement) => boolean;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => never[] | Rule.Fix;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare const updateJSXElementName: (node: JSXElement, newName: string, fixer: Rule.RuleFixer) => (Rule.Fix | null)[];
@@ -0,0 +1,11 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
4
+ * Add that functionality when needed.
5
+ *
6
+ * However, does handle duplicate identifiers.
7
+ */
8
+ export declare const upsertImportDeclaration: ({ packageName, specifiers, }: {
9
+ packageName: string;
10
+ specifiers: string[];
11
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "8.15.5",
4
+ "version": "8.16.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"
@@ -54,8 +54,10 @@
54
54
  "@emotion/styled": "^11.0.0",
55
55
  "@types/eslint": "^8.4.5",
56
56
  "eslint": "^7.7.0",
57
+ "jscodeshift": "^0.13.0",
57
58
  "prettier": "^2.8.0",
58
59
  "react": "^16.8.0",
60
+ "ts-jest": "26.5.6",
59
61
  "ts-node": "^10.9.1",
60
62
  "tsconfig-paths": "^4.2.0",
61
63
  "typescript": "~4.9.5"