@atlaskit/eslint-plugin-design-system 9.6.0 → 10.0.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 +1004 -411
- package/README.md +7 -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 +5 -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 +56 -0
- 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 +4 -2
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +7 -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/use-popup-label/index.js +90 -0
- 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 +4 -2
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +7 -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/use-popup-label/index.js +80 -0
- 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 +4 -2
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +7 -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/use-popup-label/index.js +84 -0
- package/dist/types/common/token-maps.partial.d.ts +65 -0
- package/dist/types/index.codegen.d.ts +4 -1
- package/dist/types/presets/all.codegen.d.ts +4 -2
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +3 -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/use-popup-label/index.d.ts +3 -0
- package/dist/types/rules/use-tokens-typography/utils.d.ts +0 -33
- package/dist/types-ts4.5/common/token-maps.partial.d.ts +65 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +4 -2
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +3 -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/use-popup-label/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-tokens-typography/utils.d.ts +0 -33
- package/package.json +4 -3
- 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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.positiveSpaceMap = exports.negativeSpaceMap = exports.allSpaceMap = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
/**
|
|
12
|
+
* THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
13
|
+
* @codegen <<SignedSource::30c84f908843af1f250860b6f3deeea0>>
|
|
14
|
+
* @codegenId spacing
|
|
15
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen-token-maps
|
|
16
|
+
* @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::55622b91aca9b3afac4bce440f222b71>>
|
|
17
|
+
*/
|
|
18
|
+
var positiveSpaceMap = exports.positiveSpaceMap = {
|
|
19
|
+
'0px': 'space.0',
|
|
20
|
+
'2px': 'space.025',
|
|
21
|
+
'4px': 'space.050',
|
|
22
|
+
'6px': 'space.075',
|
|
23
|
+
'8px': 'space.100',
|
|
24
|
+
'12px': 'space.150',
|
|
25
|
+
'16px': 'space.200',
|
|
26
|
+
'20px': 'space.250',
|
|
27
|
+
'24px': 'space.300',
|
|
28
|
+
'32px': 'space.400',
|
|
29
|
+
'40px': 'space.500',
|
|
30
|
+
'48px': 'space.600',
|
|
31
|
+
'64px': 'space.800',
|
|
32
|
+
'80px': 'space.1000'
|
|
33
|
+
};
|
|
34
|
+
var negativeSpaceMap = exports.negativeSpaceMap = {
|
|
35
|
+
'-2px': 'space.negative.025',
|
|
36
|
+
'-4px': 'space.negative.050',
|
|
37
|
+
'-6px': 'space.negative.075',
|
|
38
|
+
'-8px': 'space.negative.100',
|
|
39
|
+
'-12px': 'space.negative.150',
|
|
40
|
+
'-16px': 'space.negative.200',
|
|
41
|
+
'-20px': 'space.negative.250',
|
|
42
|
+
'-24px': 'space.negative.300',
|
|
43
|
+
'-32px': 'space.negative.400'
|
|
44
|
+
};
|
|
45
|
+
var allSpaceMap = exports.allSpaceMap = _objectSpread(_objectSpread({}, positiveSpaceMap), negativeSpaceMap);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @codegenEnd
|
|
49
|
+
*/
|
|
@@ -16,7 +16,7 @@ var _recommended = _interopRequireDefault(require("./presets/recommended.codegen
|
|
|
16
16
|
var _index = _interopRequireDefault(require("./rules/index.codegen"));
|
|
17
17
|
/**
|
|
18
18
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
19
|
-
* @codegen <<SignedSource::
|
|
19
|
+
* @codegen <<SignedSource::a1bb0f17560603fa4895326b1d50744e>>
|
|
20
20
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
21
21
|
*/
|
|
22
22
|
|
|
@@ -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::0be7639a95bf4c9bbfe00154d8193477>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -25,7 +25,8 @@ var _default = exports.default = {
|
|
|
25
25
|
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
26
26
|
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
27
27
|
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
28
|
-
'@atlaskit/design-system/no-html-
|
|
28
|
+
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
29
|
+
'@atlaskit/design-system/no-html-button': 'warn',
|
|
29
30
|
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
30
31
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
|
|
31
32
|
'@atlaskit/design-system/no-margin': 'warn',
|
|
@@ -41,6 +42,7 @@ var _default = exports.default = {
|
|
|
41
42
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
42
43
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
43
44
|
'@atlaskit/design-system/use-href-in-link-item': 'warn',
|
|
45
|
+
'@atlaskit/design-system/use-popup-label': 'warn',
|
|
44
46
|
'@atlaskit/design-system/use-primitives': 'warn',
|
|
45
47
|
'@atlaskit/design-system/use-primitives-text': 'warn',
|
|
46
48
|
'@atlaskit/design-system/use-tokens-space': 'error',
|
|
@@ -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::73a3666b244b58cc221eebcda071161d>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -32,6 +32,7 @@ var _default = exports.default = {
|
|
|
32
32
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
33
33
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
34
34
|
'@atlaskit/design-system/use-href-in-link-item': 'warn',
|
|
35
|
+
'@atlaskit/design-system/use-popup-label': 'warn',
|
|
35
36
|
'@atlaskit/design-system/use-visually-hidden': 'error'
|
|
36
37
|
}
|
|
37
38
|
};
|
|
@@ -18,7 +18,8 @@ var _noDirectUseOfWebPlatformDragAndDrop = _interopRequireDefault(require("./no-
|
|
|
18
18
|
var _noEmptyStyledExpression = _interopRequireDefault(require("./no-empty-styled-expression"));
|
|
19
19
|
var _noExportedCss = _interopRequireDefault(require("./no-exported-css"));
|
|
20
20
|
var _noExportedKeyframes = _interopRequireDefault(require("./no-exported-keyframes"));
|
|
21
|
-
var
|
|
21
|
+
var _noHtmlAnchor = _interopRequireDefault(require("./no-html-anchor"));
|
|
22
|
+
var _noHtmlButton = _interopRequireDefault(require("./no-html-button"));
|
|
22
23
|
var _noInvalidCssMap = _interopRequireDefault(require("./no-invalid-css-map"));
|
|
23
24
|
var _noKeyframesTaggedTemplateExpression = _interopRequireDefault(require("./no-keyframes-tagged-template-expression"));
|
|
24
25
|
var _noMargin = _interopRequireDefault(require("./no-margin"));
|
|
@@ -34,6 +35,7 @@ var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
|
|
|
34
35
|
var _useHeading = _interopRequireDefault(require("./use-heading"));
|
|
35
36
|
var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-heading-level-in-spotlight-card"));
|
|
36
37
|
var _useHrefInLinkItem = _interopRequireDefault(require("./use-href-in-link-item"));
|
|
38
|
+
var _usePopupLabel = _interopRequireDefault(require("./use-popup-label"));
|
|
37
39
|
var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
|
|
38
40
|
var _usePrimitivesText = _interopRequireDefault(require("./use-primitives-text"));
|
|
39
41
|
var _useTokensSpace = _interopRequireDefault(require("./use-tokens-space"));
|
|
@@ -41,7 +43,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
|
|
|
41
43
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
42
44
|
/**
|
|
43
45
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
44
|
-
* @codegen <<SignedSource::
|
|
46
|
+
* @codegen <<SignedSource::9b934590b0ff7880e962fa4dd73bdb0b>>
|
|
45
47
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
46
48
|
*/
|
|
47
49
|
var _default = exports.default = {
|
|
@@ -58,7 +60,8 @@ var _default = exports.default = {
|
|
|
58
60
|
'no-empty-styled-expression': _noEmptyStyledExpression.default,
|
|
59
61
|
'no-exported-css': _noExportedCss.default,
|
|
60
62
|
'no-exported-keyframes': _noExportedKeyframes.default,
|
|
61
|
-
'no-html-
|
|
63
|
+
'no-html-anchor': _noHtmlAnchor.default,
|
|
64
|
+
'no-html-button': _noHtmlButton.default,
|
|
62
65
|
'no-invalid-css-map': _noInvalidCssMap.default,
|
|
63
66
|
'no-keyframes-tagged-template-expression': _noKeyframesTaggedTemplateExpression.default,
|
|
64
67
|
'no-margin': _noMargin.default,
|
|
@@ -74,6 +77,7 @@ var _default = exports.default = {
|
|
|
74
77
|
'use-heading': _useHeading.default,
|
|
75
78
|
'use-heading-level-in-spotlight-card': _useHeadingLevelInSpotlightCard.default,
|
|
76
79
|
'use-href-in-link-item': _useHrefInLinkItem.default,
|
|
80
|
+
'use-popup-label': _usePopupLabel.default,
|
|
77
81
|
'use-primitives': _usePrimitives.default,
|
|
78
82
|
'use-primitives-text': _usePrimitivesText.default,
|
|
79
83
|
'use-tokens-space': _useTokensSpace.default,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _nodeTypes = require("./node-types");
|
|
9
|
+
var rule = (0, _createRule.createLintRule)({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'no-html-anchor',
|
|
12
|
+
type: 'suggestion',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Discourage direct usage of HTML anchor elements in favor of Atlassian Design System link components.',
|
|
15
|
+
recommended: false,
|
|
16
|
+
severity: 'warn'
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noHtmlAnchor: "This <{{ name }}> should be replaced with a link component from the Atlassian Design System, such as the \"Link\" or \"LinkButton\" component when suitable. For custom links use the \"Anchor\" primitive. ADS links include event tracking, automatic router configuration, ensure accessible implementations, and provide access to ADS styling features like design tokens."
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
create: function create(context) {
|
|
23
|
+
return {
|
|
24
|
+
// transforms styled.<anchor>(...) usages
|
|
25
|
+
CallExpression: function CallExpression(node) {
|
|
26
|
+
_nodeTypes.StyledComponent.lint(node, {
|
|
27
|
+
context: context
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
// transforms <anchor css={...}> usages
|
|
31
|
+
JSXElement: function JSXElement(node) {
|
|
32
|
+
_nodeTypes.JSXElement.lint(node, {
|
|
33
|
+
context: context
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "JSXElement", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _jsxElement.JSXElement;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "StyledComponent", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _styledComponent.StyledComponent;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _styledComponent = require("./styled-component");
|
|
19
|
+
var _jsxElement = require("./jsx-element");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.JSXElement = void 0;
|
|
8
|
+
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
9
|
+
var _supported = require("../supported");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
13
|
+
|
|
14
|
+
var JSXElement = exports.JSXElement = {
|
|
15
|
+
lint: function lint(node, _ref) {
|
|
16
|
+
var context = _ref.context;
|
|
17
|
+
if (!(0, _supported.isSupportedForLint)(node)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
context.report({
|
|
21
|
+
node: node.openingElement,
|
|
22
|
+
messageId: 'noHtmlAnchor',
|
|
23
|
+
data: {
|
|
24
|
+
name: ast.JSXElement.getName(node)
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
package/dist/cjs/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getStyledComponentCall = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
/**
|
|
9
|
+
* Returns a styled component
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var getStyledComponentCall = exports.getStyledComponentCall = function getStyledComponentCall(node) {
|
|
13
|
+
// halts unless we are dealing with a styled component
|
|
14
|
+
if (!isStyledCallExpression(node)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// halts if the component is being exported directly
|
|
18
|
+
if ((0, _eslintCodemodUtils.closestOfType)(node, 'ExportNamedDeclaration')) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var styledComponentVariableRef = node.parent;
|
|
22
|
+
// halts if the styled component is not assigned to a variable immediately
|
|
23
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef, 'VariableDeclarator')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return styledComponentVariableRef;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Some verbose precondition checks but all it does is check
|
|
31
|
+
* a call expression is of form `styled.a` or `styled2.a`
|
|
32
|
+
*/
|
|
33
|
+
var isStyledCallExpression = function isStyledCallExpression(call) {
|
|
34
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(call, 'CallExpression')) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee, 'MemberExpression')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(call.callee.property, 'Identifier')) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (/^styled2?$/.test(call.callee.object.name)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledComponent = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var _getJsxElementByName2 = require("../../utils/get-jsx-element-by-name");
|
|
9
|
+
var _supported = require("../supported");
|
|
10
|
+
var _getStyledComponentCall = require("./get-styled-component-call");
|
|
11
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
12
|
+
|
|
13
|
+
var StyledComponent = exports.StyledComponent = {
|
|
14
|
+
lint: function lint(node, _ref) {
|
|
15
|
+
var _getJsxElementByName;
|
|
16
|
+
var context = _ref.context;
|
|
17
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'MemberExpression') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee.property, 'Identifier')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var styles = (0, _getStyledComponentCall.getStyledComponentCall)(node);
|
|
21
|
+
var elementName = node.callee.property.name;
|
|
22
|
+
if (!styles || !(0, _eslintCodemodUtils.isNodeOfType)(styles.id, 'Identifier')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var jsxElement = (_getJsxElementByName = (0, _getJsxElementByName2.getJsxElementByName)(styles.id.name, context.getScope())) === null || _getJsxElementByName === void 0 ? void 0 : _getJsxElementByName.parent;
|
|
26
|
+
if (jsxElement && !(0, _supported.isSupportedForLint)(jsxElement, elementName)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
context.report({
|
|
30
|
+
node: styles,
|
|
31
|
+
messageId: 'noHtmlAnchor',
|
|
32
|
+
data: {
|
|
33
|
+
name: node.callee.property.name
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.isSupportedForLint = isSupportedForLint;
|
|
8
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
9
|
+
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
var supportedElements = [{
|
|
13
|
+
name: 'a'
|
|
14
|
+
}];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the given JSX element is a supported element to lint with this rule.
|
|
18
|
+
*/
|
|
19
|
+
function isSupportedForLint(jsxNode, elementName) {
|
|
20
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(jsxNode, 'JSXElement')) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Allow passing in the element name because the jsxNode doesn't
|
|
25
|
+
// represent the element name with styled components
|
|
26
|
+
var elName = elementName || ast.JSXElement.getName(jsxNode);
|
|
27
|
+
if (!elName) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Only check native HTML elements, not components
|
|
32
|
+
if (elName[0] !== elName[0].toLowerCase()) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var supportedElement = supportedElements.find(function (_ref) {
|
|
36
|
+
var name = _ref.name;
|
|
37
|
+
return name === elName;
|
|
38
|
+
});
|
|
39
|
+
if (!supportedElement) {
|
|
40
|
+
supportedElement = supportedElements.find(function (_ref2) {
|
|
41
|
+
var name = _ref2.name;
|
|
42
|
+
return name === '*';
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!supportedElement) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Check if the element has any attributes that are not supported
|
|
50
|
+
var attributes = ast.JSXElement.getAttributes(jsxNode);
|
|
51
|
+
if (supportedElement.attributes && !supportedElement.attributes.every(function (_ref3) {
|
|
52
|
+
var name = _ref3.name,
|
|
53
|
+
values = _ref3.values;
|
|
54
|
+
return attributes.some(function (attribute) {
|
|
55
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
var isMatchingName = attribute.name.name === name;
|
|
59
|
+
var isMatchingValues = values && attribute.value && attribute.value.type === 'Literal' && typeof attribute.value.value === 'string' && (values === null || values === void 0 ? void 0 : values.includes(attribute.value.value));
|
|
60
|
+
return isMatchingName && isMatchingValues;
|
|
61
|
+
});
|
|
62
|
+
})) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getJsxElementByName = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
|
+
/**
|
|
11
|
+
* Given a component name finds its JSX usage
|
|
12
|
+
*/
|
|
13
|
+
var getJsxElementByName = exports.getJsxElementByName = function getJsxElementByName(componentName, scope) {
|
|
14
|
+
var _variableDeclaration$;
|
|
15
|
+
var variableDeclaration = scope.variables.find(function (v) {
|
|
16
|
+
return v.name === componentName;
|
|
17
|
+
});
|
|
18
|
+
if (!variableDeclaration) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// length here should be exactly 2 to indicate only two references:
|
|
23
|
+
// one being the variable declaration itself
|
|
24
|
+
// second being the JSX call site
|
|
25
|
+
// we might consider handling multiple local JSX call sites in the future
|
|
26
|
+
// but "this is good enough for now"™️
|
|
27
|
+
if (variableDeclaration.references.length !== 2) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var jsxUsage = (_variableDeclaration$ = variableDeclaration.references[1]) === null || _variableDeclaration$ === void 0 ? void 0 : _variableDeclaration$.identifier;
|
|
31
|
+
var _variableDeclaration$2 = variableDeclaration.references.map(function (ref) {
|
|
32
|
+
return ref === null || ref === void 0 ? void 0 : ref.identifier;
|
|
33
|
+
}),
|
|
34
|
+
_variableDeclaration$3 = (0, _slicedToArray2.default)(_variableDeclaration$2, 2),
|
|
35
|
+
firstIdentifier = _variableDeclaration$3[0],
|
|
36
|
+
secondIdentifier = _variableDeclaration$3[1];
|
|
37
|
+
// Check if the first reference is a JSXOpeningElement and the second is not or vice versa
|
|
38
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(firstIdentifier, 'JSXIdentifier') && !(0, _eslintCodemodUtils.isNodeOfType)(secondIdentifier, 'JSXIdentifier')) {
|
|
39
|
+
jsxUsage = firstIdentifier;
|
|
40
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(secondIdentifier, 'JSXIdentifier') && !(0, _eslintCodemodUtils.isNodeOfType)(firstIdentifier, 'JSXIdentifier')) {
|
|
41
|
+
jsxUsage = secondIdentifier;
|
|
42
|
+
} else {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(jsxUsage, 'JSXIdentifier')) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var jsxOpeningElement = jsxUsage.parent;
|
|
49
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(jsxOpeningElement, 'JSXOpeningElement')) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return jsxOpeningElement;
|
|
53
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _nodeTypes = require("./node-types");
|
|
9
|
+
var rule = (0, _createRule.createLintRule)({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'no-html-button',
|
|
12
|
+
type: 'suggestion',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Discourage direct usage of HTML button elements in favor of Atlassian Design System button components.',
|
|
15
|
+
recommended: false,
|
|
16
|
+
severity: 'warn'
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noHtmlButton: "This {{ name }} should be replaced with a button component from the Atlassian Design System, such as the \"Button\" component when suitable. For custom buttons use the \"Pressable\" primitive. ADS buttons include event tracking, ensure accessible implementations, and provide access to ADS styling features like design tokens."
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
create: function create(context) {
|
|
23
|
+
return {
|
|
24
|
+
// transforms styled.<button>(...) usages
|
|
25
|
+
CallExpression: function CallExpression(node) {
|
|
26
|
+
_nodeTypes.StyledComponent.lint(node, {
|
|
27
|
+
context: context
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
// transforms <button css={...}> usages
|
|
31
|
+
JSXElement: function JSXElement(node) {
|
|
32
|
+
_nodeTypes.JSXElement.lint(node, {
|
|
33
|
+
context: context
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "JSXElement", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _jsxElement.JSXElement;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "StyledComponent", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _styledComponent.StyledComponent;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _styledComponent = require("./styled-component");
|
|
19
|
+
var _jsxElement = require("./jsx-element");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.JSXElement = void 0;
|
|
8
|
+
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
9
|
+
var _supported = require("../supported");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
13
|
+
|
|
14
|
+
var JSXElement = exports.JSXElement = {
|
|
15
|
+
lint: function lint(node, _ref) {
|
|
16
|
+
var context = _ref.context;
|
|
17
|
+
if (!(0, _supported.isSupportedForLint)(node)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
context.report({
|
|
21
|
+
node: node.openingElement,
|
|
22
|
+
messageId: 'noHtmlButton',
|
|
23
|
+
data: {
|
|
24
|
+
name: ast.JSXElement.getName(node)
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
package/dist/cjs/rules/no-html-button/node-types/styled-component/get-styled-component-call.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getStyledComponentCall = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
/**
|
|
9
|
+
* Returns a styled component
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var getStyledComponentCall = exports.getStyledComponentCall = function getStyledComponentCall(node) {
|
|
13
|
+
// halts unless we are dealing with a styled component
|
|
14
|
+
if (!isStyledCallExpression(node)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// halts if the component is being exported directly
|
|
18
|
+
if ((0, _eslintCodemodUtils.closestOfType)(node, 'ExportNamedDeclaration')) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var styledComponentVariableRef = node.parent;
|
|
22
|
+
// halts if the styled component is not assigned to a variable immediately
|
|
23
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef, 'VariableDeclarator')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return styledComponentVariableRef;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Some verbose precondition checks but all it does is check
|
|
31
|
+
* a call expression is of form `styled.button` or `styled2.button`
|
|
32
|
+
*/
|
|
33
|
+
var isStyledCallExpression = function isStyledCallExpression(call) {
|
|
34
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(call, 'CallExpression')) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee, 'MemberExpression')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(call.callee.property, 'Identifier')) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (/^styled2?$/.test(call.callee.object.name)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledComponent = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var _getJsxElementByName2 = require("../../utils/get-jsx-element-by-name");
|
|
9
|
+
var _supported = require("../supported");
|
|
10
|
+
var _getStyledComponentCall = require("./get-styled-component-call");
|
|
11
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
12
|
+
|
|
13
|
+
var StyledComponent = exports.StyledComponent = {
|
|
14
|
+
lint: function lint(node, _ref) {
|
|
15
|
+
var _getJsxElementByName;
|
|
16
|
+
var context = _ref.context;
|
|
17
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'MemberExpression') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee.property, 'Identifier')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var styles = (0, _getStyledComponentCall.getStyledComponentCall)(node);
|
|
21
|
+
var elementName = node.callee.property.name;
|
|
22
|
+
if (!styles || !(0, _eslintCodemodUtils.isNodeOfType)(styles.id, 'Identifier')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var jsxElement = (_getJsxElementByName = (0, _getJsxElementByName2.getJsxElementByName)(styles.id.name, context.getScope())) === null || _getJsxElementByName === void 0 ? void 0 : _getJsxElementByName.parent;
|
|
26
|
+
if (jsxElement && !(0, _supported.isSupportedForLint)(jsxElement, elementName)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
context.report({
|
|
30
|
+
node: styles,
|
|
31
|
+
messageId: 'noHtmlButton',
|
|
32
|
+
data: {
|
|
33
|
+
name: node.callee.property.name
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|