@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 10.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#128926](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128926)
|
|
8
|
+
[`5df26d24db3c7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5df26d24db3c7) - -
|
|
9
|
+
Remove config for rules that do not belong in this plugin long-term:
|
|
10
|
+
'@atlaskit/design-system/no-empty-styled-expression', '@atlaskit/design-system/no-exported-css',
|
|
11
|
+
'@atlaskit/design-system/no-exported-keyframes' — they may be removed in a future release and
|
|
12
|
+
prefer `@atlaskit/eslint-plugin/ui-styling-standard/recommended` for this type of rules in the
|
|
13
|
+
future.
|
|
14
|
+
- Reconfigure '@atlaskit/design-system/no-invalid-css-map' to work properly of the box alongside
|
|
15
|
+
ADS.
|
|
16
|
+
|
|
17
|
+
## 10.13.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [#128427](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128427)
|
|
22
|
+
[`ade1e717764e2`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ade1e717764e2) -
|
|
23
|
+
Update no-legacy-icons eslint rule following changes to color prop of new icon components
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [#127303](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/127303)
|
|
28
|
+
[`8c7d9e510fc2a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8c7d9e510fc2a) -
|
|
29
|
+
New rule config option `enableUnsafeReport` for `use-primitives-text` and `use-heading` to enable
|
|
30
|
+
error reporting for native typography elements that are not autofixable.
|
|
31
|
+
- Updated dependencies
|
|
32
|
+
|
|
3
33
|
## 10.12.5
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -60,9 +60,9 @@ module.exports = {
|
|
|
60
60
|
| <a href="./src/rules/no-deprecated-design-token-usage/README.md">no-deprecated-design-token-usage</a> | Disallow using deprecated design tokens. | Yes | Yes | |
|
|
61
61
|
| <a href="./src/rules/no-deprecated-imports/README.md">no-deprecated-imports</a> | Disallow importing deprecated modules. | Yes | | |
|
|
62
62
|
| <a href="./src/rules/no-direct-use-of-web-platform-drag-and-drop/README.md">no-direct-use-of-web-platform-drag-and-drop</a> | Disallow using direct use of native drag and drop (please use Pragmatic drag and drop) | Yes | | |
|
|
63
|
-
| <a href="./src/rules/no-empty-styled-expression/README.md">no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). |
|
|
64
|
-
| <a href="./src/rules/no-exported-css/README.md">no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. |
|
|
65
|
-
| <a href="./src/rules/no-exported-keyframes/README.md">no-exported-keyframes</a> | Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. |
|
|
63
|
+
| <a href="./src/rules/no-empty-styled-expression/README.md">no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | | | |
|
|
64
|
+
| <a href="./src/rules/no-exported-css/README.md">no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | | | |
|
|
65
|
+
| <a href="./src/rules/no-exported-keyframes/README.md">no-exported-keyframes</a> | Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | | | |
|
|
66
66
|
| <a href="./src/rules/no-html-anchor/README.md">no-html-anchor</a> | Discourage direct usage of HTML anchor elements in favor of Atlassian Design System link components. | Yes | | |
|
|
67
67
|
| <a href="./src/rules/no-html-button/README.md">no-html-button</a> | Discourage direct usage of HTML button elements in favor of Atlassian Design System button components. | Yes | | |
|
|
68
68
|
| <a href="./src/rules/no-invalid-css-map/README.md">no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::b6947ac630ea512fe3f4e3f44abb6783>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -23,12 +23,11 @@ var _default = exports.default = {
|
|
|
23
23
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
24
24
|
'@atlaskit/design-system/no-deprecated-imports': 'error',
|
|
25
25
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
26
|
-
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
27
|
-
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
28
|
-
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
29
26
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
30
27
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
31
|
-
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
28
|
+
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
29
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
30
|
+
}],
|
|
32
31
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
|
|
33
32
|
'@atlaskit/design-system/no-legacy-icons': 'warn',
|
|
34
33
|
'@atlaskit/design-system/no-margin': 'warn',
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::9b6bccf688f4ee18dd0d49dbce48e475>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -20,12 +20,11 @@ var _default = exports.default = {
|
|
|
20
20
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
21
21
|
'@atlaskit/design-system/no-deprecated-imports': 'error',
|
|
22
22
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
23
|
-
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
24
|
-
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
25
|
-
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
26
23
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
27
24
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
28
|
-
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
25
|
+
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
26
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
27
|
+
}],
|
|
29
28
|
'@atlaskit/design-system/no-nested-styles': 'error',
|
|
30
29
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
31
30
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
@@ -50,8 +50,7 @@ var noEmptyStyledExpressionRule = (0, _createRule.createLintRule)({
|
|
|
50
50
|
name: 'no-empty-styled-expression',
|
|
51
51
|
docs: {
|
|
52
52
|
description: 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
|
|
53
|
-
|
|
54
|
-
severity: 'warn'
|
|
53
|
+
removeFromPresets: true // effectively disable this rule here, this is configured by `@atlaskit/ui-styling-standard` instead
|
|
55
54
|
},
|
|
56
55
|
messages: {
|
|
57
56
|
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</>`).'
|
|
@@ -13,8 +13,7 @@ var noExportedCssRule = (0, _createRule.createLintRule)({
|
|
|
13
13
|
type: 'problem',
|
|
14
14
|
docs: {
|
|
15
15
|
description: 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
16
|
-
|
|
17
|
-
severity: 'warn'
|
|
16
|
+
removeFromPresets: true // effectively disable this rule here, this is overriden by `@atlaskit/ui-styling-standard` instead
|
|
18
17
|
},
|
|
19
18
|
messages: {
|
|
20
19
|
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."
|
|
@@ -13,8 +13,7 @@ var noExportedKeyframesRule = (0, _createRule.createLintRule)({
|
|
|
13
13
|
type: 'problem',
|
|
14
14
|
docs: {
|
|
15
15
|
description: 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
16
|
-
|
|
17
|
-
severity: 'warn'
|
|
16
|
+
removeFromPresets: true // effectively disable this rule here, this is overriden by `@atlaskit/ui-styling-standard` instead
|
|
18
17
|
},
|
|
19
18
|
messages: {
|
|
20
19
|
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."
|
|
@@ -65,7 +65,10 @@ var noInvalidCssMapRule = (0, _createRule.createLintRule)({
|
|
|
65
65
|
docs: {
|
|
66
66
|
description: "Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking.",
|
|
67
67
|
recommended: true,
|
|
68
|
-
severity: 'error'
|
|
68
|
+
severity: 'error',
|
|
69
|
+
pluginConfig: {
|
|
70
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
71
|
+
}
|
|
69
72
|
},
|
|
70
73
|
messages: {
|
|
71
74
|
mustBeTopLevelScope: 'cssMap must only be used in the top-most scope of the module.',
|
|
@@ -142,12 +142,12 @@ var createGuidance = exports.createGuidance = function createGuidance(iconPackag
|
|
|
142
142
|
* @returns True if the color can be migrated, false otherwise
|
|
143
143
|
*/
|
|
144
144
|
var canMigrateColor = exports.canMigrateColor = function canMigrateColor(color) {
|
|
145
|
-
if (color.match(/^color\.
|
|
146
|
-
return true;
|
|
147
|
-
} else if (color.match(/^color\.icon/)) {
|
|
145
|
+
if (color.match(/^color\.icon/)) {
|
|
148
146
|
return true;
|
|
149
147
|
} else if (color.match(/^color\.link/)) {
|
|
150
148
|
return true;
|
|
149
|
+
} else if (color.match(/^color\.text/)) {
|
|
150
|
+
return true;
|
|
151
151
|
} else if (color === 'currentColor') {
|
|
152
152
|
return true;
|
|
153
153
|
} else {
|
|
@@ -7,7 +7,8 @@ exports.getConfig = void 0;
|
|
|
7
7
|
var defaults = {
|
|
8
8
|
failSilently: false,
|
|
9
9
|
patterns: ['native-elements'],
|
|
10
|
-
enableUnsafeAutofix: false
|
|
10
|
+
enableUnsafeAutofix: false,
|
|
11
|
+
enableUnsafeReport: false
|
|
11
12
|
};
|
|
12
13
|
var getConfig = exports.getConfig = function getConfig(overrides) {
|
|
13
14
|
return Object.assign({}, defaults, overrides);
|
|
@@ -28,63 +28,93 @@ var NativeElements = exports.NativeElements = {
|
|
|
28
28
|
var context = _ref.context,
|
|
29
29
|
config = _ref.config;
|
|
30
30
|
// Check whether all criteria needed to make a transformation are met
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} : {
|
|
47
|
-
suggest: [{
|
|
48
|
-
desc: "Convert to Heading",
|
|
31
|
+
var _NativeElements$_chec = NativeElements._check(node, {
|
|
32
|
+
context: context,
|
|
33
|
+
config: config
|
|
34
|
+
}),
|
|
35
|
+
success = _NativeElements$_chec.success,
|
|
36
|
+
autoFixable = _NativeElements$_chec.autoFixable;
|
|
37
|
+
if (success && autoFixable) {
|
|
38
|
+
var fix = NativeElements._fix(node, {
|
|
39
|
+
context: context,
|
|
40
|
+
config: config
|
|
41
|
+
});
|
|
42
|
+
context.report(_objectSpread({
|
|
43
|
+
node: node,
|
|
44
|
+
messageId: 'preferHeading'
|
|
45
|
+
}, config.enableUnsafeAutofix ? {
|
|
49
46
|
fix: fix
|
|
50
|
-
}
|
|
51
|
-
|
|
47
|
+
} : {
|
|
48
|
+
suggest: [{
|
|
49
|
+
desc: "Convert to Heading",
|
|
50
|
+
fix: fix
|
|
51
|
+
}]
|
|
52
|
+
}));
|
|
53
|
+
} else if (success && config.enableUnsafeReport) {
|
|
54
|
+
context.report({
|
|
55
|
+
node: node,
|
|
56
|
+
messageId: 'preferHeading'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
52
59
|
},
|
|
53
60
|
_check: function _check(node, _ref2) {
|
|
54
61
|
var config = _ref2.config;
|
|
55
62
|
if (!config.patterns.includes('native-elements')) {
|
|
56
|
-
return
|
|
63
|
+
return {
|
|
64
|
+
success: false
|
|
65
|
+
};
|
|
57
66
|
}
|
|
58
67
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
|
|
59
|
-
return
|
|
68
|
+
return {
|
|
69
|
+
success: false
|
|
70
|
+
};
|
|
60
71
|
}
|
|
61
72
|
if (!node.children.length) {
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return false;
|
|
73
|
+
return {
|
|
74
|
+
success: false
|
|
75
|
+
};
|
|
66
76
|
}
|
|
67
77
|
var elementName = ast.JSXElement.getName(node);
|
|
68
78
|
if (!Object.keys(tagSizeMap).includes(elementName)) {
|
|
69
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
success: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (!node.parent) {
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
autoFixable: false
|
|
87
|
+
};
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
// Element has to be first element of its siblings
|
|
73
91
|
if (!((0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXElement') || (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXFragment'))) {
|
|
74
|
-
return
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
autoFixable: false
|
|
95
|
+
};
|
|
75
96
|
}
|
|
76
97
|
var siblings = ast.JSXElement.getChildren(node.parent);
|
|
77
98
|
if (siblings.length > 1) {
|
|
78
99
|
var _siblings$0$range, _node$range, _siblings$0$range2, _node$range2;
|
|
79
100
|
// Only report if element is first child element
|
|
80
101
|
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])) {
|
|
81
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
success: true,
|
|
104
|
+
autoFixable: false
|
|
105
|
+
};
|
|
82
106
|
}
|
|
83
107
|
}
|
|
84
108
|
if (!ast.JSXElement.hasAllowedAttrsOnly(node, _common.allowedAttrs)) {
|
|
85
|
-
return
|
|
109
|
+
return {
|
|
110
|
+
success: true,
|
|
111
|
+
autoFixable: false
|
|
112
|
+
};
|
|
86
113
|
}
|
|
87
|
-
return
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
autoFixable: true
|
|
117
|
+
};
|
|
88
118
|
},
|
|
89
119
|
_fix: function _fix(node, _ref3) {
|
|
90
120
|
var context = _ref3.context;
|
|
@@ -8,7 +8,8 @@ var defaults = {
|
|
|
8
8
|
failSilently: false,
|
|
9
9
|
patterns: ['paragraph-elements', 'span-elements', 'strong-elements', 'emphasis-elements'],
|
|
10
10
|
inheritColor: false,
|
|
11
|
-
enableUnsafeAutofix: false
|
|
11
|
+
enableUnsafeAutofix: false,
|
|
12
|
+
enableUnsafeReport: false
|
|
12
13
|
};
|
|
13
14
|
var getConfig = exports.getConfig = function getConfig(overrides) {
|
|
14
15
|
return Object.assign({}, defaults, overrides);
|
|
@@ -24,53 +24,75 @@ var EmphasisElements = exports.EmphasisElements = {
|
|
|
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 _EmphasisElements$_ch = EmphasisElements._check(node, {
|
|
28
|
+
context: context,
|
|
29
|
+
config: config
|
|
30
|
+
}),
|
|
31
|
+
success = _EmphasisElements$_ch.success,
|
|
32
|
+
autoFixable = _EmphasisElements$_ch.autoFixable;
|
|
33
|
+
if (success && autoFixable) {
|
|
34
|
+
var fix = EmphasisElements._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('emphasis-elements')) {
|
|
53
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
success: false
|
|
62
|
+
};
|
|
54
63
|
}
|
|
55
64
|
var elementName = ast.JSXElement.getName(node);
|
|
56
65
|
if (elementName !== 'em') {
|
|
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,
|
|
@@ -29,55 +29,60 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
29
29
|
config: config
|
|
30
30
|
}),
|
|
31
31
|
success = _ParagraphElements$_c.success,
|
|
32
|
+
autoFixable = _ParagraphElements$_c.autoFixable,
|
|
32
33
|
refs = _ParagraphElements$_c.refs;
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
messageId: 'preferPrimitivesStackedText'
|
|
57
|
-
}, config.enableUnsafeAutofix ? {
|
|
58
|
-
fix: fix
|
|
59
|
-
} : {
|
|
60
|
-
suggest: [{
|
|
61
|
-
desc: "Convert to Text and Stack",
|
|
34
|
+
if (success && autoFixable) {
|
|
35
|
+
if (refs.siblings.length > 1) {
|
|
36
|
+
var _refs$siblings$0$loc, _refs$siblings$loc;
|
|
37
|
+
/**
|
|
38
|
+
* Highlighting from first opening element to last closing element
|
|
39
|
+
* to indicate fix will change all p elements and wrap them in a Stack,
|
|
40
|
+
* falls back to first opening element.
|
|
41
|
+
*/
|
|
42
|
+
var startLoc = (_refs$siblings$0$loc = refs.siblings[0].loc) === null || _refs$siblings$0$loc === void 0 ? void 0 : _refs$siblings$0$loc.start;
|
|
43
|
+
var endLoc = (_refs$siblings$loc = refs.siblings[refs.siblings.length - 1].loc) === null || _refs$siblings$loc === void 0 ? void 0 : _refs$siblings$loc.end;
|
|
44
|
+
var fix = ParagraphElements._fixMultiple(node, {
|
|
45
|
+
context: context,
|
|
46
|
+
config: config,
|
|
47
|
+
refs: refs
|
|
48
|
+
});
|
|
49
|
+
context.report(_objectSpread({
|
|
50
|
+
loc: startLoc && endLoc && {
|
|
51
|
+
start: startLoc,
|
|
52
|
+
end: endLoc
|
|
53
|
+
},
|
|
54
|
+
node: node.openingElement,
|
|
55
|
+
messageId: 'preferPrimitivesStackedText'
|
|
56
|
+
}, config.enableUnsafeAutofix ? {
|
|
62
57
|
fix: fix
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
} : {
|
|
59
|
+
suggest: [{
|
|
60
|
+
desc: "Convert to Text and Stack",
|
|
61
|
+
fix: fix
|
|
62
|
+
}]
|
|
63
|
+
}));
|
|
64
|
+
} else {
|
|
65
|
+
var _fix = ParagraphElements._fixSingle(node, {
|
|
66
|
+
context: context,
|
|
67
|
+
config: config
|
|
68
|
+
});
|
|
69
|
+
context.report(_objectSpread({
|
|
70
|
+
node: node.openingElement,
|
|
71
|
+
messageId: 'preferPrimitivesText'
|
|
72
|
+
}, config.enableUnsafeAutofix ? {
|
|
78
73
|
fix: _fix
|
|
79
|
-
}
|
|
80
|
-
|
|
74
|
+
} : {
|
|
75
|
+
suggest: [{
|
|
76
|
+
desc: "Convert to Text",
|
|
77
|
+
fix: _fix
|
|
78
|
+
}]
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
} else if (success && config.enableUnsafeReport) {
|
|
82
|
+
context.report({
|
|
83
|
+
node: node.openingElement,
|
|
84
|
+
messageId: 'preferPrimitivesText'
|
|
85
|
+
});
|
|
81
86
|
}
|
|
82
87
|
},
|
|
83
88
|
_check: function _check(node, _ref2) {
|
|
@@ -112,7 +117,8 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
112
117
|
// All siblings have to be paragraph elements with no unallowed props
|
|
113
118
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXElement')) {
|
|
114
119
|
return {
|
|
115
|
-
success:
|
|
120
|
+
success: true,
|
|
121
|
+
autoFixable: false,
|
|
116
122
|
refs: {
|
|
117
123
|
siblings: []
|
|
118
124
|
}
|
|
@@ -124,7 +130,8 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
124
130
|
// Only report for the first p element by comparing node location
|
|
125
131
|
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])) {
|
|
126
132
|
return {
|
|
127
|
-
success:
|
|
133
|
+
success: true,
|
|
134
|
+
autoFixable: false,
|
|
128
135
|
refs: {
|
|
129
136
|
siblings: siblings
|
|
130
137
|
}
|
|
@@ -142,7 +149,8 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
142
149
|
});
|
|
143
150
|
if (!siblingsMatch) {
|
|
144
151
|
return {
|
|
145
|
-
success:
|
|
152
|
+
success: true,
|
|
153
|
+
autoFixable: false,
|
|
146
154
|
refs: {
|
|
147
155
|
siblings: siblings
|
|
148
156
|
}
|
|
@@ -150,7 +158,8 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
150
158
|
}
|
|
151
159
|
} else if (!ast.JSXElement.hasAllowedAttrsOnly(node, _common.allowedAttrs)) {
|
|
152
160
|
return {
|
|
153
|
-
success:
|
|
161
|
+
success: true,
|
|
162
|
+
autoFixable: false,
|
|
154
163
|
refs: {
|
|
155
164
|
siblings: siblings
|
|
156
165
|
}
|
|
@@ -161,7 +170,8 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
161
170
|
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
162
171
|
if (importDeclaration.length > 1) {
|
|
163
172
|
return {
|
|
164
|
-
success:
|
|
173
|
+
success: true,
|
|
174
|
+
autoFixable: false,
|
|
165
175
|
refs: {
|
|
166
176
|
siblings: siblings
|
|
167
177
|
}
|
|
@@ -169,6 +179,7 @@ var ParagraphElements = exports.ParagraphElements = {
|
|
|
169
179
|
}
|
|
170
180
|
return {
|
|
171
181
|
success: true,
|
|
182
|
+
autoFixable: true,
|
|
172
183
|
refs: {
|
|
173
184
|
siblings: siblings
|
|
174
185
|
}
|