@atlaskit/eslint-plugin-design-system 10.12.5 → 10.14.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 +30 -0
- package/README.md +3 -3
- package/dist/cjs/presets/all.codegen.js +4 -5
- package/dist/cjs/presets/recommended.codegen.js +4 -5
- package/dist/cjs/rules/no-empty-styled-expression/index.js +1 -2
- package/dist/cjs/rules/no-exported-css/index.js +1 -2
- package/dist/cjs/rules/no-exported-keyframes/index.js +1 -2
- package/dist/cjs/rules/no-invalid-css-map/index.js +4 -1
- package/dist/cjs/rules/no-legacy-icons/helpers.js +3 -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/presets/all.codegen.js +4 -5
- package/dist/es2019/presets/recommended.codegen.js +4 -5
- package/dist/es2019/rules/no-empty-styled-expression/index.js +1 -2
- package/dist/es2019/rules/no-exported-css/index.js +1 -2
- package/dist/es2019/rules/no-exported-keyframes/index.js +1 -2
- package/dist/es2019/rules/no-invalid-css-map/index.js +4 -1
- package/dist/es2019/rules/no-legacy-icons/helpers.js +3 -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/presets/all.codegen.js +4 -5
- package/dist/esm/presets/recommended.codegen.js +4 -5
- package/dist/esm/rules/no-empty-styled-expression/index.js +1 -2
- package/dist/esm/rules/no-exported-css/index.js +1 -2
- package/dist/esm/rules/no-exported-keyframes/index.js +1 -2
- package/dist/esm/rules/no-invalid-css-map/index.js +4 -1
- package/dist/esm/rules/no-legacy-icons/helpers.js +3 -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/index.codegen.d.ts +6 -8
- package/dist/types/presets/all.codegen.d.ts +4 -5
- package/dist/types/presets/recommended.codegen.d.ts +4 -5
- package/dist/types/rules/ensure-design-token-usage/rule-meta.d.ts +43 -2
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +13 -1
- 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/index.codegen.d.ts +6 -8
- package/dist/types-ts4.5/presets/all.codegen.d.ts +4 -5
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +4 -5
- package/dist/types-ts4.5/rules/ensure-design-token-usage/rule-meta.d.ts +43 -2
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +13 -1
- 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
|
@@ -24,58 +24,82 @@ var SpanElements = exports.SpanElements = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Check whether all criteria needed to make a transformation are met
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} : {
|
|
43
|
-
suggest: [{
|
|
44
|
-
desc: "Convert to Text",
|
|
27
|
+
var _SpanElements$_check = SpanElements._check(node, {
|
|
28
|
+
context: context,
|
|
29
|
+
config: config
|
|
30
|
+
}),
|
|
31
|
+
success = _SpanElements$_check.success,
|
|
32
|
+
autoFixable = _SpanElements$_check.autoFixable;
|
|
33
|
+
if (success && autoFixable) {
|
|
34
|
+
var fix = SpanElements._fix(node, {
|
|
35
|
+
context: context,
|
|
36
|
+
config: config
|
|
37
|
+
});
|
|
38
|
+
context.report(_objectSpread({
|
|
39
|
+
node: node.openingElement,
|
|
40
|
+
messageId: 'preferPrimitivesText'
|
|
41
|
+
}, config.enableUnsafeAutofix ? {
|
|
45
42
|
fix: fix
|
|
46
|
-
}
|
|
47
|
-
|
|
43
|
+
} : {
|
|
44
|
+
suggest: [{
|
|
45
|
+
desc: "Convert to Text",
|
|
46
|
+
fix: fix
|
|
47
|
+
}]
|
|
48
|
+
}));
|
|
49
|
+
} else if (success && config.enableUnsafeReport) {
|
|
50
|
+
context.report({
|
|
51
|
+
node: node.openingElement,
|
|
52
|
+
messageId: 'preferPrimitivesText'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
48
55
|
},
|
|
49
56
|
_check: function _check(node, _ref2) {
|
|
50
57
|
var context = _ref2.context,
|
|
51
58
|
config = _ref2.config;
|
|
52
59
|
if (!config.patterns.includes('span-elements')) {
|
|
53
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
success: false
|
|
62
|
+
};
|
|
54
63
|
}
|
|
55
64
|
var elementName = ast.JSXElement.getName(node);
|
|
56
65
|
if (elementName !== 'span') {
|
|
57
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
success: false
|
|
68
|
+
};
|
|
58
69
|
}
|
|
59
70
|
if (!node.children.length) {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Element has no unallowed props
|
|
64
|
-
if (!ast.JSXElement.hasAllowedAttrsOnly(node, _common.allowedAttrs)) {
|
|
65
|
-
return false;
|
|
71
|
+
return {
|
|
72
|
+
success: false
|
|
73
|
+
};
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
// Only allow elements with strings as children
|
|
69
77
|
if (!(0, _common.hasTextChildrenOnly)(node)) {
|
|
70
|
-
return
|
|
78
|
+
return {
|
|
79
|
+
success: false
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Element has no unallowed props
|
|
84
|
+
if (!ast.JSXElement.hasAllowedAttrsOnly(node, _common.allowedAttrs)) {
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
autoFixable: false
|
|
88
|
+
};
|
|
71
89
|
}
|
|
72
|
-
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
73
90
|
|
|
74
91
|
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
92
|
+
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
75
93
|
if (importDeclaration.length > 1) {
|
|
76
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
autoFixable: false
|
|
97
|
+
};
|
|
77
98
|
}
|
|
78
|
-
return
|
|
99
|
+
return {
|
|
100
|
+
success: true,
|
|
101
|
+
autoFixable: true
|
|
102
|
+
};
|
|
79
103
|
},
|
|
80
104
|
_fix: function _fix(node, _ref3) {
|
|
81
105
|
var context = _ref3.context,
|
|
@@ -24,53 +24,75 @@ var StrongElements = exports.StrongElements = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Check whether all criteria needed to make a transformation are met
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} : {
|
|
43
|
-
suggest: [{
|
|
44
|
-
desc: "Convert to Text",
|
|
27
|
+
var _StrongElements$_chec = StrongElements._check(node, {
|
|
28
|
+
context: context,
|
|
29
|
+
config: config
|
|
30
|
+
}),
|
|
31
|
+
success = _StrongElements$_chec.success,
|
|
32
|
+
autoFixable = _StrongElements$_chec.autoFixable;
|
|
33
|
+
if (success && autoFixable) {
|
|
34
|
+
var fix = StrongElements._fix(node, {
|
|
35
|
+
context: context,
|
|
36
|
+
config: config
|
|
37
|
+
});
|
|
38
|
+
context.report(_objectSpread({
|
|
39
|
+
node: node.openingElement,
|
|
40
|
+
messageId: 'preferPrimitivesText'
|
|
41
|
+
}, config.enableUnsafeAutofix ? {
|
|
45
42
|
fix: fix
|
|
46
|
-
}
|
|
47
|
-
|
|
43
|
+
} : {
|
|
44
|
+
suggest: [{
|
|
45
|
+
desc: "Convert to Text",
|
|
46
|
+
fix: fix
|
|
47
|
+
}]
|
|
48
|
+
}));
|
|
49
|
+
} else if (success && config.enableUnsafeReport) {
|
|
50
|
+
context.report({
|
|
51
|
+
node: node.openingElement,
|
|
52
|
+
messageId: 'preferPrimitivesText'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
48
55
|
},
|
|
49
56
|
_check: function _check(node, _ref2) {
|
|
50
57
|
var context = _ref2.context,
|
|
51
58
|
config = _ref2.config;
|
|
52
59
|
if (!config.patterns.includes('strong-elements')) {
|
|
53
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
success: false
|
|
62
|
+
};
|
|
54
63
|
}
|
|
55
64
|
var elementName = ast.JSXElement.getName(node);
|
|
56
65
|
if (elementName !== 'strong') {
|
|
57
|
-
return
|
|
66
|
+
return {
|
|
67
|
+
success: false
|
|
68
|
+
};
|
|
58
69
|
}
|
|
59
70
|
if (!node.children.length) {
|
|
60
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
success: false
|
|
73
|
+
};
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
// Element has no unallowed props
|
|
64
77
|
if (!ast.JSXElement.hasAllowedAttrsOnly(node, _common.allowedAttrs)) {
|
|
65
|
-
return
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
autoFixable: false
|
|
81
|
+
};
|
|
66
82
|
}
|
|
67
83
|
|
|
68
84
|
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
69
85
|
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
70
86
|
if (importDeclaration.length > 1) {
|
|
71
|
-
return
|
|
87
|
+
return {
|
|
88
|
+
success: true,
|
|
89
|
+
autoFixable: false
|
|
90
|
+
};
|
|
72
91
|
}
|
|
73
|
-
return
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
autoFixable: true
|
|
95
|
+
};
|
|
74
96
|
},
|
|
75
97
|
_fix: function _fix(node, _ref3) {
|
|
76
98
|
var context = _ref3.context,
|
|
@@ -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::b6947ac630ea512fe3f4e3f44abb6783>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -17,12 +17,11 @@ export default {
|
|
|
17
17
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
18
18
|
'@atlaskit/design-system/no-deprecated-imports': 'error',
|
|
19
19
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
20
|
-
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
21
|
-
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
22
|
-
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
23
20
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
24
21
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
25
|
-
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
22
|
+
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
23
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
24
|
+
}],
|
|
26
25
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
|
|
27
26
|
'@atlaskit/design-system/no-legacy-icons': 'warn',
|
|
28
27
|
'@atlaskit/design-system/no-margin': 'warn',
|
|
@@ -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::9b6bccf688f4ee18dd0d49dbce48e475>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -14,12 +14,11 @@ export default {
|
|
|
14
14
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
15
15
|
'@atlaskit/design-system/no-deprecated-imports': 'error',
|
|
16
16
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
17
|
-
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
18
|
-
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
19
|
-
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
20
17
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
21
18
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
22
|
-
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
19
|
+
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
20
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
21
|
+
}],
|
|
23
22
|
'@atlaskit/design-system/no-nested-styles': 'error',
|
|
24
23
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
25
24
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
@@ -40,8 +40,7 @@ const noEmptyStyledExpressionRule = createLintRule({
|
|
|
40
40
|
name: 'no-empty-styled-expression',
|
|
41
41
|
docs: {
|
|
42
42
|
description: 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
|
|
43
|
-
|
|
44
|
-
severity: 'warn'
|
|
43
|
+
removeFromPresets: true // effectively disable this rule here, this is configured by `@atlaskit/ui-styling-standard` instead
|
|
45
44
|
},
|
|
46
45
|
messages: {
|
|
47
46
|
unexpected: 'Found an empty expression, or empty object argument passed to `styled` function call. This unnecessarily causes a major performance penalty - please use a plain JSX element or a React fragment instead (e.g. `<div>Hello</div>` or `<>Hello</>`).'
|
|
@@ -7,8 +7,7 @@ const noExportedCssRule = createLintRule({
|
|
|
7
7
|
type: 'problem',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
10
|
-
|
|
11
|
-
severity: 'warn'
|
|
10
|
+
removeFromPresets: true // effectively disable this rule here, this is overriden by `@atlaskit/ui-styling-standard` instead
|
|
12
11
|
},
|
|
13
12
|
messages: {
|
|
14
13
|
unexpected: "`css` can't be exported - this will cause unexpected behaviour at runtime. Instead, please move your `css(...)` code to the same file where these styles are being used."
|
|
@@ -7,8 +7,7 @@ const noExportedKeyframesRule = createLintRule({
|
|
|
7
7
|
type: 'problem',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
10
|
-
|
|
11
|
-
severity: 'warn'
|
|
10
|
+
removeFromPresets: true // effectively disable this rule here, this is overriden by `@atlaskit/ui-styling-standard` instead
|
|
12
11
|
},
|
|
13
12
|
messages: {
|
|
14
13
|
unexpected: "`keyframes` can't be exported - this will cause unexpected behaviour at runtime. Instead, please move your `keyframes(...)` code to the same file where these styles are being used."
|
|
@@ -58,7 +58,10 @@ const noInvalidCssMapRule = createLintRule({
|
|
|
58
58
|
docs: {
|
|
59
59
|
description: "Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking.",
|
|
60
60
|
recommended: true,
|
|
61
|
-
severity: 'error'
|
|
61
|
+
severity: 'error',
|
|
62
|
+
pluginConfig: {
|
|
63
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
64
|
+
}
|
|
62
65
|
},
|
|
63
66
|
messages: {
|
|
64
67
|
mustBeTopLevelScope: 'cssMap must only be used in the top-most scope of the module.',
|
|
@@ -121,12 +121,12 @@ export const createGuidance = (iconPackage, insideNewButton = false, size) => {
|
|
|
121
121
|
* @returns True if the color can be migrated, false otherwise
|
|
122
122
|
*/
|
|
123
123
|
export const canMigrateColor = color => {
|
|
124
|
-
if (color.match(/^color\.
|
|
125
|
-
return true;
|
|
126
|
-
} else if (color.match(/^color\.icon/)) {
|
|
124
|
+
if (color.match(/^color\.icon/)) {
|
|
127
125
|
return true;
|
|
128
126
|
} else if (color.match(/^color\.link/)) {
|
|
129
127
|
return true;
|
|
128
|
+
} else if (color.match(/^color\.text/)) {
|
|
129
|
+
return true;
|
|
130
130
|
} else if (color === 'currentColor') {
|
|
131
131
|
return true;
|
|
132
132
|
} else {
|
|
@@ -17,65 +17,96 @@ export const NativeElements = {
|
|
|
17
17
|
config
|
|
18
18
|
}) {
|
|
19
19
|
// Check whether all criteria needed to make a transformation are met
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const fix = NativeElements._fix(node, {
|
|
20
|
+
const {
|
|
21
|
+
success,
|
|
22
|
+
autoFixable
|
|
23
|
+
} = NativeElements._check(node, {
|
|
27
24
|
context,
|
|
28
25
|
config
|
|
29
26
|
});
|
|
30
|
-
|
|
31
|
-
node,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
if (success && autoFixable) {
|
|
28
|
+
const fix = NativeElements._fix(node, {
|
|
29
|
+
context,
|
|
30
|
+
config
|
|
31
|
+
});
|
|
32
|
+
context.report({
|
|
33
|
+
node,
|
|
34
|
+
messageId: 'preferHeading',
|
|
35
|
+
...(config.enableUnsafeAutofix ? {
|
|
38
36
|
fix
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
} : {
|
|
38
|
+
suggest: [{
|
|
39
|
+
desc: `Convert to Heading`,
|
|
40
|
+
fix
|
|
41
|
+
}]
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
} else if (success && config.enableUnsafeReport) {
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: 'preferHeading'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
42
50
|
},
|
|
43
51
|
_check(node, {
|
|
44
52
|
config
|
|
45
53
|
}) {
|
|
46
54
|
if (!config.patterns.includes('native-elements')) {
|
|
47
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
success: false
|
|
57
|
+
};
|
|
48
58
|
}
|
|
49
59
|
if (!isNodeOfType(node, 'JSXElement')) {
|
|
50
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
success: false
|
|
62
|
+
};
|
|
51
63
|
}
|
|
52
64
|
if (!node.children.length) {
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return false;
|
|
65
|
+
return {
|
|
66
|
+
success: false
|
|
67
|
+
};
|
|
57
68
|
}
|
|
58
69
|
const elementName = ast.JSXElement.getName(node);
|
|
59
70
|
if (!Object.keys(tagSizeMap).includes(elementName)) {
|
|
60
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
success: false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (!node.parent) {
|
|
76
|
+
return {
|
|
77
|
+
success: true,
|
|
78
|
+
autoFixable: false
|
|
79
|
+
};
|
|
61
80
|
}
|
|
62
81
|
|
|
63
82
|
// Element has to be first element of its siblings
|
|
64
83
|
if (!(isNodeOfType(node.parent, 'JSXElement') || isNodeOfType(node.parent, 'JSXFragment'))) {
|
|
65
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
autoFixable: false
|
|
87
|
+
};
|
|
66
88
|
}
|
|
67
89
|
const siblings = ast.JSXElement.getChildren(node.parent);
|
|
68
90
|
if (siblings.length > 1) {
|
|
69
91
|
var _siblings$0$range, _node$range, _siblings$0$range2, _node$range2;
|
|
70
92
|
// Only report if element is first child element
|
|
71
93
|
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])) {
|
|
72
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
autoFixable: false
|
|
97
|
+
};
|
|
73
98
|
}
|
|
74
99
|
}
|
|
75
100
|
if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
|
|
76
|
-
return
|
|
101
|
+
return {
|
|
102
|
+
success: true,
|
|
103
|
+
autoFixable: false
|
|
104
|
+
};
|
|
77
105
|
}
|
|
78
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
success: true,
|
|
108
|
+
autoFixable: true
|
|
109
|
+
};
|
|
79
110
|
},
|
|
80
111
|
_fix(node, {
|
|
81
112
|
context
|
|
@@ -2,7 +2,8 @@ const defaults = {
|
|
|
2
2
|
failSilently: false,
|
|
3
3
|
patterns: ['paragraph-elements', 'span-elements', 'strong-elements', 'emphasis-elements'],
|
|
4
4
|
inheritColor: false,
|
|
5
|
-
enableUnsafeAutofix: false
|
|
5
|
+
enableUnsafeAutofix: false,
|
|
6
|
+
enableUnsafeReport: false
|
|
6
7
|
};
|
|
7
8
|
export const getConfig = overrides => {
|
|
8
9
|
return Object.assign({}, defaults, overrides);
|
|
@@ -13,55 +13,78 @@ export const EmphasisElements = {
|
|
|
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 = EmphasisElements._fix(node, {
|
|
16
|
+
const {
|
|
17
|
+
success,
|
|
18
|
+
autoFixable
|
|
19
|
+
} = EmphasisElements._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 = EmphasisElements._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('emphasis-elements')) {
|
|
44
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
success: false
|
|
54
|
+
};
|
|
45
55
|
}
|
|
46
56
|
const elementName = ast.JSXElement.getName(node);
|
|
47
57
|
if (elementName !== 'em') {
|
|
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,
|