@atlaskit/eslint-plugin-design-system 8.15.5 → 8.17.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 +12 -0
- package/constellation/index/usage.mdx +62 -16
- package/dist/cjs/rules/prefer-primitives/index.js +2 -3
- package/dist/cjs/rules/prefer-primitives/utils.js +16 -5
- package/dist/cjs/rules/use-primitives/index.js +89 -58
- package/dist/cjs/rules/use-primitives/transformers/css-to-xcss.js +95 -0
- package/dist/cjs/rules/use-primitives/transformers/index.js +31 -0
- package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +26 -0
- package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +19 -0
- package/dist/cjs/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +31 -0
- package/dist/cjs/rules/use-primitives/utils/get-attribute-value-identifier.js +37 -0
- package/dist/cjs/rules/use-primitives/utils/get-function-argument-at-pos.js +10 -0
- package/dist/cjs/rules/use-primitives/utils/get-jsx-attribute-by-name.js +16 -0
- package/dist/cjs/rules/use-primitives/utils/get-variable-definition-value.js +29 -0
- package/dist/cjs/rules/use-primitives/utils/get-variable-usage-count.js +21 -0
- package/dist/cjs/rules/use-primitives/utils/index.js +89 -0
- package/dist/cjs/rules/use-primitives/utils/is-function-named.js +19 -0
- package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +13 -0
- package/dist/cjs/rules/use-primitives/utils/update-jsx-attribute-by-name.js +31 -0
- package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +16 -0
- package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +80 -0
- package/dist/es2019/rules/prefer-primitives/index.js +1 -2
- package/dist/es2019/rules/prefer-primitives/utils.js +11 -2
- package/dist/es2019/rules/use-primitives/index.js +91 -60
- package/dist/es2019/rules/use-primitives/transformers/css-to-xcss.js +91 -0
- package/dist/es2019/rules/use-primitives/transformers/index.js +2 -0
- package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +16 -0
- package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +13 -0
- package/dist/es2019/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +26 -0
- package/dist/es2019/rules/use-primitives/utils/get-attribute-value-identifier.js +32 -0
- package/dist/es2019/rules/use-primitives/utils/get-function-argument-at-pos.js +4 -0
- package/dist/es2019/rules/use-primitives/utils/get-jsx-attribute-by-name.js +10 -0
- package/dist/es2019/rules/use-primitives/utils/get-variable-definition-value.js +23 -0
- package/dist/es2019/rules/use-primitives/utils/get-variable-usage-count.js +15 -0
- package/dist/es2019/rules/use-primitives/utils/index.js +12 -0
- package/dist/es2019/rules/use-primitives/utils/is-function-named.js +13 -0
- package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +7 -0
- package/dist/es2019/rules/use-primitives/utils/update-jsx-attribute-by-name.js +26 -0
- package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +12 -0
- package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +76 -0
- package/dist/esm/rules/prefer-primitives/index.js +1 -2
- package/dist/esm/rules/prefer-primitives/utils.js +13 -2
- package/dist/esm/rules/use-primitives/index.js +91 -60
- package/dist/esm/rules/use-primitives/transformers/css-to-xcss.js +88 -0
- package/dist/esm/rules/use-primitives/transformers/index.js +2 -0
- package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +19 -0
- package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +13 -0
- package/dist/esm/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +26 -0
- package/dist/esm/rules/use-primitives/utils/get-attribute-value-identifier.js +32 -0
- package/dist/esm/rules/use-primitives/utils/get-function-argument-at-pos.js +4 -0
- package/dist/esm/rules/use-primitives/utils/get-jsx-attribute-by-name.js +10 -0
- package/dist/esm/rules/use-primitives/utils/get-variable-definition-value.js +23 -0
- package/dist/esm/rules/use-primitives/utils/get-variable-usage-count.js +15 -0
- package/dist/esm/rules/use-primitives/utils/index.js +12 -0
- package/dist/esm/rules/use-primitives/utils/is-function-named.js +13 -0
- package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +7 -0
- package/dist/esm/rules/use-primitives/utils/update-jsx-attribute-by-name.js +24 -0
- package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +10 -0
- package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +75 -0
- package/dist/types/rules/prefer-primitives/utils.d.ts +2 -1
- package/dist/types/rules/use-primitives/transformers/css-to-xcss.d.ts +9 -0
- package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -0
- package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +3 -0
- package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +2 -0
- package/dist/types/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +9 -0
- package/dist/types/rules/use-primitives/utils/get-attribute-value-identifier.d.ts +14 -0
- package/dist/types/rules/use-primitives/utils/get-function-argument-at-pos.d.ts +2 -0
- package/dist/types/rules/use-primitives/utils/get-jsx-attribute-by-name.d.ts +2 -0
- package/dist/types/rules/use-primitives/utils/get-variable-definition-value.d.ts +2 -0
- package/dist/types/rules/use-primitives/utils/get-variable-usage-count.d.ts +6 -0
- package/dist/types/rules/use-primitives/utils/index.d.ts +12 -0
- package/dist/types/rules/use-primitives/utils/is-function-named.d.ts +2 -0
- package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +2 -0
- package/dist/types/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +3 -0
- package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +3 -0
- package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +11 -0
- package/dist/types-ts4.5/rules/prefer-primitives/utils.d.ts +2 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/css-to-xcss.d.ts +9 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +9 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/get-attribute-value-identifier.d.ts +14 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/get-function-argument-at-pos.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/get-jsx-attribute-by-name.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/get-variable-definition-value.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/get-variable-usage-count.d.ts +6 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +12 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/is-function-named.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +11 -0
- package/package.json +3 -1
- package/dist/cjs/rules/use-primitives/utils.js +0 -364
- package/dist/es2019/rules/use-primitives/utils.js +0 -353
- package/dist/esm/rules/use-primitives/utils.js +0 -359
- package/dist/types/rules/use-primitives/utils.d.ts +0 -13
- 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,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
|
+
};
|
|
@@ -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,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,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,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;
|
|
@@ -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
|
+
};
|
package/dist/types-ts4.5/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts
ADDED
|
@@ -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,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,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.
|
|
4
|
+
"version": "8.17.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"
|