@atlaskit/eslint-plugin-design-system 8.34.0 → 8.36.1
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 +28 -0
- package/constellation/use-primitives-text/usage.mdx +13 -3
- package/dist/cjs/rules/ensure-design-token-usage/color.js +5 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/find-valid-jsx-usage-to-transform.js +24 -1
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +2 -1
- package/dist/cjs/rules/use-primitives-text/config/index.js +2 -1
- package/dist/cjs/rules/use-primitives-text/transformers/common.js +10 -1
- package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +6 -3
- package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +19 -4
- package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +6 -4
- package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +6 -3
- package/dist/cjs/rules/utils/is-node.js +18 -1
- package/dist/es2019/rules/ensure-design-token-usage/color.js +6 -1
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/find-valid-jsx-usage-to-transform.js +17 -3
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +2 -1
- package/dist/es2019/rules/use-primitives-text/config/index.js +2 -1
- package/dist/es2019/rules/use-primitives-text/transformers/common.js +9 -2
- package/dist/es2019/rules/use-primitives-text/transformers/emphasis-elements.js +7 -4
- package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +20 -5
- package/dist/es2019/rules/use-primitives-text/transformers/span-elements.js +7 -5
- package/dist/es2019/rules/use-primitives-text/transformers/strong-elements.js +7 -4
- package/dist/es2019/rules/utils/is-node.js +17 -0
- package/dist/esm/rules/ensure-design-token-usage/color.js +6 -1
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/find-valid-jsx-usage-to-transform.js +23 -2
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +2 -1
- package/dist/esm/rules/use-primitives-text/config/index.js +2 -1
- package/dist/esm/rules/use-primitives-text/transformers/common.js +9 -2
- package/dist/esm/rules/use-primitives-text/transformers/emphasis-elements.js +7 -4
- package/dist/esm/rules/use-primitives-text/transformers/paragraph-elements.js +20 -5
- package/dist/esm/rules/use-primitives-text/transformers/span-elements.js +7 -5
- package/dist/esm/rules/use-primitives-text/transformers/strong-elements.js +7 -4
- package/dist/esm/rules/utils/is-node.js +17 -0
- package/dist/types/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types/rules/use-primitives/transformers/compiled-styled/find-valid-jsx-usage-to-transform.d.ts +3 -1
- package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
- package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -2
- package/dist/types/rules/use-primitives-text/config/index.d.ts +1 -0
- package/dist/types/rules/use-primitives-text/transformers/common.d.ts +6 -0
- package/dist/types/rules/use-primitives-text/transformers/emphasis-elements.d.ts +2 -10
- package/dist/types/rules/use-primitives-text/transformers/paragraph-elements.d.ts +4 -12
- package/dist/types/rules/use-primitives-text/transformers/span-elements.d.ts +2 -10
- package/dist/types/rules/use-primitives-text/transformers/strong-elements.d.ts +2 -10
- package/dist/types/rules/use-tokens-typography/utils.d.ts +33 -0
- package/dist/types/rules/utils/is-node.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/find-valid-jsx-usage-to-transform.d.ts +3 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -2
- package/dist/types-ts4.5/rules/use-primitives-text/config/index.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/common.d.ts +6 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/emphasis-elements.d.ts +2 -10
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/paragraph-elements.d.ts +4 -12
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/span-elements.d.ts +2 -10
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/strong-elements.d.ts +2 -10
- package/dist/types-ts4.5/rules/use-tokens-typography/utils.d.ts +33 -0
- package/dist/types-ts4.5/rules/utils/is-node.d.ts +1 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import * as ast from '../../../ast-nodes';
|
|
5
5
|
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
6
|
-
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
6
|
+
import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
7
7
|
export const StrongElements = {
|
|
8
8
|
lint(node, {
|
|
9
9
|
context,
|
|
@@ -26,7 +26,8 @@ export const StrongElements = {
|
|
|
26
26
|
suggest: [{
|
|
27
27
|
desc: `Convert to Text`,
|
|
28
28
|
fix: StrongElements._fix(node, {
|
|
29
|
-
context
|
|
29
|
+
context,
|
|
30
|
+
config
|
|
30
31
|
})
|
|
31
32
|
}]
|
|
32
33
|
});
|
|
@@ -56,7 +57,8 @@ export const StrongElements = {
|
|
|
56
57
|
return true;
|
|
57
58
|
},
|
|
58
59
|
_fix(node, {
|
|
59
|
-
context
|
|
60
|
+
context,
|
|
61
|
+
config
|
|
60
62
|
}) {
|
|
61
63
|
return fixer => {
|
|
62
64
|
const importFix = upsertImportDeclaration({
|
|
@@ -65,8 +67,9 @@ export const StrongElements = {
|
|
|
65
67
|
}, context, fixer);
|
|
66
68
|
const elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
67
69
|
const asAttributeFix = ast.JSXElement.addAttribute(node, 'as', 'strong', fixer);
|
|
70
|
+
const colorAttributeFix = addColorInheritAttributeFix(node, config, fixer);
|
|
68
71
|
const testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
69
|
-
return [importFix, ...elementNameFixes, asAttributeFix, testAttributeFix].filter(fix => Boolean(fix)); // Some of the transformers can return arrays with undefined, so filter them out
|
|
72
|
+
return [importFix, ...elementNameFixes, asAttributeFix, colorAttributeFix, testAttributeFix].filter(fix => Boolean(fix)); // Some of the transformers can return arrays with undefined, so filter them out
|
|
70
73
|
};
|
|
71
74
|
}
|
|
72
75
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
+
import { Root } from '../../ast-nodes';
|
|
4
5
|
export const isDecendantOfGlobalToken = node => {
|
|
5
6
|
if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
|
|
6
7
|
return true;
|
|
@@ -47,6 +48,22 @@ export const isDecendantOfSvgElement = node => {
|
|
|
47
48
|
}
|
|
48
49
|
return false;
|
|
49
50
|
};
|
|
51
|
+
export const isDecendantOfPrimitive = (node, context) => {
|
|
52
|
+
const primitivesToCheck = ['Box', 'Text'];
|
|
53
|
+
if (isNodeOfType(node, 'JSXElement')) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
if (primitivesToCheck.includes(node.openingElement.name.name)) {
|
|
56
|
+
const importDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
57
|
+
if (importDeclaration.length) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (node.parent) {
|
|
63
|
+
return isDecendantOfPrimitive(node.parent, context);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
50
67
|
const cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
51
68
|
export const isCssInJsTemplateNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
52
69
|
export const isCssInJsCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name);
|
|
@@ -4,7 +4,7 @@ import { node as generate, isNodeOfType } from 'eslint-codemod-utils';
|
|
|
4
4
|
import { getIsException } from '../utils/get-is-exception';
|
|
5
5
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
6
6
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
7
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
7
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfPrimitive, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
8
8
|
// TemplateLiteral > Identifier
|
|
9
9
|
export var lintTemplateIdentifierForColor = function lintTemplateIdentifierForColor(node, context, config) {
|
|
10
10
|
if (node.type !== 'Identifier') {
|
|
@@ -137,6 +137,11 @@ export var lintJSXLiteralForColor = function lintJSXLiteralForColor(node, contex
|
|
|
137
137
|
if (isDecendantOfSvgElement(node.parent)) {
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
// Box backgroundColor prop accepts token names directly - don't lint against this
|
|
142
|
+
if (isDecendantOfPrimitive(node.parent, context)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
140
145
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
141
146
|
return;
|
|
142
147
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
+
var JSX_IDENTIFIER = 'JSXIdentifier';
|
|
3
4
|
/**
|
|
4
5
|
* Given a component name finds its JSX usages and performs some
|
|
5
6
|
* additional validations to ensure transformation can be done correctly
|
|
7
|
+
*
|
|
8
|
+
* anyOrder: if true, the order of the references doesn't matter (JSX or style declaration)
|
|
6
9
|
*/
|
|
7
10
|
export var findValidJsxUsageToTransform = function findValidJsxUsageToTransform(componentName, scope) {
|
|
11
|
+
var _variableDeclaration$;
|
|
12
|
+
var anyOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
8
13
|
var variableDeclaration = scope.variables.find(function (v) {
|
|
9
14
|
return v.name === componentName;
|
|
10
15
|
});
|
|
@@ -20,7 +25,23 @@ export var findValidJsxUsageToTransform = function findValidJsxUsageToTransform(
|
|
|
20
25
|
if (variableDeclaration.references.length !== 2) {
|
|
21
26
|
return;
|
|
22
27
|
}
|
|
23
|
-
var jsxUsage = variableDeclaration.references[1]
|
|
28
|
+
var jsxUsage = (_variableDeclaration$ = variableDeclaration.references[1]) === null || _variableDeclaration$ === void 0 ? void 0 : _variableDeclaration$.identifier;
|
|
29
|
+
if (anyOrder) {
|
|
30
|
+
var _variableDeclaration$2 = variableDeclaration.references.map(function (ref) {
|
|
31
|
+
return ref === null || ref === void 0 ? void 0 : ref.identifier;
|
|
32
|
+
}),
|
|
33
|
+
_variableDeclaration$3 = _slicedToArray(_variableDeclaration$2, 2),
|
|
34
|
+
firstIdentifier = _variableDeclaration$3[0],
|
|
35
|
+
secondIdentifier = _variableDeclaration$3[1];
|
|
36
|
+
// Check if the first reference is a JSXOpeningElement and the second is not or vice versa
|
|
37
|
+
if (isNodeOfType(firstIdentifier, JSX_IDENTIFIER) && !isNodeOfType(secondIdentifier, JSX_IDENTIFIER)) {
|
|
38
|
+
jsxUsage = firstIdentifier;
|
|
39
|
+
} else if (isNodeOfType(secondIdentifier, JSX_IDENTIFIER) && !isNodeOfType(firstIdentifier, JSX_IDENTIFIER)) {
|
|
40
|
+
jsxUsage = secondIdentifier;
|
|
41
|
+
} else {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
24
45
|
if (!isNodeOfType(jsxUsage, 'JSXIdentifier')) {
|
|
25
46
|
return;
|
|
26
47
|
}
|
|
@@ -55,7 +55,8 @@ export var CompiledStyled = {
|
|
|
55
55
|
success: false
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
var
|
|
58
|
+
var anyOrder = config.patterns.includes('jsx-order-fix');
|
|
59
|
+
var styledComponentJsxRef = findValidJsxUsageToTransform(styledComponentVariableRef.id.name, context.getScope(), anyOrder);
|
|
59
60
|
if (!styledComponentJsxRef) {
|
|
60
61
|
return {
|
|
61
62
|
success: false
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var defaults = {
|
|
2
|
-
patterns: ['paragraph-elements', 'span-elements', 'strong-elements', 'emphasis-elements']
|
|
2
|
+
patterns: ['paragraph-elements', 'span-elements', 'strong-elements', 'emphasis-elements'],
|
|
3
|
+
inheritColor: false
|
|
3
4
|
};
|
|
4
5
|
export var getConfig = function getConfig(overrides) {
|
|
5
6
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import * as ast from '../../../ast-nodes';
|
|
3
|
-
|
|
4
3
|
// Rename data-testid prop to testId if present
|
|
5
4
|
export function updateTestIdAttributeFix(node, fixer) {
|
|
6
5
|
var testIdAttr = ast.JSXElement.getAttributeByName(node, 'data-testid');
|
|
@@ -8,10 +7,18 @@ export function updateTestIdAttributeFix(node, fixer) {
|
|
|
8
7
|
return ast.JSXAttribute.updateName(testIdAttr, 'testId', fixer);
|
|
9
8
|
}
|
|
10
9
|
}
|
|
10
|
+
|
|
11
|
+
// Add color="inherit" prop depending on config
|
|
12
|
+
export function addColorInheritAttributeFix(node, config, fixer) {
|
|
13
|
+
if (!config.inheritColor) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return ast.JSXElement.addAttribute(node, 'color', 'inherit', fixer);
|
|
17
|
+
}
|
|
11
18
|
export var allowedAttrs = ['id', 'data-testid', 'key'];
|
|
12
19
|
|
|
13
20
|
// Only allow elements with strings as children
|
|
14
|
-
// The use of
|
|
21
|
+
// The use of `<FormattedMessage ... />` component and `{formatMessage(...)}` are allowed as these are used for i18n
|
|
15
22
|
export function hasTextChildrenOnly(node) {
|
|
16
23
|
var _node$children;
|
|
17
24
|
return (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.every(function (child) {
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import * as ast from '../../../ast-nodes';
|
|
6
6
|
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
-
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
7
|
+
import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
8
8
|
export var EmphasisElements = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
10
|
var context = _ref.context,
|
|
@@ -26,7 +26,8 @@ export var EmphasisElements = {
|
|
|
26
26
|
suggest: [{
|
|
27
27
|
desc: "Convert to Text",
|
|
28
28
|
fix: EmphasisElements._fix(node, {
|
|
29
|
-
context: context
|
|
29
|
+
context: context,
|
|
30
|
+
config: config
|
|
30
31
|
})
|
|
31
32
|
}]
|
|
32
33
|
});
|
|
@@ -55,7 +56,8 @@ export var EmphasisElements = {
|
|
|
55
56
|
return true;
|
|
56
57
|
},
|
|
57
58
|
_fix: function _fix(node, _ref3) {
|
|
58
|
-
var context = _ref3.context
|
|
59
|
+
var context = _ref3.context,
|
|
60
|
+
config = _ref3.config;
|
|
59
61
|
return function (fixer) {
|
|
60
62
|
var importFix = upsertImportDeclaration({
|
|
61
63
|
module: '@atlaskit/primitives',
|
|
@@ -63,8 +65,9 @@ export var EmphasisElements = {
|
|
|
63
65
|
}, context, fixer);
|
|
64
66
|
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
65
67
|
var asAttributeFix = ast.JSXElement.addAttribute(node, 'as', 'em', fixer);
|
|
68
|
+
var colorAttributeFix = addColorInheritAttributeFix(node, config, fixer);
|
|
66
69
|
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
67
|
-
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
70
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, colorAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
68
71
|
return Boolean(fix);
|
|
69
72
|
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
70
73
|
};
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import * as ast from '../../../ast-nodes';
|
|
6
6
|
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
-
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
7
|
+
import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
8
8
|
export var ParagraphElements = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
10
|
var context = _ref.context,
|
|
@@ -43,6 +43,7 @@ export var ParagraphElements = {
|
|
|
43
43
|
desc: 'Convert to Text and Stack',
|
|
44
44
|
fix: ParagraphElements._fixMultiple(node, {
|
|
45
45
|
context: context,
|
|
46
|
+
config: config,
|
|
46
47
|
refs: refs
|
|
47
48
|
})
|
|
48
49
|
}]
|
|
@@ -54,7 +55,8 @@ export var ParagraphElements = {
|
|
|
54
55
|
suggest: [{
|
|
55
56
|
desc: 'Convert to Text',
|
|
56
57
|
fix: ParagraphElements._fixSingle(node, {
|
|
57
|
-
context: context
|
|
58
|
+
context: context,
|
|
59
|
+
config: config
|
|
58
60
|
})
|
|
59
61
|
}]
|
|
60
62
|
});
|
|
@@ -120,6 +122,13 @@ export var ParagraphElements = {
|
|
|
120
122
|
}
|
|
121
123
|
};
|
|
122
124
|
}
|
|
125
|
+
} else if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
refs: {
|
|
129
|
+
siblings: siblings
|
|
130
|
+
}
|
|
131
|
+
};
|
|
123
132
|
}
|
|
124
133
|
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
125
134
|
|
|
@@ -140,21 +149,25 @@ export var ParagraphElements = {
|
|
|
140
149
|
};
|
|
141
150
|
},
|
|
142
151
|
_fixSingle: function _fixSingle(node, _ref3) {
|
|
143
|
-
var context = _ref3.context
|
|
152
|
+
var context = _ref3.context,
|
|
153
|
+
config = _ref3.config;
|
|
144
154
|
return function (fixer) {
|
|
145
155
|
var importFix = upsertImportDeclaration({
|
|
146
156
|
module: '@atlaskit/primitives',
|
|
147
157
|
specifiers: ['Text']
|
|
148
158
|
}, context, fixer);
|
|
149
159
|
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
160
|
+
var asAttributeFix = ast.JSXElement.addAttribute(node, 'as', 'p', fixer);
|
|
161
|
+
var colorAttributeFix = addColorInheritAttributeFix(node, config, fixer);
|
|
150
162
|
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
151
|
-
return [importFix].concat(_toConsumableArray(elementNameFixes), [testAttributeFix]).filter(function (fix) {
|
|
163
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, colorAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
152
164
|
return Boolean(fix);
|
|
153
165
|
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
154
166
|
};
|
|
155
167
|
},
|
|
156
168
|
_fixMultiple: function _fixMultiple(node, _ref4) {
|
|
157
169
|
var context = _ref4.context,
|
|
170
|
+
config = _ref4.config,
|
|
158
171
|
refs = _ref4.refs;
|
|
159
172
|
return function (fixer) {
|
|
160
173
|
if (!isNodeOfType(node.parent, 'JSXElement') || !node.parent.closingElement) {
|
|
@@ -169,8 +182,10 @@ export var ParagraphElements = {
|
|
|
169
182
|
var siblingFixes = refs.siblings.map(function (sibling) {
|
|
170
183
|
if (isNodeOfType(sibling, 'JSXElement')) {
|
|
171
184
|
var elementNameFixes = ast.JSXElement.updateName(sibling, 'Text', fixer);
|
|
185
|
+
var asAttributeFix = ast.JSXElement.addAttribute(sibling, 'as', 'p', fixer);
|
|
186
|
+
var colorAttributeFix = addColorInheritAttributeFix(sibling, config, fixer);
|
|
172
187
|
var testAttributeFix = updateTestIdAttributeFix(sibling, fixer);
|
|
173
|
-
return [].concat(_toConsumableArray(elementNameFixes), [testAttributeFix]);
|
|
188
|
+
return [].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, colorAttributeFix, testAttributeFix]);
|
|
174
189
|
}
|
|
175
190
|
return undefined;
|
|
176
191
|
}).flat();
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import * as ast from '../../../ast-nodes';
|
|
6
6
|
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
-
import { allowedAttrs, hasTextChildrenOnly, updateTestIdAttributeFix } from './common';
|
|
7
|
+
import { addColorInheritAttributeFix, allowedAttrs, hasTextChildrenOnly, updateTestIdAttributeFix } from './common';
|
|
8
8
|
export var SpanElements = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
10
|
var context = _ref.context,
|
|
@@ -26,7 +26,8 @@ export var SpanElements = {
|
|
|
26
26
|
suggest: [{
|
|
27
27
|
desc: "Convert to Text",
|
|
28
28
|
fix: SpanElements._fix(node, {
|
|
29
|
-
context: context
|
|
29
|
+
context: context,
|
|
30
|
+
config: config
|
|
30
31
|
})
|
|
31
32
|
}]
|
|
32
33
|
});
|
|
@@ -60,16 +61,17 @@ export var SpanElements = {
|
|
|
60
61
|
return true;
|
|
61
62
|
},
|
|
62
63
|
_fix: function _fix(node, _ref3) {
|
|
63
|
-
var context = _ref3.context
|
|
64
|
+
var context = _ref3.context,
|
|
65
|
+
config = _ref3.config;
|
|
64
66
|
return function (fixer) {
|
|
65
67
|
var importFix = upsertImportDeclaration({
|
|
66
68
|
module: '@atlaskit/primitives',
|
|
67
69
|
specifiers: ['Text']
|
|
68
70
|
}, context, fixer);
|
|
69
71
|
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
70
|
-
var
|
|
72
|
+
var colorAttributeFix = addColorInheritAttributeFix(node, config, fixer);
|
|
71
73
|
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
72
|
-
return [importFix].concat(_toConsumableArray(elementNameFixes), [
|
|
74
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [colorAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
73
75
|
return Boolean(fix);
|
|
74
76
|
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
75
77
|
};
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import * as ast from '../../../ast-nodes';
|
|
6
6
|
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
-
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
7
|
+
import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
8
8
|
export var StrongElements = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
10
|
var context = _ref.context,
|
|
@@ -26,7 +26,8 @@ export var StrongElements = {
|
|
|
26
26
|
suggest: [{
|
|
27
27
|
desc: "Convert to Text",
|
|
28
28
|
fix: StrongElements._fix(node, {
|
|
29
|
-
context: context
|
|
29
|
+
context: context,
|
|
30
|
+
config: config
|
|
30
31
|
})
|
|
31
32
|
}]
|
|
32
33
|
});
|
|
@@ -55,7 +56,8 @@ export var StrongElements = {
|
|
|
55
56
|
return true;
|
|
56
57
|
},
|
|
57
58
|
_fix: function _fix(node, _ref3) {
|
|
58
|
-
var context = _ref3.context
|
|
59
|
+
var context = _ref3.context,
|
|
60
|
+
config = _ref3.config;
|
|
59
61
|
return function (fixer) {
|
|
60
62
|
var importFix = upsertImportDeclaration({
|
|
61
63
|
module: '@atlaskit/primitives',
|
|
@@ -63,8 +65,9 @@ export var StrongElements = {
|
|
|
63
65
|
}, context, fixer);
|
|
64
66
|
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
65
67
|
var asAttributeFix = ast.JSXElement.addAttribute(node, 'as', 'strong', fixer);
|
|
68
|
+
var colorAttributeFix = addColorInheritAttributeFix(node, config, fixer);
|
|
66
69
|
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
67
|
-
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
70
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, colorAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
68
71
|
return Boolean(fix);
|
|
69
72
|
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
70
73
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
+
import { Root } from '../../ast-nodes';
|
|
4
5
|
export var isDecendantOfGlobalToken = function isDecendantOfGlobalToken(node) {
|
|
5
6
|
if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
|
|
6
7
|
return true;
|
|
@@ -48,6 +49,22 @@ export var isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
|
|
|
48
49
|
}
|
|
49
50
|
return false;
|
|
50
51
|
};
|
|
52
|
+
export var isDecendantOfPrimitive = function isDecendantOfPrimitive(node, context) {
|
|
53
|
+
var primitivesToCheck = ['Box', 'Text'];
|
|
54
|
+
if (isNodeOfType(node, 'JSXElement')) {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
if (primitivesToCheck.includes(node.openingElement.name.name)) {
|
|
57
|
+
var importDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
58
|
+
if (importDeclaration.length) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (node.parent) {
|
|
64
|
+
return isDecendantOfPrimitive(node.parent, context);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
51
68
|
var cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
52
69
|
export var isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
|
|
53
70
|
return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties';
|
|
1
|
+
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties' | 'jsx-order-fix';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
4
|
}
|
|
@@ -3,5 +3,7 @@ import { JSXOpeningElement } from 'eslint-codemod-utils';
|
|
|
3
3
|
/**
|
|
4
4
|
* Given a component name finds its JSX usages and performs some
|
|
5
5
|
* additional validations to ensure transformation can be done correctly
|
|
6
|
+
*
|
|
7
|
+
* anyOrder: if true, the order of the references doesn't matter (JSX or style declaration)
|
|
6
8
|
*/
|
|
7
|
-
export declare const findValidJsxUsageToTransform: (componentName: string, scope: Scope.Scope) => (JSXOpeningElement & Rule.NodeParentExtension) | undefined;
|
|
9
|
+
export declare const findValidJsxUsageToTransform: (componentName: string, scope: Scope.Scope, anyOrder?: boolean) => (JSXOpeningElement & Rule.NodeParentExtension) | undefined;
|
|
@@ -20,6 +20,6 @@ export declare const CompiledStyled: {
|
|
|
20
20
|
* All required validation steps have been taken care of before this
|
|
21
21
|
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
22
22
|
*/
|
|
23
|
-
_fix(refs: Refs, context: Rule.RuleContext):
|
|
23
|
+
_fix(refs: Refs, context: Rule.RuleContext): Rule.ReportFixer;
|
|
24
24
|
};
|
|
25
25
|
export {};
|
|
@@ -5,12 +5,11 @@ interface MetaData {
|
|
|
5
5
|
context: Rule.RuleContext;
|
|
6
6
|
config: RuleConfig;
|
|
7
7
|
}
|
|
8
|
-
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
9
8
|
export declare const EmotionCSS: {
|
|
10
9
|
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
10
|
_check(node: Rule.Node, { context, config }: MetaData): boolean;
|
|
12
11
|
_fix(node: JSXElement, { context }: {
|
|
13
12
|
context: Rule.RuleContext;
|
|
14
|
-
}):
|
|
13
|
+
}): Rule.ReportFixer;
|
|
15
14
|
};
|
|
16
15
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type Pattern = 'paragraph-elements' | 'span-elements' | 'strong-elements' | 'emphasis-elements';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
|
+
inheritColor: boolean;
|
|
4
5
|
}
|
|
5
6
|
export declare const getConfig: (overrides: Partial<RuleConfig>) => Required<RuleConfig>;
|
|
6
7
|
export {};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
4
|
+
export type MetaData = {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
config: RuleConfig;
|
|
7
|
+
};
|
|
3
8
|
export declare function updateTestIdAttributeFix(node: JSXElement, fixer: Rule.RuleFixer): Rule.Fix | undefined;
|
|
9
|
+
export declare function addColorInheritAttributeFix(node: JSXElement, config: RuleConfig, fixer: Rule.RuleFixer): Rule.Fix | undefined;
|
|
4
10
|
export declare const allowedAttrs: string[];
|
|
5
11
|
export declare function hasTextChildrenOnly(node: JSXElement): boolean;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
-
import {
|
|
4
|
-
interface MetaData {
|
|
5
|
-
context: Rule.RuleContext;
|
|
6
|
-
config: RuleConfig;
|
|
7
|
-
}
|
|
8
|
-
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
3
|
+
import { type MetaData } from './common';
|
|
9
4
|
export declare const EmphasisElements: {
|
|
10
5
|
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
6
|
_check(node: JSXElement, { context, config }: MetaData): boolean;
|
|
12
|
-
_fix(node: JSXElement, { context }:
|
|
13
|
-
context: Rule.RuleContext;
|
|
14
|
-
}): FixFunction;
|
|
7
|
+
_fix(node: JSXElement, { context, config }: MetaData): Rule.ReportFixer;
|
|
15
8
|
};
|
|
16
|
-
export {};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
-
import {
|
|
4
|
-
type MetaData = {
|
|
5
|
-
context: Rule.RuleContext;
|
|
6
|
-
config: RuleConfig;
|
|
7
|
-
};
|
|
3
|
+
import { type MetaData } from './common';
|
|
8
4
|
type CheckResult = {
|
|
9
5
|
success: boolean;
|
|
10
6
|
refs: {
|
|
11
7
|
siblings: JSXElement['children'];
|
|
12
8
|
};
|
|
13
9
|
};
|
|
14
|
-
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
15
10
|
export declare const ParagraphElements: {
|
|
16
11
|
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
17
12
|
_check(node: JSXElement & {
|
|
@@ -19,14 +14,11 @@ export declare const ParagraphElements: {
|
|
|
19
14
|
}, { context, config }: MetaData): CheckResult;
|
|
20
15
|
_fixSingle(node: JSXElement & {
|
|
21
16
|
parent: Rule.Node;
|
|
22
|
-
}, { context }:
|
|
23
|
-
context: Rule.RuleContext;
|
|
24
|
-
}): FixFunction;
|
|
17
|
+
}, { context, config }: MetaData): Rule.ReportFixer;
|
|
25
18
|
_fixMultiple(node: JSXElement & {
|
|
26
19
|
parent: Rule.Node;
|
|
27
|
-
}, { context, refs }: {
|
|
28
|
-
context: Rule.RuleContext;
|
|
20
|
+
}, { context, config, refs }: MetaData & {
|
|
29
21
|
refs: CheckResult['refs'];
|
|
30
|
-
}):
|
|
22
|
+
}): Rule.ReportFixer;
|
|
31
23
|
};
|
|
32
24
|
export {};
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
-
import {
|
|
4
|
-
interface MetaData {
|
|
5
|
-
context: Rule.RuleContext;
|
|
6
|
-
config: RuleConfig;
|
|
7
|
-
}
|
|
8
|
-
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
3
|
+
import { type MetaData } from './common';
|
|
9
4
|
export declare const SpanElements: {
|
|
10
5
|
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
6
|
_check(node: JSXElement, { context, config }: MetaData): boolean;
|
|
12
|
-
_fix(node: JSXElement, { context }:
|
|
13
|
-
context: Rule.RuleContext;
|
|
14
|
-
}): FixFunction;
|
|
7
|
+
_fix(node: JSXElement, { context, config }: MetaData): Rule.ReportFixer;
|
|
15
8
|
};
|
|
16
|
-
export {};
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
-
import {
|
|
4
|
-
interface MetaData {
|
|
5
|
-
context: Rule.RuleContext;
|
|
6
|
-
config: RuleConfig;
|
|
7
|
-
}
|
|
8
|
-
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
3
|
+
import { type MetaData } from './common';
|
|
9
4
|
export declare const StrongElements: {
|
|
10
5
|
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
6
|
_check(node: JSXElement, { context, config }: MetaData): boolean;
|
|
12
|
-
_fix(node: JSXElement, { context }:
|
|
13
|
-
context: Rule.RuleContext;
|
|
14
|
-
}): FixFunction;
|
|
7
|
+
_fix(node: JSXElement, { context, config }: MetaData): Rule.ReportFixer;
|
|
15
8
|
};
|
|
16
|
-
export {};
|
|
@@ -126,6 +126,39 @@ export declare const fontFamilyTokens: ({
|
|
|
126
126
|
name: string;
|
|
127
127
|
path: string[];
|
|
128
128
|
cleanName: string;
|
|
129
|
+
} | {
|
|
130
|
+
attributes: {
|
|
131
|
+
group: string;
|
|
132
|
+
state: string;
|
|
133
|
+
introduced: string;
|
|
134
|
+
deprecated: string;
|
|
135
|
+
description: string;
|
|
136
|
+
responsiveSmallerVariant?: undefined;
|
|
137
|
+
};
|
|
138
|
+
value: string;
|
|
139
|
+
filePath: string;
|
|
140
|
+
isSource: boolean;
|
|
141
|
+
original: {
|
|
142
|
+
attributes: {
|
|
143
|
+
group: string;
|
|
144
|
+
state: string;
|
|
145
|
+
introduced: string;
|
|
146
|
+
deprecated: string;
|
|
147
|
+
description: string;
|
|
148
|
+
responsiveSmallerVariant?: undefined;
|
|
149
|
+
};
|
|
150
|
+
value: {
|
|
151
|
+
fontWeight: string;
|
|
152
|
+
fontSize: string;
|
|
153
|
+
lineHeight: string;
|
|
154
|
+
fontFamily: string;
|
|
155
|
+
fontStyle: string;
|
|
156
|
+
letterSpacing: string;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
name: string;
|
|
160
|
+
path: string[];
|
|
161
|
+
cleanName: string;
|
|
129
162
|
} | {
|
|
130
163
|
attributes: {
|
|
131
164
|
group: string;
|
|
@@ -5,6 +5,7 @@ export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'
|
|
|
5
5
|
export declare const isPropertyKey: (node: Rule.Node) => boolean;
|
|
6
6
|
export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
|
|
7
7
|
export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
|
|
8
|
+
export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.RuleContext) => boolean;
|
|
8
9
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
9
10
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
10
11
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties';
|
|
1
|
+
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties' | 'jsx-order-fix';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
4
|
}
|
|
@@ -3,5 +3,7 @@ import { JSXOpeningElement } from 'eslint-codemod-utils';
|
|
|
3
3
|
/**
|
|
4
4
|
* Given a component name finds its JSX usages and performs some
|
|
5
5
|
* additional validations to ensure transformation can be done correctly
|
|
6
|
+
*
|
|
7
|
+
* anyOrder: if true, the order of the references doesn't matter (JSX or style declaration)
|
|
6
8
|
*/
|
|
7
|
-
export declare const findValidJsxUsageToTransform: (componentName: string, scope: Scope.Scope) => (JSXOpeningElement & Rule.NodeParentExtension) | undefined;
|
|
9
|
+
export declare const findValidJsxUsageToTransform: (componentName: string, scope: Scope.Scope, anyOrder?: boolean) => (JSXOpeningElement & Rule.NodeParentExtension) | undefined;
|