@atlaskit/eslint-plugin-design-system 9.7.0 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +6 -5
- package/constellation/consistent-css-prop-usage/usage.mdx +44 -30
- package/constellation/ensure-design-token-usage/usage.mdx +12 -7
- package/constellation/ensure-design-token-usage-preview/usage.mdx +2 -1
- package/constellation/icon-label/usage.mdx +5 -3
- package/constellation/index/usage.mdx +4 -2
- package/constellation/no-banned-imports/usage.mdx +3 -1
- package/constellation/no-css-tagged-template-expression/usage.mdx +22 -17
- package/constellation/no-deprecated-apis/usage.mdx +33 -27
- package/constellation/no-deprecated-design-token-usage/usage.mdx +7 -4
- package/constellation/no-deprecated-imports/usage.mdx +31 -27
- package/constellation/no-direct-use-of-web-platform-drag-and-drop/usage.mdx +19 -10
- package/constellation/no-empty-styled-expression/usage.mdx +19 -14
- package/constellation/no-exported-css/usage.mdx +15 -10
- package/constellation/no-exported-keyframes/usage.mdx +15 -10
- package/constellation/no-html-anchor/usage.mdx +40 -0
- package/constellation/no-html-button/usage.mdx +52 -0
- package/constellation/no-invalid-css-map/usage.mdx +69 -58
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +24 -18
- package/constellation/no-margin/usage.mdx +3 -2
- package/constellation/no-nested-styles/usage.mdx +16 -16
- package/constellation/no-physical-properties/usage.mdx +13 -13
- package/constellation/no-styled-tagged-template-expression/usage.mdx +39 -34
- package/constellation/no-unsafe-design-token-usage/usage.mdx +8 -7
- package/constellation/no-unsafe-style-overrides/usage.mdx +10 -7
- package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +8 -2
- package/constellation/prefer-primitives/usage.mdx +3 -2
- package/constellation/use-button-group-label/usage.mdx +4 -2
- package/constellation/use-drawer-label/usage.mdx +4 -2
- package/constellation/use-heading/usage.mdx +7 -4
- package/constellation/use-heading-level-in-spotlight-card/usage.mdx +3 -2
- package/constellation/use-href-in-link-item/usage.mdx +2 -1
- package/constellation/use-popup-label/usage.mdx +5 -2
- package/constellation/use-primitives/usage.mdx +40 -39
- package/constellation/use-primitives-text/usage.mdx +7 -3
- package/constellation/use-tokens-space/usage.mdx +7 -3
- package/constellation/use-tokens-typography/usage.mdx +15 -6
- package/constellation/use-visually-hidden/usage.mdx +2 -1
- package/dist/cjs/common/token-maps.partial.js +49 -0
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +3 -2
- package/dist/cjs/presets/recommended.codegen.js +1 -1
- package/dist/cjs/rules/ensure-design-token-usage/index.js +10 -1
- package/dist/cjs/rules/index.codegen.js +5 -3
- package/dist/cjs/rules/no-html-anchor/index.js +39 -0
- package/dist/cjs/rules/no-html-anchor/node-types/index.js +19 -0
- package/dist/cjs/rules/no-html-anchor/node-types/jsx-element/index.js +28 -0
- package/dist/cjs/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +47 -0
- package/dist/cjs/rules/no-html-anchor/node-types/styled-component/index.js +37 -0
- package/dist/cjs/rules/no-html-anchor/node-types/supported.js +66 -0
- package/dist/cjs/rules/no-html-anchor/utils/get-jsx-element-by-name.js +53 -0
- package/dist/cjs/rules/no-html-button/index.js +39 -0
- package/dist/cjs/rules/no-html-button/node-types/index.js +19 -0
- package/dist/cjs/rules/no-html-button/node-types/jsx-element/index.js +28 -0
- package/dist/cjs/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +47 -0
- package/dist/cjs/rules/no-html-button/node-types/styled-component/index.js +37 -0
- package/dist/cjs/rules/no-html-button/node-types/supported.js +79 -0
- package/dist/cjs/rules/no-html-button/utils/get-jsx-element-by-name.js +53 -0
- package/dist/cjs/rules/utils/is-node.js +4 -6
- package/dist/es2019/common/token-maps.partial.js +42 -0
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +3 -2
- package/dist/es2019/presets/recommended.codegen.js +1 -1
- package/dist/es2019/rules/ensure-design-token-usage/index.js +11 -1
- package/dist/es2019/rules/index.codegen.js +5 -3
- package/dist/es2019/rules/no-html-anchor/index.js +33 -0
- package/dist/es2019/rules/no-html-anchor/node-types/index.js +2 -0
- package/dist/es2019/rules/no-html-anchor/node-types/jsx-element/index.js +20 -0
- package/dist/es2019/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +42 -0
- package/dist/es2019/rules/no-html-anchor/node-types/styled-component/index.js +32 -0
- package/dist/es2019/rules/no-html-anchor/node-types/supported.js +56 -0
- package/dist/es2019/rules/no-html-anchor/utils/get-jsx-element-by-name.js +39 -0
- package/dist/es2019/rules/no-html-button/index.js +33 -0
- package/dist/es2019/rules/no-html-button/node-types/index.js +2 -0
- package/dist/es2019/rules/no-html-button/node-types/jsx-element/index.js +20 -0
- package/dist/es2019/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +42 -0
- package/dist/es2019/rules/no-html-button/node-types/styled-component/index.js +32 -0
- package/dist/es2019/rules/no-html-button/node-types/supported.js +69 -0
- package/dist/es2019/rules/no-html-button/utils/get-jsx-element-by-name.js +39 -0
- package/dist/es2019/rules/utils/is-node.js +4 -4
- package/dist/esm/common/token-maps.partial.js +42 -0
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +3 -2
- package/dist/esm/presets/recommended.codegen.js +1 -1
- package/dist/esm/rules/ensure-design-token-usage/index.js +10 -1
- package/dist/esm/rules/index.codegen.js +5 -3
- package/dist/esm/rules/no-html-anchor/index.js +33 -0
- package/dist/esm/rules/no-html-anchor/node-types/index.js +2 -0
- package/dist/esm/rules/no-html-anchor/node-types/jsx-element/index.js +19 -0
- package/dist/esm/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +42 -0
- package/dist/esm/rules/no-html-anchor/node-types/styled-component/index.js +31 -0
- package/dist/esm/rules/no-html-anchor/node-types/supported.js +57 -0
- package/dist/esm/rules/no-html-anchor/utils/get-jsx-element-by-name.js +47 -0
- package/dist/esm/rules/no-html-button/index.js +33 -0
- package/dist/esm/rules/no-html-button/node-types/index.js +2 -0
- package/dist/esm/rules/no-html-button/node-types/jsx-element/index.js +19 -0
- package/dist/esm/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +42 -0
- package/dist/esm/rules/no-html-button/node-types/styled-component/index.js +31 -0
- package/dist/esm/rules/no-html-button/node-types/supported.js +70 -0
- package/dist/esm/rules/no-html-button/utils/get-jsx-element-by-name.js +47 -0
- package/dist/esm/rules/utils/is-node.js +4 -6
- package/dist/types/common/token-maps.partial.d.ts +65 -0
- package/dist/types/index.codegen.d.ts +2 -1
- package/dist/types/presets/all.codegen.d.ts +3 -2
- package/dist/types/presets/recommended.codegen.d.ts +1 -1
- package/dist/types/rules/ensure-design-token-usage/index.d.ts +1 -1
- package/dist/types/rules/index.codegen.d.ts +2 -1
- package/dist/types/rules/no-html-anchor/index.d.ts +3 -0
- package/dist/types/rules/no-html-anchor/node-types/index.d.ts +2 -0
- package/dist/types/rules/no-html-anchor/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.d.ts +6 -0
- package/dist/types/rules/no-html-anchor/node-types/styled-component/index.d.ts +8 -0
- package/dist/types/rules/no-html-anchor/node-types/supported.d.ts +7 -0
- package/dist/types/rules/no-html-anchor/utils/get-jsx-element-by-name.d.ts +6 -0
- package/dist/types/rules/no-html-button/index.d.ts +3 -0
- package/dist/types/rules/no-html-button/node-types/index.d.ts +2 -0
- package/dist/types/rules/no-html-button/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types/rules/no-html-button/node-types/styled-component/get-styled-component-call.d.ts +6 -0
- package/dist/types/rules/no-html-button/node-types/styled-component/index.d.ts +8 -0
- package/dist/types/rules/no-html-button/node-types/supported.d.ts +7 -0
- package/dist/types/rules/no-html-button/utils/get-jsx-element-by-name.d.ts +6 -0
- package/dist/types/rules/utils/is-node.d.ts +3 -3
- package/dist/types-ts4.5/common/token-maps.partial.d.ts +65 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -2
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/ensure-design-token-usage/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/no-html-anchor/node-types/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-html-anchor/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.d.ts +6 -0
- package/dist/types-ts4.5/rules/no-html-anchor/node-types/styled-component/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-anchor/node-types/supported.d.ts +7 -0
- package/dist/types-ts4.5/rules/no-html-anchor/utils/get-jsx-element-by-name.d.ts +6 -0
- package/dist/types-ts4.5/rules/no-html-button/node-types/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-html-button/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-button/node-types/styled-component/get-styled-component-call.d.ts +6 -0
- package/dist/types-ts4.5/rules/no-html-button/node-types/styled-component/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-button/node-types/supported.d.ts +7 -0
- package/dist/types-ts4.5/rules/no-html-button/utils/get-jsx-element-by-name.d.ts +6 -0
- package/dist/types-ts4.5/rules/utils/is-node.d.ts +3 -3
- package/package.json +3 -2
- package/constellation/no-html-button-element/usage.mdx +0 -26
- package/dist/cjs/rules/no-html-button-element/index.js +0 -107
- package/dist/cjs/rules/no-html-button-element/utils.js +0 -18
- package/dist/es2019/rules/no-html-button-element/index.js +0 -101
- package/dist/es2019/rules/no-html-button-element/utils.js +0 -12
- package/dist/esm/rules/no-html-button-element/index.js +0 -101
- package/dist/esm/rules/no-html-button-element/utils.js +0 -12
- package/dist/types/rules/no-html-button-element/utils.d.ts +0 -2
- package/dist/types-ts4.5/rules/no-html-button-element/utils.d.ts +0 -2
- /package/dist/types-ts4.5/rules/{no-html-button-element → no-html-anchor}/index.d.ts +0 -0
- /package/dist/{types/rules/no-html-button-element → types-ts4.5/rules/no-html-button}/index.d.ts +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
-
var _createRule = require("../utils/create-rule");
|
|
9
|
-
var _utils = require("./utils");
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
|
-
|
|
12
|
-
var buttonDocsUrl = 'https://atlassian.design/components/button';
|
|
13
|
-
var pressableDocsUrl = 'https://atlassian.design/components/primitives/pressable/';
|
|
14
|
-
var rule = (0, _createRule.createLintRule)({
|
|
15
|
-
meta: {
|
|
16
|
-
name: 'no-html-button-element',
|
|
17
|
-
type: 'suggestion',
|
|
18
|
-
hasSuggestions: false,
|
|
19
|
-
docs: {
|
|
20
|
-
description: 'Prevent direct usage of HTML button elements and enforce usage of Button and Pressable.',
|
|
21
|
-
recommended: false,
|
|
22
|
-
severity: 'warn'
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
noHtmlButtonElement: "This \"{{element}}\" should be replaced with a Button component. If beyond the capabilities of the Button component, use the Pressable primitive. See ".concat(buttonDocsUrl, " and ").concat(pressableDocsUrl, " for guidance.")
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
create: function create(context) {
|
|
29
|
-
return {
|
|
30
|
-
// Look for <button> HTML elements
|
|
31
|
-
// Look for styled calls/templates - styled.button(...)
|
|
32
|
-
JSXOpeningElement: function JSXOpeningElement(node) {
|
|
33
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXOpeningElement')) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier')) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
var suggest = (0, _utils.shouldSuggest)(node === null || node === void 0 ? void 0 : node.parent);
|
|
40
|
-
if (suggest) {
|
|
41
|
-
context.report({
|
|
42
|
-
node: node,
|
|
43
|
-
messageId: 'noHtmlButtonElement',
|
|
44
|
-
data: {
|
|
45
|
-
element: node.name.name
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
// styled.button`` | styled2.button`` | styled.button()
|
|
51
|
-
'MemberExpression[object.name="styled"],MemberExpression[object.name="styled2"]': function MemberExpressionObjectNameStyledMemberExpressionObjectNameStyled2(node) {
|
|
52
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'MemberExpression')) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// styled.button``
|
|
57
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(node.property, 'Identifier')) {
|
|
58
|
-
if (node.property.name === 'button') {
|
|
59
|
-
var styledIdentifier = node.object.name;
|
|
60
|
-
var elementName = node.property.name;
|
|
61
|
-
|
|
62
|
-
// Including the `styled.` portion in the message to help makers understand it's not just the `button` element that should be replaced
|
|
63
|
-
var reportName = "".concat(styledIdentifier, ".").concat(elementName); // styled.button
|
|
64
|
-
|
|
65
|
-
context.report({
|
|
66
|
-
node: node,
|
|
67
|
-
messageId: 'noHtmlButtonElement',
|
|
68
|
-
data: {
|
|
69
|
-
element: reportName
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
// styled(X)``
|
|
76
|
-
'CallExpression[callee.name="styled"]': function CallExpressionCalleeNameStyled(node) {
|
|
77
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// styled('button')`` - We only care about 'button', ignore extending other components
|
|
82
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(node.arguments[0], 'Literal')) {
|
|
83
|
-
var argValue = node.arguments[0].raw;
|
|
84
|
-
if (typeof argValue === 'string') {
|
|
85
|
-
var suggest = argValue.replaceAll("'", '') === 'button';
|
|
86
|
-
if (suggest) {
|
|
87
|
-
var styledIdentifier = node.callee.name;
|
|
88
|
-
var elementName = argValue;
|
|
89
|
-
|
|
90
|
-
// Including the `styled()` portion in the message to help makers understand it's not just the `button` element that should be replaced
|
|
91
|
-
var reportName = "".concat(styledIdentifier, "(").concat(elementName, ")"); // styled('button')
|
|
92
|
-
|
|
93
|
-
context.report({
|
|
94
|
-
node: node,
|
|
95
|
-
messageId: 'noHtmlButtonElement',
|
|
96
|
-
data: {
|
|
97
|
-
element: reportName
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
var _default = exports.default = rule;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.shouldSuggest = void 0;
|
|
7
|
-
var isButtonHtmlElement = function isButtonHtmlElement(node) {
|
|
8
|
-
return node.openingElement.name.name === 'button';
|
|
9
|
-
};
|
|
10
|
-
var shouldSuggest = exports.shouldSuggest = function shouldSuggest(node) {
|
|
11
|
-
if (!node) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (!isButtonHtmlElement(node)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
|
|
3
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
-
import { createLintRule } from '../utils/create-rule';
|
|
5
|
-
import { shouldSuggest } from './utils';
|
|
6
|
-
const buttonDocsUrl = 'https://atlassian.design/components/button';
|
|
7
|
-
const pressableDocsUrl = 'https://atlassian.design/components/primitives/pressable/';
|
|
8
|
-
const rule = createLintRule({
|
|
9
|
-
meta: {
|
|
10
|
-
name: 'no-html-button-element',
|
|
11
|
-
type: 'suggestion',
|
|
12
|
-
hasSuggestions: false,
|
|
13
|
-
docs: {
|
|
14
|
-
description: 'Prevent direct usage of HTML button elements and enforce usage of Button and Pressable.',
|
|
15
|
-
recommended: false,
|
|
16
|
-
severity: 'warn'
|
|
17
|
-
},
|
|
18
|
-
messages: {
|
|
19
|
-
noHtmlButtonElement: `This "{{element}}" should be replaced with a Button component. If beyond the capabilities of the Button component, use the Pressable primitive. See ${buttonDocsUrl} and ${pressableDocsUrl} for guidance.`
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
create(context) {
|
|
23
|
-
return {
|
|
24
|
-
// Look for <button> HTML elements
|
|
25
|
-
// Look for styled calls/templates - styled.button(...)
|
|
26
|
-
JSXOpeningElement(node) {
|
|
27
|
-
if (!isNodeOfType(node, 'JSXOpeningElement')) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!isNodeOfType(node.name, 'JSXIdentifier')) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const suggest = shouldSuggest(node === null || node === void 0 ? void 0 : node.parent);
|
|
34
|
-
if (suggest) {
|
|
35
|
-
context.report({
|
|
36
|
-
node: node,
|
|
37
|
-
messageId: 'noHtmlButtonElement',
|
|
38
|
-
data: {
|
|
39
|
-
element: node.name.name
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
// styled.button`` | styled2.button`` | styled.button()
|
|
45
|
-
'MemberExpression[object.name="styled"],MemberExpression[object.name="styled2"]': node => {
|
|
46
|
-
if (!isNodeOfType(node, 'MemberExpression')) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// styled.button``
|
|
51
|
-
if (isNodeOfType(node.property, 'Identifier')) {
|
|
52
|
-
if (node.property.name === 'button') {
|
|
53
|
-
const styledIdentifier = node.object.name;
|
|
54
|
-
const elementName = node.property.name;
|
|
55
|
-
|
|
56
|
-
// Including the `styled.` portion in the message to help makers understand it's not just the `button` element that should be replaced
|
|
57
|
-
const reportName = `${styledIdentifier}.${elementName}`; // styled.button
|
|
58
|
-
|
|
59
|
-
context.report({
|
|
60
|
-
node: node,
|
|
61
|
-
messageId: 'noHtmlButtonElement',
|
|
62
|
-
data: {
|
|
63
|
-
element: reportName
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
// styled(X)``
|
|
70
|
-
'CallExpression[callee.name="styled"]': node => {
|
|
71
|
-
if (!isNodeOfType(node, 'CallExpression')) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// styled('button')`` - We only care about 'button', ignore extending other components
|
|
76
|
-
if (isNodeOfType(node.arguments[0], 'Literal')) {
|
|
77
|
-
const argValue = node.arguments[0].raw;
|
|
78
|
-
if (typeof argValue === 'string') {
|
|
79
|
-
const suggest = argValue.replaceAll(`'`, '') === 'button';
|
|
80
|
-
if (suggest) {
|
|
81
|
-
const styledIdentifier = node.callee.name;
|
|
82
|
-
const elementName = argValue;
|
|
83
|
-
|
|
84
|
-
// Including the `styled()` portion in the message to help makers understand it's not just the `button` element that should be replaced
|
|
85
|
-
const reportName = `${styledIdentifier}(${elementName})`; // styled('button')
|
|
86
|
-
|
|
87
|
-
context.report({
|
|
88
|
-
node: node,
|
|
89
|
-
messageId: 'noHtmlButtonElement',
|
|
90
|
-
data: {
|
|
91
|
-
element: reportName
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
export default rule;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
|
|
3
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
-
import { createLintRule } from '../utils/create-rule';
|
|
5
|
-
import { shouldSuggest } from './utils';
|
|
6
|
-
var buttonDocsUrl = 'https://atlassian.design/components/button';
|
|
7
|
-
var pressableDocsUrl = 'https://atlassian.design/components/primitives/pressable/';
|
|
8
|
-
var rule = createLintRule({
|
|
9
|
-
meta: {
|
|
10
|
-
name: 'no-html-button-element',
|
|
11
|
-
type: 'suggestion',
|
|
12
|
-
hasSuggestions: false,
|
|
13
|
-
docs: {
|
|
14
|
-
description: 'Prevent direct usage of HTML button elements and enforce usage of Button and Pressable.',
|
|
15
|
-
recommended: false,
|
|
16
|
-
severity: 'warn'
|
|
17
|
-
},
|
|
18
|
-
messages: {
|
|
19
|
-
noHtmlButtonElement: "This \"{{element}}\" should be replaced with a Button component. If beyond the capabilities of the Button component, use the Pressable primitive. See ".concat(buttonDocsUrl, " and ").concat(pressableDocsUrl, " for guidance.")
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
create: function create(context) {
|
|
23
|
-
return {
|
|
24
|
-
// Look for <button> HTML elements
|
|
25
|
-
// Look for styled calls/templates - styled.button(...)
|
|
26
|
-
JSXOpeningElement: function JSXOpeningElement(node) {
|
|
27
|
-
if (!isNodeOfType(node, 'JSXOpeningElement')) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!isNodeOfType(node.name, 'JSXIdentifier')) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
var suggest = shouldSuggest(node === null || node === void 0 ? void 0 : node.parent);
|
|
34
|
-
if (suggest) {
|
|
35
|
-
context.report({
|
|
36
|
-
node: node,
|
|
37
|
-
messageId: 'noHtmlButtonElement',
|
|
38
|
-
data: {
|
|
39
|
-
element: node.name.name
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
// styled.button`` | styled2.button`` | styled.button()
|
|
45
|
-
'MemberExpression[object.name="styled"],MemberExpression[object.name="styled2"]': function MemberExpressionObjectNameStyledMemberExpressionObjectNameStyled2(node) {
|
|
46
|
-
if (!isNodeOfType(node, 'MemberExpression')) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// styled.button``
|
|
51
|
-
if (isNodeOfType(node.property, 'Identifier')) {
|
|
52
|
-
if (node.property.name === 'button') {
|
|
53
|
-
var styledIdentifier = node.object.name;
|
|
54
|
-
var elementName = node.property.name;
|
|
55
|
-
|
|
56
|
-
// Including the `styled.` portion in the message to help makers understand it's not just the `button` element that should be replaced
|
|
57
|
-
var reportName = "".concat(styledIdentifier, ".").concat(elementName); // styled.button
|
|
58
|
-
|
|
59
|
-
context.report({
|
|
60
|
-
node: node,
|
|
61
|
-
messageId: 'noHtmlButtonElement',
|
|
62
|
-
data: {
|
|
63
|
-
element: reportName
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
// styled(X)``
|
|
70
|
-
'CallExpression[callee.name="styled"]': function CallExpressionCalleeNameStyled(node) {
|
|
71
|
-
if (!isNodeOfType(node, 'CallExpression')) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// styled('button')`` - We only care about 'button', ignore extending other components
|
|
76
|
-
if (isNodeOfType(node.arguments[0], 'Literal')) {
|
|
77
|
-
var argValue = node.arguments[0].raw;
|
|
78
|
-
if (typeof argValue === 'string') {
|
|
79
|
-
var suggest = argValue.replaceAll("'", '') === 'button';
|
|
80
|
-
if (suggest) {
|
|
81
|
-
var styledIdentifier = node.callee.name;
|
|
82
|
-
var elementName = argValue;
|
|
83
|
-
|
|
84
|
-
// Including the `styled()` portion in the message to help makers understand it's not just the `button` element that should be replaced
|
|
85
|
-
var reportName = "".concat(styledIdentifier, "(").concat(elementName, ")"); // styled('button')
|
|
86
|
-
|
|
87
|
-
context.report({
|
|
88
|
-
node: node,
|
|
89
|
-
messageId: 'noHtmlButtonElement',
|
|
90
|
-
data: {
|
|
91
|
-
element: reportName
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
export default rule;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
var isButtonHtmlElement = function isButtonHtmlElement(node) {
|
|
2
|
-
return node.openingElement.name.name === 'button';
|
|
3
|
-
};
|
|
4
|
-
export var shouldSuggest = function shouldSuggest(node) {
|
|
5
|
-
if (!node) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
if (!isButtonHtmlElement(node)) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
return true;
|
|
12
|
-
};
|
|
File without changes
|
/package/dist/{types/rules/no-html-button-element → types-ts4.5/rules/no-html-button}/index.d.ts
RENAMED
|
File without changes
|