@atlaskit/eslint-plugin-design-system 10.12.4 → 10.13.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 +24 -0
- package/dist/cjs/rules/no-legacy-icons/checks.js +90 -44
- package/dist/cjs/rules/no-legacy-icons/helpers.js +44 -12
- package/dist/cjs/rules/no-legacy-icons/index.js +5 -3
- package/dist/cjs/rules/use-heading/config/index.js +2 -1
- package/dist/cjs/rules/use-heading/transformers/native-elements.js +61 -31
- package/dist/cjs/rules/use-primitives-text/config/index.js +2 -1
- package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +48 -26
- package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +62 -51
- package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +56 -32
- package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +48 -26
- package/dist/es2019/rules/no-legacy-icons/checks.js +75 -33
- package/dist/es2019/rules/no-legacy-icons/helpers.js +43 -11
- package/dist/es2019/rules/no-legacy-icons/index.js +5 -3
- package/dist/es2019/rules/use-heading/config/index.js +2 -1
- package/dist/es2019/rules/use-heading/transformers/native-elements.js +60 -29
- package/dist/es2019/rules/use-primitives-text/config/index.js +2 -1
- package/dist/es2019/rules/use-primitives-text/transformers/emphasis-elements.js +47 -24
- package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +63 -52
- package/dist/es2019/rules/use-primitives-text/transformers/span-elements.js +55 -30
- package/dist/es2019/rules/use-primitives-text/transformers/strong-elements.js +47 -24
- package/dist/esm/rules/no-legacy-icons/checks.js +91 -45
- package/dist/esm/rules/no-legacy-icons/helpers.js +43 -11
- package/dist/esm/rules/no-legacy-icons/index.js +5 -3
- package/dist/esm/rules/use-heading/config/index.js +2 -1
- package/dist/esm/rules/use-heading/transformers/native-elements.js +61 -31
- package/dist/esm/rules/use-primitives-text/config/index.js +2 -1
- package/dist/esm/rules/use-primitives-text/transformers/emphasis-elements.js +48 -26
- package/dist/esm/rules/use-primitives-text/transformers/paragraph-elements.js +62 -51
- package/dist/esm/rules/use-primitives-text/transformers/span-elements.js +56 -32
- package/dist/esm/rules/use-primitives-text/transformers/strong-elements.js +48 -26
- package/dist/types/rules/no-legacy-icons/checks.d.ts +4 -1
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +21 -14
- package/dist/types/rules/use-heading/config/index.d.ts +2 -1
- package/dist/types/rules/use-heading/transformers/native-elements.d.ts +5 -1
- package/dist/types/rules/use-primitives-text/config/index.d.ts +1 -0
- package/dist/types/rules/use-primitives-text/transformers/emphasis-elements.d.ts +6 -1
- package/dist/types/rules/use-primitives-text/transformers/paragraph-elements.d.ts +1 -0
- package/dist/types/rules/use-primitives-text/transformers/span-elements.d.ts +6 -1
- package/dist/types/rules/use-primitives-text/transformers/strong-elements.d.ts +6 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +4 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +21 -14
- package/dist/types-ts4.5/rules/use-heading/config/index.d.ts +2 -1
- package/dist/types-ts4.5/rules/use-heading/transformers/native-elements.d.ts +5 -1
- 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/emphasis-elements.d.ts +6 -1
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/paragraph-elements.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/span-elements.d.ts +6 -1
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/strong-elements.d.ts +6 -1
- package/package.json +2 -2
|
@@ -15,60 +15,65 @@ export const ParagraphElements = {
|
|
|
15
15
|
// Check whether all criteria needed to make a transformation are met
|
|
16
16
|
const {
|
|
17
17
|
success,
|
|
18
|
+
autoFixable,
|
|
18
19
|
refs
|
|
19
20
|
} = ParagraphElements._check(node, {
|
|
20
21
|
context,
|
|
21
22
|
config
|
|
22
23
|
});
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
messageId: 'preferPrimitivesStackedText',
|
|
47
|
-
...(config.enableUnsafeAutofix ? {
|
|
48
|
-
fix
|
|
49
|
-
} : {
|
|
50
|
-
suggest: [{
|
|
51
|
-
desc: `Convert to Text and Stack`,
|
|
24
|
+
if (success && autoFixable) {
|
|
25
|
+
if (refs.siblings.length > 1) {
|
|
26
|
+
var _refs$siblings$0$loc, _refs$siblings$loc;
|
|
27
|
+
/**
|
|
28
|
+
* Highlighting from first opening element to last closing element
|
|
29
|
+
* to indicate fix will change all p elements and wrap them in a Stack,
|
|
30
|
+
* falls back to first opening element.
|
|
31
|
+
*/
|
|
32
|
+
const startLoc = (_refs$siblings$0$loc = refs.siblings[0].loc) === null || _refs$siblings$0$loc === void 0 ? void 0 : _refs$siblings$0$loc.start;
|
|
33
|
+
const endLoc = (_refs$siblings$loc = refs.siblings[refs.siblings.length - 1].loc) === null || _refs$siblings$loc === void 0 ? void 0 : _refs$siblings$loc.end;
|
|
34
|
+
const fix = ParagraphElements._fixMultiple(node, {
|
|
35
|
+
context,
|
|
36
|
+
config,
|
|
37
|
+
refs
|
|
38
|
+
});
|
|
39
|
+
context.report({
|
|
40
|
+
loc: startLoc && endLoc && {
|
|
41
|
+
start: startLoc,
|
|
42
|
+
end: endLoc
|
|
43
|
+
},
|
|
44
|
+
node: node.openingElement,
|
|
45
|
+
messageId: 'preferPrimitivesStackedText',
|
|
46
|
+
...(config.enableUnsafeAutofix ? {
|
|
52
47
|
fix
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
} : {
|
|
49
|
+
suggest: [{
|
|
50
|
+
desc: `Convert to Text and Stack`,
|
|
51
|
+
fix
|
|
52
|
+
}]
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
const fix = ParagraphElements._fixSingle(node, {
|
|
57
|
+
context,
|
|
58
|
+
config
|
|
59
|
+
});
|
|
60
|
+
context.report({
|
|
61
|
+
node: node.openingElement,
|
|
62
|
+
messageId: 'preferPrimitivesText',
|
|
63
|
+
...(config.enableUnsafeAutofix ? {
|
|
69
64
|
fix
|
|
70
|
-
}
|
|
71
|
-
|
|
65
|
+
} : {
|
|
66
|
+
suggest: [{
|
|
67
|
+
desc: `Convert to Text`,
|
|
68
|
+
fix
|
|
69
|
+
}]
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
} else if (success && config.enableUnsafeReport) {
|
|
74
|
+
context.report({
|
|
75
|
+
node: node.openingElement,
|
|
76
|
+
messageId: 'preferPrimitivesText'
|
|
72
77
|
});
|
|
73
78
|
}
|
|
74
79
|
},
|
|
@@ -105,7 +110,8 @@ export const ParagraphElements = {
|
|
|
105
110
|
// All siblings have to be paragraph elements with no unallowed props
|
|
106
111
|
if (!isNodeOfType(node.parent, 'JSXElement')) {
|
|
107
112
|
return {
|
|
108
|
-
success:
|
|
113
|
+
success: true,
|
|
114
|
+
autoFixable: false,
|
|
109
115
|
refs: {
|
|
110
116
|
siblings: []
|
|
111
117
|
}
|
|
@@ -117,7 +123,8 @@ export const ParagraphElements = {
|
|
|
117
123
|
// Only report for the first p element by comparing node location
|
|
118
124
|
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])) {
|
|
119
125
|
return {
|
|
120
|
-
success:
|
|
126
|
+
success: true,
|
|
127
|
+
autoFixable: false,
|
|
121
128
|
refs: {
|
|
122
129
|
siblings
|
|
123
130
|
}
|
|
@@ -135,7 +142,8 @@ export const ParagraphElements = {
|
|
|
135
142
|
});
|
|
136
143
|
if (!siblingsMatch) {
|
|
137
144
|
return {
|
|
138
|
-
success:
|
|
145
|
+
success: true,
|
|
146
|
+
autoFixable: false,
|
|
139
147
|
refs: {
|
|
140
148
|
siblings
|
|
141
149
|
}
|
|
@@ -143,7 +151,8 @@ export const ParagraphElements = {
|
|
|
143
151
|
}
|
|
144
152
|
} else if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
145
153
|
return {
|
|
146
|
-
success:
|
|
154
|
+
success: true,
|
|
155
|
+
autoFixable: false,
|
|
147
156
|
refs: {
|
|
148
157
|
siblings
|
|
149
158
|
}
|
|
@@ -154,7 +163,8 @@ export const ParagraphElements = {
|
|
|
154
163
|
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
155
164
|
if (importDeclaration.length > 1) {
|
|
156
165
|
return {
|
|
157
|
-
success:
|
|
166
|
+
success: true,
|
|
167
|
+
autoFixable: false,
|
|
158
168
|
refs: {
|
|
159
169
|
siblings
|
|
160
170
|
}
|
|
@@ -162,6 +172,7 @@ export const ParagraphElements = {
|
|
|
162
172
|
}
|
|
163
173
|
return {
|
|
164
174
|
success: true,
|
|
175
|
+
autoFixable: true,
|
|
165
176
|
refs: {
|
|
166
177
|
siblings
|
|
167
178
|
}
|
|
@@ -13,60 +13,85 @@ export const SpanElements = {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// Check whether all criteria needed to make a transformation are met
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const fix = SpanElements._fix(node, {
|
|
16
|
+
const {
|
|
17
|
+
success,
|
|
18
|
+
autoFixable
|
|
19
|
+
} = SpanElements._check(node, {
|
|
23
20
|
context,
|
|
24
21
|
config
|
|
25
22
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
if (success && autoFixable) {
|
|
24
|
+
const fix = SpanElements._fix(node, {
|
|
25
|
+
context,
|
|
26
|
+
config
|
|
27
|
+
});
|
|
28
|
+
context.report({
|
|
29
|
+
node: node.openingElement,
|
|
30
|
+
messageId: 'preferPrimitivesText',
|
|
31
|
+
...(config.enableUnsafeAutofix ? {
|
|
34
32
|
fix
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
} : {
|
|
34
|
+
suggest: [{
|
|
35
|
+
desc: `Convert to Text`,
|
|
36
|
+
fix
|
|
37
|
+
}]
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
} else if (success && config.enableUnsafeReport) {
|
|
41
|
+
context.report({
|
|
42
|
+
node: node.openingElement,
|
|
43
|
+
messageId: 'preferPrimitivesText'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
38
46
|
},
|
|
39
47
|
_check(node, {
|
|
40
48
|
context,
|
|
41
49
|
config
|
|
42
50
|
}) {
|
|
43
51
|
if (!config.patterns.includes('span-elements')) {
|
|
44
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
success: false
|
|
54
|
+
};
|
|
45
55
|
}
|
|
46
56
|
const elementName = ast.JSXElement.getName(node);
|
|
47
57
|
if (elementName !== 'span') {
|
|
48
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
success: false
|
|
60
|
+
};
|
|
49
61
|
}
|
|
50
62
|
if (!node.children.length) {
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Element has no unallowed props
|
|
55
|
-
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
56
|
-
return false;
|
|
63
|
+
return {
|
|
64
|
+
success: false
|
|
65
|
+
};
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
// Only allow elements with strings as children
|
|
60
69
|
if (!hasTextChildrenOnly(node)) {
|
|
61
|
-
return
|
|
70
|
+
return {
|
|
71
|
+
success: false
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Element has no unallowed props
|
|
76
|
+
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
autoFixable: false
|
|
80
|
+
};
|
|
62
81
|
}
|
|
63
|
-
const importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
64
82
|
|
|
65
83
|
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
84
|
+
const importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
66
85
|
if (importDeclaration.length > 1) {
|
|
67
|
-
return
|
|
86
|
+
return {
|
|
87
|
+
success: true,
|
|
88
|
+
autoFixable: false
|
|
89
|
+
};
|
|
68
90
|
}
|
|
69
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
success: true,
|
|
93
|
+
autoFixable: true
|
|
94
|
+
};
|
|
70
95
|
},
|
|
71
96
|
_fix(node, {
|
|
72
97
|
context,
|
|
@@ -13,55 +13,78 @@ export const StrongElements = {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// Check whether all criteria needed to make a transformation are met
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const fix = StrongElements._fix(node, {
|
|
16
|
+
const {
|
|
17
|
+
success,
|
|
18
|
+
autoFixable
|
|
19
|
+
} = StrongElements._check(node, {
|
|
23
20
|
context,
|
|
24
21
|
config
|
|
25
22
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
if (success && autoFixable) {
|
|
24
|
+
const fix = StrongElements._fix(node, {
|
|
25
|
+
context,
|
|
26
|
+
config
|
|
27
|
+
});
|
|
28
|
+
context.report({
|
|
29
|
+
node: node.openingElement,
|
|
30
|
+
messageId: 'preferPrimitivesText',
|
|
31
|
+
...(config.enableUnsafeAutofix ? {
|
|
34
32
|
fix
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
} : {
|
|
34
|
+
suggest: [{
|
|
35
|
+
desc: `Convert to Text`,
|
|
36
|
+
fix
|
|
37
|
+
}]
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
} else if (success && config.enableUnsafeReport) {
|
|
41
|
+
context.report({
|
|
42
|
+
node: node.openingElement,
|
|
43
|
+
messageId: 'preferPrimitivesText'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
38
46
|
},
|
|
39
47
|
_check(node, {
|
|
40
48
|
context,
|
|
41
49
|
config
|
|
42
50
|
}) {
|
|
43
51
|
if (!config.patterns.includes('strong-elements')) {
|
|
44
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
success: false
|
|
54
|
+
};
|
|
45
55
|
}
|
|
46
56
|
const elementName = ast.JSXElement.getName(node);
|
|
47
57
|
if (elementName !== 'strong') {
|
|
48
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
success: false
|
|
60
|
+
};
|
|
49
61
|
}
|
|
50
62
|
if (!node.children.length) {
|
|
51
|
-
return
|
|
63
|
+
return {
|
|
64
|
+
success: false
|
|
65
|
+
};
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
// Element has no unallowed props
|
|
55
69
|
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
56
|
-
return
|
|
70
|
+
return {
|
|
71
|
+
success: true,
|
|
72
|
+
autoFixable: false
|
|
73
|
+
};
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
60
77
|
const importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
61
78
|
if (importDeclaration.length > 1) {
|
|
62
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
autoFixable: false
|
|
82
|
+
};
|
|
63
83
|
}
|
|
64
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
autoFixable: true
|
|
87
|
+
};
|
|
65
88
|
},
|
|
66
89
|
_fix(node, {
|
|
67
90
|
context,
|