@atlaskit/eslint-plugin-design-system 8.29.1 → 8.31.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/README.md +1 -1
- package/configs/deprecated.json +0 -5
- package/constellation/index/usage.mdx +1 -1
- package/constellation/use-primitives-text/usage.mdx +21 -0
- package/dist/cjs/ast-nodes/jsx-element.js +33 -2
- package/dist/cjs/presets/all.codegen.js +2 -2
- package/dist/cjs/presets/recommended.codegen.js +1 -2
- package/dist/cjs/rules/index.codegen.js +3 -3
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +1 -2
- package/dist/cjs/rules/use-primitives-text/config/index.js +15 -0
- package/dist/cjs/rules/use-primitives-text/index.js +57 -0
- package/dist/cjs/rules/use-primitives-text/transformers/common.js +43 -0
- package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +82 -0
- package/dist/cjs/rules/use-primitives-text/transformers/index.js +33 -0
- package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +196 -0
- package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +87 -0
- package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +82 -0
- package/dist/configs/deprecated.json +0 -5
- package/dist/es2019/ast-nodes/jsx-element.js +33 -2
- package/dist/es2019/presets/all.codegen.js +2 -2
- package/dist/es2019/presets/recommended.codegen.js +1 -2
- package/dist/es2019/rules/index.codegen.js +3 -3
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +1 -2
- package/dist/es2019/rules/use-primitives-text/config/index.js +9 -0
- package/dist/es2019/rules/use-primitives-text/index.js +51 -0
- package/dist/es2019/rules/use-primitives-text/transformers/common.js +33 -0
- package/dist/es2019/rules/use-primitives-text/transformers/emphasis-elements.js +72 -0
- package/dist/es2019/rules/use-primitives-text/transformers/index.js +4 -0
- package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +187 -0
- package/dist/es2019/rules/use-primitives-text/transformers/span-elements.js +77 -0
- package/dist/es2019/rules/use-primitives-text/transformers/strong-elements.js +72 -0
- package/dist/esm/ast-nodes/jsx-element.js +33 -2
- package/dist/esm/presets/all.codegen.js +2 -2
- package/dist/esm/presets/recommended.codegen.js +1 -2
- package/dist/esm/rules/index.codegen.js +3 -3
- package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +1 -2
- package/dist/esm/rules/use-primitives-text/config/index.js +9 -0
- package/dist/esm/rules/use-primitives-text/index.js +51 -0
- package/dist/esm/rules/use-primitives-text/transformers/common.js +33 -0
- package/dist/esm/rules/use-primitives-text/transformers/emphasis-elements.js +72 -0
- package/dist/esm/rules/use-primitives-text/transformers/index.js +4 -0
- package/dist/esm/rules/use-primitives-text/transformers/paragraph-elements.js +186 -0
- package/dist/esm/rules/use-primitives-text/transformers/span-elements.js +77 -0
- package/dist/esm/rules/use-primitives-text/transformers/strong-elements.js +72 -0
- package/dist/types/ast-nodes/jsx-element.d.ts +5 -2
- package/dist/types/index.codegen.d.ts +1 -2
- package/dist/types/presets/all.codegen.d.ts +2 -2
- package/dist/types/presets/recommended.codegen.d.ts +1 -2
- package/dist/types/rules/index.codegen.d.ts +1 -1
- package/dist/types/rules/use-primitives-text/config/index.d.ts +6 -0
- package/dist/types/rules/{local-cx-xcss → use-primitives-text}/index.d.ts +1 -1
- package/dist/types/rules/use-primitives-text/transformers/common.d.ts +5 -0
- package/dist/types/rules/use-primitives-text/transformers/emphasis-elements.d.ts +16 -0
- package/dist/types/rules/use-primitives-text/transformers/index.d.ts +4 -0
- package/dist/types/rules/use-primitives-text/transformers/paragraph-elements.d.ts +32 -0
- package/dist/types/rules/use-primitives-text/transformers/span-elements.d.ts +16 -0
- package/dist/types/rules/use-primitives-text/transformers/strong-elements.d.ts +16 -0
- package/dist/types-ts4.5/ast-nodes/jsx-element.d.ts +5 -2
- package/dist/types-ts4.5/index.codegen.d.ts +1 -2
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -2
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -2
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives-text/config/index.d.ts +6 -0
- package/dist/types-ts4.5/rules/{local-cx-xcss → use-primitives-text}/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/common.d.ts +5 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/emphasis-elements.d.ts +16 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/index.d.ts +4 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/paragraph-elements.d.ts +32 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/span-elements.d.ts +16 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/strong-elements.d.ts +16 -0
- package/package.json +1 -1
- package/constellation/local-cx-xcss/usage.mdx +0 -37
- package/dist/cjs/rules/local-cx-xcss/index.js +0 -51
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +0 -27
- package/dist/es2019/rules/local-cx-xcss/index.js +0 -45
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +0 -19
- package/dist/esm/rules/local-cx-xcss/index.js +0 -45
- package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +0 -19
- package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +0 -7
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +0 -7
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
3
|
+
|
|
4
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
+
import * as ast from '../../../ast-nodes';
|
|
6
|
+
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
+
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
8
|
+
export var EmphasisElements = {
|
|
9
|
+
lint: function lint(node, _ref) {
|
|
10
|
+
var context = _ref.context,
|
|
11
|
+
config = _ref.config;
|
|
12
|
+
if (!isNodeOfType(node, 'JSXElement')) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Check whether all criteria needed to make a transformation are met
|
|
17
|
+
if (!EmphasisElements._check(node, {
|
|
18
|
+
context: context,
|
|
19
|
+
config: config
|
|
20
|
+
})) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
context.report({
|
|
24
|
+
node: node.openingElement,
|
|
25
|
+
messageId: 'preferPrimitivesText',
|
|
26
|
+
suggest: [{
|
|
27
|
+
desc: "Convert to Text",
|
|
28
|
+
fix: EmphasisElements._fix(node, {
|
|
29
|
+
context: context
|
|
30
|
+
})
|
|
31
|
+
}]
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
_check: function _check(node, _ref2) {
|
|
35
|
+
var context = _ref2.context,
|
|
36
|
+
config = _ref2.config;
|
|
37
|
+
if (!config.patterns.includes('emphasis-elements')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
var elementName = ast.JSXElement.getName(node);
|
|
41
|
+
if (elementName !== 'em') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Element has no unallowed props
|
|
46
|
+
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
51
|
+
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
52
|
+
if (importDeclaration.length > 1) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
_fix: function _fix(node, _ref3) {
|
|
58
|
+
var context = _ref3.context;
|
|
59
|
+
return function (fixer) {
|
|
60
|
+
var importFix = upsertImportDeclaration({
|
|
61
|
+
module: '@atlaskit/primitives',
|
|
62
|
+
specifiers: ['Text']
|
|
63
|
+
}, context, fixer);
|
|
64
|
+
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
65
|
+
var asAttributeFix = ast.JSXElement.addAttribute(node, 'as', 'em', fixer);
|
|
66
|
+
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
67
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
68
|
+
return Boolean(fix);
|
|
69
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
3
|
+
|
|
4
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
+
import * as ast from '../../../ast-nodes';
|
|
6
|
+
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
+
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
8
|
+
export var ParagraphElements = {
|
|
9
|
+
lint: function lint(node, _ref) {
|
|
10
|
+
var context = _ref.context,
|
|
11
|
+
config = _ref.config;
|
|
12
|
+
if (!isNodeOfType(node, 'JSXElement')) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Check whether all criteria needed to make a transformation are met
|
|
17
|
+
var _ParagraphElements$_c = ParagraphElements._check(node, {
|
|
18
|
+
context: context,
|
|
19
|
+
config: config
|
|
20
|
+
}),
|
|
21
|
+
success = _ParagraphElements$_c.success,
|
|
22
|
+
refs = _ParagraphElements$_c.refs;
|
|
23
|
+
if (!success) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (refs.siblings.length > 1) {
|
|
27
|
+
var _refs$siblings$0$loc, _refs$siblings$loc;
|
|
28
|
+
/**
|
|
29
|
+
* Highlighting from first opening element to last closing element
|
|
30
|
+
* to indicate fix will change all p elements and wrap them in a Stack,
|
|
31
|
+
* falls back to first opening element.
|
|
32
|
+
*/
|
|
33
|
+
var startLoc = (_refs$siblings$0$loc = refs.siblings[0].loc) === null || _refs$siblings$0$loc === void 0 ? void 0 : _refs$siblings$0$loc.start;
|
|
34
|
+
var endLoc = (_refs$siblings$loc = refs.siblings[refs.siblings.length - 1].loc) === null || _refs$siblings$loc === void 0 ? void 0 : _refs$siblings$loc.end;
|
|
35
|
+
context.report({
|
|
36
|
+
loc: startLoc && endLoc && {
|
|
37
|
+
start: startLoc,
|
|
38
|
+
end: endLoc
|
|
39
|
+
},
|
|
40
|
+
node: node.openingElement,
|
|
41
|
+
messageId: 'preferPrimitivesStackedText',
|
|
42
|
+
suggest: [{
|
|
43
|
+
desc: 'Convert to Text and Stack',
|
|
44
|
+
fix: ParagraphElements._fixMultiple(node, {
|
|
45
|
+
context: context,
|
|
46
|
+
refs: refs
|
|
47
|
+
})
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
context.report({
|
|
52
|
+
node: node,
|
|
53
|
+
messageId: 'preferPrimitivesText',
|
|
54
|
+
suggest: [{
|
|
55
|
+
desc: 'Convert to Text',
|
|
56
|
+
fix: ParagraphElements._fixSingle(node, {
|
|
57
|
+
context: context
|
|
58
|
+
})
|
|
59
|
+
}]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
_check: function _check(node, _ref2) {
|
|
64
|
+
var context = _ref2.context,
|
|
65
|
+
config = _ref2.config;
|
|
66
|
+
if (!config.patterns.includes('paragraph-elements')) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
refs: {
|
|
70
|
+
siblings: []
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var elementName = ast.JSXElement.getName(node);
|
|
75
|
+
if (elementName !== 'p') {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
refs: {
|
|
79
|
+
siblings: []
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// All siblings have to be paragraph elements with no unallowed props
|
|
85
|
+
if (!isNodeOfType(node.parent, 'JSXElement')) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
refs: {
|
|
89
|
+
siblings: []
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var siblings = ast.JSXElement.getChildren(node.parent);
|
|
94
|
+
if (siblings.length > 1) {
|
|
95
|
+
var _siblings$0$range, _node$range, _siblings$0$range2, _node$range2;
|
|
96
|
+
// Only report for the first p element by comparing node location
|
|
97
|
+
if (((_siblings$0$range = siblings[0].range) === null || _siblings$0$range === void 0 ? void 0 : _siblings$0$range[0]) !== ((_node$range = node.range) === null || _node$range === void 0 ? void 0 : _node$range[0]) || ((_siblings$0$range2 = siblings[0].range) === null || _siblings$0$range2 === void 0 ? void 0 : _siblings$0$range2[1]) !== ((_node$range2 = node.range) === null || _node$range2 === void 0 ? void 0 : _node$range2[1])) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
refs: {
|
|
101
|
+
siblings: siblings
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Only report when every sibling is a p element
|
|
106
|
+
var siblingsMatch = siblings.every(function (child) {
|
|
107
|
+
if (!isNodeOfType(child, 'JSXElement')) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (ast.JSXElement.getName(child) !== 'p') {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return ast.JSXElement.hasAllowedAttrsOnly(child, allowedAttrs);
|
|
114
|
+
});
|
|
115
|
+
if (!siblingsMatch) {
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
refs: {
|
|
119
|
+
siblings: siblings
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
125
|
+
|
|
126
|
+
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
127
|
+
if (importDeclaration.length > 1) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
refs: {
|
|
131
|
+
siblings: siblings
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
refs: {
|
|
138
|
+
siblings: siblings
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
_fixSingle: function _fixSingle(node, _ref3) {
|
|
143
|
+
var context = _ref3.context;
|
|
144
|
+
return function (fixer) {
|
|
145
|
+
var importFix = upsertImportDeclaration({
|
|
146
|
+
module: '@atlaskit/primitives',
|
|
147
|
+
specifiers: ['Text']
|
|
148
|
+
}, context, fixer);
|
|
149
|
+
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
150
|
+
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
151
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [testAttributeFix]).filter(function (fix) {
|
|
152
|
+
return Boolean(fix);
|
|
153
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
_fixMultiple: function _fixMultiple(node, _ref4) {
|
|
157
|
+
var context = _ref4.context,
|
|
158
|
+
refs = _ref4.refs;
|
|
159
|
+
return function (fixer) {
|
|
160
|
+
if (!isNodeOfType(node.parent, 'JSXElement') || !node.parent.closingElement) {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
var importFix = upsertImportDeclaration({
|
|
164
|
+
module: '@atlaskit/primitives',
|
|
165
|
+
specifiers: ['Text', 'Stack']
|
|
166
|
+
}, context, fixer);
|
|
167
|
+
|
|
168
|
+
// Update all siblings elements and their attributes
|
|
169
|
+
var siblingFixes = refs.siblings.map(function (sibling) {
|
|
170
|
+
if (isNodeOfType(sibling, 'JSXElement')) {
|
|
171
|
+
var elementNameFixes = ast.JSXElement.updateName(sibling, 'Text', fixer);
|
|
172
|
+
var testAttributeFix = updateTestIdAttributeFix(sibling, fixer);
|
|
173
|
+
return [].concat(_toConsumableArray(elementNameFixes), [testAttributeFix]);
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}).flat();
|
|
177
|
+
|
|
178
|
+
// Wrap in <Stack /> when more than 1 sibling
|
|
179
|
+
var wrapperOpenElementFix = fixer.insertTextAfter(node.parent.openingElement, "<Stack space='space.150'>");
|
|
180
|
+
var wrapperCloseElementFix = fixer.insertTextBefore(node.parent.closingElement, '</Stack>');
|
|
181
|
+
return [importFix].concat(_toConsumableArray(siblingFixes), [wrapperOpenElementFix, wrapperCloseElementFix]).filter(function (fix) {
|
|
182
|
+
return Boolean(fix);
|
|
183
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
3
|
+
|
|
4
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
+
import * as ast from '../../../ast-nodes';
|
|
6
|
+
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
+
import { allowedAttrs, hasTextChildrenOnly, updateTestIdAttributeFix } from './common';
|
|
8
|
+
export var SpanElements = {
|
|
9
|
+
lint: function lint(node, _ref) {
|
|
10
|
+
var context = _ref.context,
|
|
11
|
+
config = _ref.config;
|
|
12
|
+
if (!isNodeOfType(node, 'JSXElement')) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Check whether all criteria needed to make a transformation are met
|
|
17
|
+
if (!SpanElements._check(node, {
|
|
18
|
+
context: context,
|
|
19
|
+
config: config
|
|
20
|
+
})) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
context.report({
|
|
24
|
+
node: node.openingElement,
|
|
25
|
+
messageId: 'preferPrimitivesText',
|
|
26
|
+
suggest: [{
|
|
27
|
+
desc: "Convert to Text",
|
|
28
|
+
fix: SpanElements._fix(node, {
|
|
29
|
+
context: context
|
|
30
|
+
})
|
|
31
|
+
}]
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
_check: function _check(node, _ref2) {
|
|
35
|
+
var context = _ref2.context,
|
|
36
|
+
config = _ref2.config;
|
|
37
|
+
if (!config.patterns.includes('span-elements')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
var elementName = ast.JSXElement.getName(node);
|
|
41
|
+
if (elementName !== 'span') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Element has no unallowed props
|
|
46
|
+
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Only allow elements with strings as children
|
|
51
|
+
if (!hasTextChildrenOnly(node)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
55
|
+
|
|
56
|
+
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
57
|
+
if (importDeclaration.length > 1) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
_fix: function _fix(node, _ref3) {
|
|
63
|
+
var context = _ref3.context;
|
|
64
|
+
return function (fixer) {
|
|
65
|
+
var importFix = upsertImportDeclaration({
|
|
66
|
+
module: '@atlaskit/primitives',
|
|
67
|
+
specifiers: ['Text']
|
|
68
|
+
}, context, fixer);
|
|
69
|
+
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
70
|
+
var variantAttributeFix = ast.JSXElement.addAttribute(node, 'variant', 'ui', fixer);
|
|
71
|
+
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
72
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [variantAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
73
|
+
return Boolean(fix);
|
|
74
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
3
|
+
|
|
4
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
+
import * as ast from '../../../ast-nodes';
|
|
6
|
+
import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
|
|
7
|
+
import { allowedAttrs, updateTestIdAttributeFix } from './common';
|
|
8
|
+
export var StrongElements = {
|
|
9
|
+
lint: function lint(node, _ref) {
|
|
10
|
+
var context = _ref.context,
|
|
11
|
+
config = _ref.config;
|
|
12
|
+
if (!isNodeOfType(node, 'JSXElement')) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Check whether all criteria needed to make a transformation are met
|
|
17
|
+
if (!StrongElements._check(node, {
|
|
18
|
+
context: context,
|
|
19
|
+
config: config
|
|
20
|
+
})) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
context.report({
|
|
24
|
+
node: node.openingElement,
|
|
25
|
+
messageId: 'preferPrimitivesText',
|
|
26
|
+
suggest: [{
|
|
27
|
+
desc: "Convert to Text",
|
|
28
|
+
fix: StrongElements._fix(node, {
|
|
29
|
+
context: context
|
|
30
|
+
})
|
|
31
|
+
}]
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
_check: function _check(node, _ref2) {
|
|
35
|
+
var context = _ref2.context,
|
|
36
|
+
config = _ref2.config;
|
|
37
|
+
if (!config.patterns.includes('strong-elements')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
var elementName = ast.JSXElement.getName(node);
|
|
41
|
+
if (elementName !== 'strong') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Element has no unallowed props
|
|
46
|
+
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
51
|
+
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
52
|
+
if (importDeclaration.length > 1) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
_fix: function _fix(node, _ref3) {
|
|
58
|
+
var context = _ref3.context;
|
|
59
|
+
return function (fixer) {
|
|
60
|
+
var importFix = upsertImportDeclaration({
|
|
61
|
+
module: '@atlaskit/primitives',
|
|
62
|
+
specifiers: ['Text']
|
|
63
|
+
}, context, fixer);
|
|
64
|
+
var elementNameFixes = ast.JSXElement.updateName(node, 'Text', fixer);
|
|
65
|
+
var asAttributeFix = ast.JSXElement.addAttribute(node, 'as', 'strong', fixer);
|
|
66
|
+
var testAttributeFix = updateTestIdAttributeFix(node, fixer);
|
|
67
|
+
return [importFix].concat(_toConsumableArray(elementNameFixes), [asAttributeFix, testAttributeFix]).filter(function (fix) {
|
|
68
|
+
return Boolean(fix);
|
|
69
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -7,8 +7,8 @@ export declare const JSXElementHelper: {
|
|
|
7
7
|
* `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is a namespace (JSXNamespacedName)
|
|
8
8
|
* `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is an object (JSXMemberExpression)
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* e.g.
|
|
10
|
+
* getting the name of a JSXMemberExpression is difficult, because object can contain objects, which is recursively defined in the AST.
|
|
11
|
+
* e.g. Getting the name of `<MyComponents.PresentationLayer.LeftSideBar.Header />` would require `getName` to recursively resolve all parts of the name.
|
|
12
12
|
* `getName` does not currently have this functionality. Add it if you need it.
|
|
13
13
|
*/
|
|
14
14
|
getName(node: JSXElement): string;
|
|
@@ -17,5 +17,8 @@ export declare const JSXElementHelper: {
|
|
|
17
17
|
getAttributes(node: JSXElement): (JSXAttribute | JSXSpreadAttribute)[];
|
|
18
18
|
getAttributeByName(node: JSXElement, name: string): JSXAttribute | undefined;
|
|
19
19
|
containsSpreadAttributes(node: JSXElement): boolean;
|
|
20
|
+
addAttribute(node: JSXElement, name: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
|
|
21
|
+
getChildren(node: JSXElement): JSXElement['children'];
|
|
22
|
+
hasAllowedAttrsOnly(node: JSXElement, allowedProps: string[]): boolean;
|
|
20
23
|
};
|
|
21
24
|
export { JSXElementHelper as JSXElement };
|
|
@@ -7,7 +7,6 @@ export declare const configs: {
|
|
|
7
7
|
'@atlaskit/design-system/ensure-design-token-usage': string;
|
|
8
8
|
'@atlaskit/design-system/ensure-design-token-usage/preview': string;
|
|
9
9
|
'@atlaskit/design-system/icon-label': string;
|
|
10
|
-
'@atlaskit/design-system/local-cx-xcss': string;
|
|
11
10
|
'@atlaskit/design-system/no-banned-imports': string;
|
|
12
11
|
'@atlaskit/design-system/no-css-tagged-template-expression': string;
|
|
13
12
|
'@atlaskit/design-system/no-deprecated-apis': string;
|
|
@@ -31,6 +30,7 @@ export declare const configs: {
|
|
|
31
30
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
|
|
32
31
|
'@atlaskit/design-system/use-href-in-link-item': string;
|
|
33
32
|
'@atlaskit/design-system/use-primitives': string;
|
|
33
|
+
'@atlaskit/design-system/use-primitives-text': string;
|
|
34
34
|
'@atlaskit/design-system/use-visually-hidden': string;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
@@ -40,7 +40,6 @@ export declare const configs: {
|
|
|
40
40
|
'@atlaskit/design-system/consistent-css-prop-usage': string;
|
|
41
41
|
'@atlaskit/design-system/ensure-design-token-usage': string;
|
|
42
42
|
'@atlaskit/design-system/icon-label': string;
|
|
43
|
-
'@atlaskit/design-system/local-cx-xcss': string;
|
|
44
43
|
'@atlaskit/design-system/no-banned-imports': string;
|
|
45
44
|
'@atlaskit/design-system/no-deprecated-apis': string;
|
|
46
45
|
'@atlaskit/design-system/no-deprecated-design-token-usage': string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::aa64b4343b8763cfa5aa66230faea408>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -10,7 +10,6 @@ declare const _default: {
|
|
|
10
10
|
'@atlaskit/design-system/ensure-design-token-usage': string;
|
|
11
11
|
'@atlaskit/design-system/ensure-design-token-usage/preview': string;
|
|
12
12
|
'@atlaskit/design-system/icon-label': string;
|
|
13
|
-
'@atlaskit/design-system/local-cx-xcss': string;
|
|
14
13
|
'@atlaskit/design-system/no-banned-imports': string;
|
|
15
14
|
'@atlaskit/design-system/no-css-tagged-template-expression': string;
|
|
16
15
|
'@atlaskit/design-system/no-deprecated-apis': string;
|
|
@@ -34,6 +33,7 @@ declare const _default: {
|
|
|
34
33
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
|
|
35
34
|
'@atlaskit/design-system/use-href-in-link-item': string;
|
|
36
35
|
'@atlaskit/design-system/use-primitives': string;
|
|
36
|
+
'@atlaskit/design-system/use-primitives-text': string;
|
|
37
37
|
'@atlaskit/design-system/use-visually-hidden': string;
|
|
38
38
|
};
|
|
39
39
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::aebc778f0b10032cbb2941b55189d766>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -9,7 +9,6 @@ declare const _default: {
|
|
|
9
9
|
'@atlaskit/design-system/consistent-css-prop-usage': string;
|
|
10
10
|
'@atlaskit/design-system/ensure-design-token-usage': string;
|
|
11
11
|
'@atlaskit/design-system/icon-label': string;
|
|
12
|
-
'@atlaskit/design-system/local-cx-xcss': string;
|
|
13
12
|
'@atlaskit/design-system/no-banned-imports': string;
|
|
14
13
|
'@atlaskit/design-system/no-deprecated-apis': string;
|
|
15
14
|
'@atlaskit/design-system/no-deprecated-design-token-usage': string;
|
|
@@ -3,7 +3,6 @@ declare const _default: {
|
|
|
3
3
|
'ensure-design-token-usage': import("eslint").Rule.RuleModule;
|
|
4
4
|
'ensure-design-token-usage/preview': import("eslint").Rule.RuleModule;
|
|
5
5
|
'icon-label': import("eslint").Rule.RuleModule;
|
|
6
|
-
'local-cx-xcss': import("eslint").Rule.RuleModule;
|
|
7
6
|
'no-banned-imports': import("eslint").Rule.RuleModule;
|
|
8
7
|
'no-css-tagged-template-expression': import("eslint").Rule.RuleModule;
|
|
9
8
|
'no-deprecated-apis': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, [{
|
|
@@ -31,6 +30,7 @@ declare const _default: {
|
|
|
31
30
|
'use-heading-level-in-spotlight-card': import("eslint").Rule.RuleModule;
|
|
32
31
|
'use-href-in-link-item': import("eslint").Rule.RuleModule;
|
|
33
32
|
'use-primitives': import("eslint").Rule.RuleModule;
|
|
33
|
+
'use-primitives-text': import("eslint").Rule.RuleModule;
|
|
34
34
|
'use-visually-hidden': import("eslint").Rule.RuleModule;
|
|
35
35
|
};
|
|
36
36
|
export default _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
export declare function updateTestIdAttributeFix(node: JSXElement, fixer: Rule.RuleFixer): Rule.Fix | undefined;
|
|
4
|
+
export declare const allowedAttrs: string[];
|
|
5
|
+
export declare function hasTextChildrenOnly(node: JSXElement): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
4
|
+
interface MetaData {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
config: RuleConfig;
|
|
7
|
+
}
|
|
8
|
+
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
9
|
+
export declare const EmphasisElements: {
|
|
10
|
+
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
|
+
_check(node: JSXElement, { context, config }: MetaData): boolean;
|
|
12
|
+
_fix(node: JSXElement, { context }: {
|
|
13
|
+
context: Rule.RuleContext;
|
|
14
|
+
}): FixFunction;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
4
|
+
type MetaData = {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
config: RuleConfig;
|
|
7
|
+
};
|
|
8
|
+
type CheckResult = {
|
|
9
|
+
success: boolean;
|
|
10
|
+
refs: {
|
|
11
|
+
siblings: JSXElement['children'];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
15
|
+
export declare const ParagraphElements: {
|
|
16
|
+
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
17
|
+
_check(node: JSXElement & {
|
|
18
|
+
parent: Rule.Node;
|
|
19
|
+
}, { context, config }: MetaData): CheckResult;
|
|
20
|
+
_fixSingle(node: JSXElement & {
|
|
21
|
+
parent: Rule.Node;
|
|
22
|
+
}, { context }: {
|
|
23
|
+
context: Rule.RuleContext;
|
|
24
|
+
}): FixFunction;
|
|
25
|
+
_fixMultiple(node: JSXElement & {
|
|
26
|
+
parent: Rule.Node;
|
|
27
|
+
}, { context, refs }: {
|
|
28
|
+
context: Rule.RuleContext;
|
|
29
|
+
refs: CheckResult['refs'];
|
|
30
|
+
}): FixFunction;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
4
|
+
interface MetaData {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
config: RuleConfig;
|
|
7
|
+
}
|
|
8
|
+
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
9
|
+
export declare const SpanElements: {
|
|
10
|
+
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
|
+
_check(node: JSXElement, { context, config }: MetaData): boolean;
|
|
12
|
+
_fix(node: JSXElement, { context }: {
|
|
13
|
+
context: Rule.RuleContext;
|
|
14
|
+
}): FixFunction;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
4
|
+
interface MetaData {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
config: RuleConfig;
|
|
7
|
+
}
|
|
8
|
+
type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
9
|
+
export declare const StrongElements: {
|
|
10
|
+
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
11
|
+
_check(node: JSXElement, { context, config }: MetaData): boolean;
|
|
12
|
+
_fix(node: JSXElement, { context }: {
|
|
13
|
+
context: Rule.RuleContext;
|
|
14
|
+
}): FixFunction;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -7,8 +7,8 @@ export declare const JSXElementHelper: {
|
|
|
7
7
|
* `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is a namespace (JSXNamespacedName)
|
|
8
8
|
* `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is an object (JSXMemberExpression)
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* e.g.
|
|
10
|
+
* getting the name of a JSXMemberExpression is difficult, because object can contain objects, which is recursively defined in the AST.
|
|
11
|
+
* e.g. Getting the name of `<MyComponents.PresentationLayer.LeftSideBar.Header />` would require `getName` to recursively resolve all parts of the name.
|
|
12
12
|
* `getName` does not currently have this functionality. Add it if you need it.
|
|
13
13
|
*/
|
|
14
14
|
getName(node: JSXElement): string;
|
|
@@ -17,5 +17,8 @@ export declare const JSXElementHelper: {
|
|
|
17
17
|
getAttributes(node: JSXElement): (JSXAttribute | JSXSpreadAttribute)[];
|
|
18
18
|
getAttributeByName(node: JSXElement, name: string): JSXAttribute | undefined;
|
|
19
19
|
containsSpreadAttributes(node: JSXElement): boolean;
|
|
20
|
+
addAttribute(node: JSXElement, name: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
|
|
21
|
+
getChildren(node: JSXElement): JSXElement['children'];
|
|
22
|
+
hasAllowedAttrsOnly(node: JSXElement, allowedProps: string[]): boolean;
|
|
20
23
|
};
|
|
21
24
|
export { JSXElementHelper as JSXElement };
|