@atlaskit/eslint-plugin-design-system 13.17.2 → 13.18.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 +18 -0
- package/README.md +2 -0
- package/dist/cjs/presets/all-flat.codegen.js +3 -1
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/enforce-inline-styles-in-select/index.js +76 -0
- package/dist/cjs/rules/enforce-inline-styles-in-select/utils.js +231 -0
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-nested-styles/index.js +27 -20
- package/dist/cjs/rules/no-utility-icons/checks.js +0 -1
- package/dist/cjs/rules/use-correct-field/index.js +167 -0
- package/dist/es2019/presets/all-flat.codegen.js +3 -1
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/enforce-inline-styles-in-select/index.js +68 -0
- package/dist/es2019/rules/enforce-inline-styles-in-select/utils.js +217 -0
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-nested-styles/index.js +27 -18
- package/dist/es2019/rules/no-utility-icons/checks.js +0 -1
- package/dist/es2019/rules/use-correct-field/index.js +153 -0
- package/dist/esm/presets/all-flat.codegen.js +3 -1
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended-flat.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/enforce-inline-styles-in-select/index.js +70 -0
- package/dist/esm/rules/enforce-inline-styles-in-select/utils.js +225 -0
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-nested-styles/index.js +27 -20
- package/dist/esm/rules/no-utility-icons/checks.js +0 -1
- package/dist/esm/rules/use-correct-field/index.js +161 -0
- package/dist/types/index.codegen.d.ts +14 -0
- package/dist/types/presets/all-flat.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -0
- package/dist/types/presets/recommended-flat.codegen.d.ts +1 -0
- package/dist/types/presets/recommended.codegen.d.ts +1 -0
- package/dist/types/rules/enforce-inline-styles-in-select/index.d.ts +3 -0
- package/dist/types/rules/enforce-inline-styles-in-select/utils.d.ts +2 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/use-correct-field/index.d.ts +5 -0
- package/dist/types-ts4.5/index.codegen.d.ts +14 -0
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -0
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/enforce-inline-styles-in-select/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/enforce-inline-styles-in-select/utils.d.ts +2 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-correct-field/index.d.ts +5 -0
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 13.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#187514](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/187514)
|
|
8
|
+
[`c159d1d45ed81`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c159d1d45ed81) -
|
|
9
|
+
Add new rule to check that inputs use the correct field component from form.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 13.17.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 13.17.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ module.exports = {
|
|
|
50
50
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
51
51
|
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------- | ----------- |
|
|
52
52
|
| <a href="./packages/design-system/eslint-plugin/src/rules/consistent-css-prop-usage/README.md">consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
53
|
+
| <a href="./packages/design-system/eslint-plugin/src/rules/enforce-inline-styles-in-select/README.md">enforce-inline-styles-in-select</a> | Disallow unsupported CSS selectors in styles prop for @atlaskit/select and require inline styles only | | | |
|
|
53
54
|
| <a href="./packages/design-system/eslint-plugin/src/rules/ensure-design-token-usage/README.md">ensure-design-token-usage</a> | Enforces usage of design tokens rather than hard-coded values. | Yes | Yes | Yes |
|
|
54
55
|
| <a href="./packages/design-system/eslint-plugin/src/rules/ensure-design-token-usage-preview/README.md">ensure-design-token-usage/preview</a> | Enforces usage of pre-release design tokens rather than hard-coded values. | | Yes | Yes |
|
|
55
56
|
| <a href="./packages/design-system/eslint-plugin/src/rules/ensure-icon-color/README.md">ensure-icon-color</a> | Enforces that upcoming icon components have a color prop set, to enable a migration of the default value. | | | |
|
|
@@ -93,6 +94,7 @@ module.exports = {
|
|
|
93
94
|
| <a href="./packages/design-system/eslint-plugin/src/rules/no-utility-icons/README.md">no-utility-icons</a> | Disallow use of deprecated utility icons, in favor of core icons with `size="small"`. | Yes | Yes | Yes |
|
|
94
95
|
| <a href="./packages/design-system/eslint-plugin/src/rules/prefer-primitives/README.md">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
|
|
95
96
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-button-group-label/README.md">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
|
|
97
|
+
| <a href="./packages/design-system/eslint-plugin/src/rules/use-correct-field/README.md">use-correct-field</a> | Ensure makers use appropriate field component for their respective form elements. | Yes | Yes | Yes |
|
|
96
98
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-cx-function-in-xcss/README.md">use-cx-function-in-xcss</a> | Enforces cx function use to combine styles in xcss. | Yes | Yes | Yes |
|
|
97
99
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-datetime-picker-calendar-button/README.md">use-datetime-picker-calendar-button</a> | Encourages makers to use calendar button in Atlassian Design System's date picker and datetime picker components. | Yes | Yes | Yes |
|
|
98
100
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-drawer-label/README.md">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | 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::8fb6e53ac7d9be7b9252dd64ec022d26>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -14,6 +14,7 @@ var _default = exports.default = {
|
|
|
14
14
|
plugins: {},
|
|
15
15
|
rules: {
|
|
16
16
|
'@atlaskit/design-system/consistent-css-prop-usage': 'error',
|
|
17
|
+
'@atlaskit/design-system/enforce-inline-styles-in-select': 'error',
|
|
17
18
|
'@atlaskit/design-system/ensure-design-token-usage': 'error',
|
|
18
19
|
'@atlaskit/design-system/ensure-design-token-usage/preview': 'warn',
|
|
19
20
|
'@atlaskit/design-system/ensure-icon-color': 'error',
|
|
@@ -56,6 +57,7 @@ var _default = exports.default = {
|
|
|
56
57
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
57
58
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
58
59
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
60
|
+
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
59
61
|
'@atlaskit/design-system/use-cx-function-in-xcss': 'error',
|
|
60
62
|
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
61
63
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
@@ -6,13 +6,14 @@ 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::b727e6e2b1813b88da0df6ff6083be3c>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
13
13
|
plugins: ['@atlaskit/design-system'],
|
|
14
14
|
rules: {
|
|
15
15
|
'@atlaskit/design-system/consistent-css-prop-usage': 'error',
|
|
16
|
+
'@atlaskit/design-system/enforce-inline-styles-in-select': 'error',
|
|
16
17
|
'@atlaskit/design-system/ensure-design-token-usage': 'error',
|
|
17
18
|
'@atlaskit/design-system/ensure-design-token-usage/preview': 'warn',
|
|
18
19
|
'@atlaskit/design-system/ensure-icon-color': 'error',
|
|
@@ -55,6 +56,7 @@ var _default = exports.default = {
|
|
|
55
56
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
56
57
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
57
58
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
59
|
+
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
58
60
|
'@atlaskit/design-system/use-cx-function-in-xcss': 'error',
|
|
59
61
|
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
60
62
|
'@atlaskit/design-system/use-drawer-label': '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::af48ffd75d906d008c5701554187b606>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -43,6 +43,7 @@ var _default = exports.default = {
|
|
|
43
43
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
44
44
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
45
45
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
46
|
+
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
46
47
|
'@atlaskit/design-system/use-cx-function-in-xcss': 'error',
|
|
47
48
|
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
48
49
|
'@atlaskit/design-system/use-drawer-label': '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::96e803ae8ae873736bab690b2af62bed>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -42,6 +42,7 @@ var _default = exports.default = {
|
|
|
42
42
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
43
43
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
44
44
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
45
|
+
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
45
46
|
'@atlaskit/design-system/use-cx-function-in-xcss': 'error',
|
|
46
47
|
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
47
48
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
var rule = (0, _createRule.createLintRule)({
|
|
11
|
+
meta: {
|
|
12
|
+
name: 'enforce-inline-styles-in-select',
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Disallow unsupported CSS selectors in styles prop for @atlaskit/select and require inline styles only',
|
|
15
|
+
recommended: false,
|
|
16
|
+
severity: 'error'
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
noPseudoClass: "This selector '{{pseudo}}' is not allowed in styles for @atlaskit/select. Please use the `components` API in select with `xcss` props.",
|
|
20
|
+
noVariableStyles: 'Variable-defined styles are not allowed for @atlaskit/select. Please use inline styles object or the `components` API with `xcss` props.'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
create: function create(context) {
|
|
24
|
+
// Track imports of @atlaskit/select
|
|
25
|
+
var atlaskitSelectImports = new Set();
|
|
26
|
+
return {
|
|
27
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
|
28
|
+
if (node.source.value !== '@atlaskit/select') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
node.specifiers.forEach(function (spec) {
|
|
32
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(spec, 'ImportDefaultSpecifier')) {
|
|
33
|
+
atlaskitSelectImports.add(spec.local.name);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
JSXElement: function JSXElement(node) {
|
|
38
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Check if this is a Select component from @atlaskit/select
|
|
43
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier') && atlaskitSelectImports.has(node.openingElement.name.name)) {
|
|
44
|
+
// Look for styles prop
|
|
45
|
+
var stylesAttr = node.openingElement.attributes.find(function (attr) {
|
|
46
|
+
return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier') && attr.name.name === 'styles';
|
|
47
|
+
});
|
|
48
|
+
if (stylesAttr && (0, _eslintCodemodUtils.isNodeOfType)(stylesAttr, 'JSXAttribute') && stylesAttr.value) {
|
|
49
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(stylesAttr.value, 'JSXExpressionContainer')) {
|
|
50
|
+
var expression = stylesAttr.value.expression;
|
|
51
|
+
|
|
52
|
+
// Check if it's an inline object expression
|
|
53
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(expression, 'ObjectExpression')) {
|
|
54
|
+
// This is an inline styles object - check for unsupported selectors
|
|
55
|
+
(0, _utils.checkStylesObject)(node, expression, context);
|
|
56
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(expression, 'Identifier')) {
|
|
57
|
+
// This is a variable reference - not allowed
|
|
58
|
+
context.report({
|
|
59
|
+
node: expression,
|
|
60
|
+
messageId: 'noVariableStyles'
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
// Any other expression type (function calls, member expressions, etc.) - not allowed
|
|
64
|
+
context.report({
|
|
65
|
+
node: expression,
|
|
66
|
+
messageId: 'noVariableStyles'
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkStylesObject = checkStylesObject;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var unsupportedSelectors = [':',
|
|
9
|
+
// pseudo-classes/elements
|
|
10
|
+
'[',
|
|
11
|
+
// attribute selectors
|
|
12
|
+
'>',
|
|
13
|
+
// child combinator
|
|
14
|
+
'+',
|
|
15
|
+
// adjacent sibling combinator
|
|
16
|
+
'~',
|
|
17
|
+
// general sibling combinator
|
|
18
|
+
' ',
|
|
19
|
+
// descendant combinator
|
|
20
|
+
'*',
|
|
21
|
+
// universal selector
|
|
22
|
+
'#',
|
|
23
|
+
// ID selector
|
|
24
|
+
'.',
|
|
25
|
+
// class selector
|
|
26
|
+
'@',
|
|
27
|
+
// at-rules
|
|
28
|
+
'&',
|
|
29
|
+
// parent selector
|
|
30
|
+
'|',
|
|
31
|
+
// namespace separator
|
|
32
|
+
'^',
|
|
33
|
+
// starts with
|
|
34
|
+
'$',
|
|
35
|
+
// ends with
|
|
36
|
+
'=' // equals
|
|
37
|
+
];
|
|
38
|
+
function checkForPseudoClasses(node, objectExpression, context) {
|
|
39
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(objectExpression, 'ObjectExpression')) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
objectExpression.properties.forEach(function (prop) {
|
|
43
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(prop, 'Property')) {
|
|
44
|
+
// Check if property key is a pseudo-class
|
|
45
|
+
var keyValue = null;
|
|
46
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(prop.key, 'Literal')) {
|
|
47
|
+
keyValue = prop.key.value;
|
|
48
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(prop.key, 'Identifier')) {
|
|
49
|
+
keyValue = prop.key.name;
|
|
50
|
+
}
|
|
51
|
+
if (keyValue && typeof keyValue === 'string' && unsupportedSelectors.some(function (selector) {
|
|
52
|
+
return keyValue.includes(selector);
|
|
53
|
+
})) {
|
|
54
|
+
context.report({
|
|
55
|
+
node: prop.key,
|
|
56
|
+
messageId: 'noPseudoClass',
|
|
57
|
+
data: {
|
|
58
|
+
pseudo: keyValue
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Recursively check nested objects (for function return values)
|
|
64
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'ArrowFunctionExpression') || (0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'FunctionExpression')) {
|
|
65
|
+
// Check the function body for returned object expressions
|
|
66
|
+
var body = prop.value.body;
|
|
67
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(body, 'ObjectExpression')) {
|
|
68
|
+
checkForPseudoClasses(node, body, context);
|
|
69
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(body, 'BlockStatement')) {
|
|
70
|
+
// Look for return statements
|
|
71
|
+
body.body.forEach(function (stmt) {
|
|
72
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(stmt, 'ReturnStatement') && stmt.argument && (0, _eslintCodemodUtils.isNodeOfType)(stmt.argument, 'ObjectExpression')) {
|
|
73
|
+
checkForPseudoClasses(node, stmt.argument, context);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'ObjectExpression')) {
|
|
78
|
+
checkForPseudoClasses(node, prop.value, context);
|
|
79
|
+
}
|
|
80
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(prop, 'SpreadElement')) {
|
|
81
|
+
// Handle spread elements like ...styles or ...conditionalStyles
|
|
82
|
+
checkSpreadElement(node, prop, context);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function checkSpreadElement(node, spreadElement, context) {
|
|
87
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(spreadElement, 'SpreadElement')) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
var argument = spreadElement.argument;
|
|
91
|
+
|
|
92
|
+
// Handle direct identifier (e.g., ...styles)
|
|
93
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'Identifier')) {
|
|
94
|
+
var scope = context.getScope();
|
|
95
|
+
var variable = null;
|
|
96
|
+
var currentScope = scope;
|
|
97
|
+
|
|
98
|
+
// Search through scope chain
|
|
99
|
+
while (currentScope && !variable) {
|
|
100
|
+
variable = currentScope.variables.find(function (v) {
|
|
101
|
+
return v.name === argument.name;
|
|
102
|
+
});
|
|
103
|
+
currentScope = currentScope.upper;
|
|
104
|
+
}
|
|
105
|
+
if (variable && variable.defs.length > 0) {
|
|
106
|
+
var def = variable.defs[0];
|
|
107
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(def.node, 'VariableDeclarator') && def.node.init) {
|
|
108
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(def.node.init, 'ObjectExpression')) {
|
|
109
|
+
checkForPseudoClasses(node, def.node.init, context);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Handle conditional expressions (e.g., ...(condition ? { ':hover': ... } : undefined))
|
|
115
|
+
else if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'ConditionalExpression')) {
|
|
116
|
+
// Check both consequent and alternate
|
|
117
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argument.consequent, 'ObjectExpression')) {
|
|
118
|
+
checkForPseudoClasses(node, argument.consequent, context);
|
|
119
|
+
}
|
|
120
|
+
if (argument.alternate && (0, _eslintCodemodUtils.isNodeOfType)(argument.alternate, 'ObjectExpression')) {
|
|
121
|
+
checkForPseudoClasses(node, argument.alternate, context);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Handle logical expressions (e.g., ...condition && { ':hover': ... })
|
|
125
|
+
else if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'LogicalExpression')) {
|
|
126
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argument.right, 'ObjectExpression')) {
|
|
127
|
+
checkForPseudoClasses(node, argument.right, context);
|
|
128
|
+
}
|
|
129
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argument.left, 'ObjectExpression')) {
|
|
130
|
+
checkForPseudoClasses(node, argument.left, context);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Handle direct object expressions (e.g., ...{ ':hover': ... })
|
|
134
|
+
else if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'ObjectExpression')) {
|
|
135
|
+
checkForPseudoClasses(node, argument, context);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function checkStylesObject(node, stylesValue, context) {
|
|
139
|
+
if (!stylesValue) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(stylesValue, 'ObjectExpression')) {
|
|
143
|
+
stylesValue.properties.forEach(function (prop) {
|
|
144
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(prop, 'Property') || !prop.value || !(0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'ArrowFunctionExpression') && !(0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'FunctionExpression')) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
var body = prop.value.body;
|
|
148
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(body, 'ObjectExpression')) {
|
|
149
|
+
checkForPseudoClasses(node, body, context);
|
|
150
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(body, 'BlockStatement')) {
|
|
151
|
+
var visitor = {
|
|
152
|
+
ReturnStatement: function ReturnStatement(returnStmt) {
|
|
153
|
+
if (returnStmt.argument && (0, _eslintCodemodUtils.isNodeOfType)(returnStmt.argument, 'ObjectExpression')) {
|
|
154
|
+
checkForPseudoClasses(node, returnStmt.argument, context);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
AssignmentExpression: function AssignmentExpression(assignExpr) {
|
|
158
|
+
// Handle cases like styles[':hover'] = { ... }
|
|
159
|
+
var left = assignExpr.left;
|
|
160
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(left, 'MemberExpression')) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var property = left.property;
|
|
164
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(property, 'Literal')) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
var value = property.value;
|
|
168
|
+
if (typeof value !== 'string') {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (unsupportedSelectors.some(function (selector) {
|
|
172
|
+
return value.includes(selector);
|
|
173
|
+
})) {
|
|
174
|
+
context.report({
|
|
175
|
+
node: property,
|
|
176
|
+
messageId: 'noPseudoClass',
|
|
177
|
+
data: {
|
|
178
|
+
pseudo: value
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
body.body.forEach(function (stmt) {
|
|
185
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(stmt, 'ReturnStatement')) {
|
|
186
|
+
visitor.ReturnStatement(stmt);
|
|
187
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(stmt, 'ExpressionStatement') && (0, _eslintCodemodUtils.isNodeOfType)(stmt.expression, 'AssignmentExpression')) {
|
|
188
|
+
visitor.AssignmentExpression(stmt.expression);
|
|
189
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(stmt, 'IfStatement')) {
|
|
190
|
+
var checkBlock = function checkBlock(block) {
|
|
191
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(block, 'BlockStatement')) {
|
|
192
|
+
block.body.forEach(function (innerStmt) {
|
|
193
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(innerStmt, 'ExpressionStatement') && (0, _eslintCodemodUtils.isNodeOfType)(innerStmt.expression, 'AssignmentExpression')) {
|
|
194
|
+
visitor.AssignmentExpression(innerStmt.expression);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(block, 'ExpressionStatement') && (0, _eslintCodemodUtils.isNodeOfType)(block.expression, 'AssignmentExpression')) {
|
|
198
|
+
visitor.AssignmentExpression(block.expression);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
if (stmt.consequent) {
|
|
202
|
+
checkBlock(stmt.consequent);
|
|
203
|
+
}
|
|
204
|
+
if (stmt.alternate) {
|
|
205
|
+
checkBlock(stmt.alternate);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(stylesValue, 'Identifier')) {
|
|
212
|
+
// track the variable
|
|
213
|
+
var scope = context.getScope();
|
|
214
|
+
var variable = null;
|
|
215
|
+
var currentScope = scope;
|
|
216
|
+
|
|
217
|
+
// Search through scope chain
|
|
218
|
+
while (currentScope && !variable) {
|
|
219
|
+
variable = currentScope.variables.find(function (v) {
|
|
220
|
+
return v.name === stylesValue.name;
|
|
221
|
+
});
|
|
222
|
+
currentScope = currentScope.upper;
|
|
223
|
+
}
|
|
224
|
+
if (variable && variable.defs.length > 0) {
|
|
225
|
+
var def = variable.defs[0];
|
|
226
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(def.node, 'VariableDeclarator') && def.node.init) {
|
|
227
|
+
checkStylesObject(node, def.node.init, context);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.rules = void 0;
|
|
8
8
|
var _consistentCssPropUsage = _interopRequireDefault(require("./consistent-css-prop-usage"));
|
|
9
|
+
var _enforceInlineStylesInSelect = _interopRequireDefault(require("./enforce-inline-styles-in-select"));
|
|
9
10
|
var _ensureDesignTokenUsage = _interopRequireDefault(require("./ensure-design-token-usage"));
|
|
10
11
|
var _ensureDesignTokenUsagePreview = _interopRequireDefault(require("./ensure-design-token-usage-preview"));
|
|
11
12
|
var _ensureIconColor = _interopRequireDefault(require("./ensure-icon-color"));
|
|
@@ -49,6 +50,7 @@ var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-un
|
|
|
49
50
|
var _noUtilityIcons = _interopRequireDefault(require("./no-utility-icons"));
|
|
50
51
|
var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
|
|
51
52
|
var _useButtonGroupLabel = _interopRequireDefault(require("./use-button-group-label"));
|
|
53
|
+
var _useCorrectField = _interopRequireDefault(require("./use-correct-field"));
|
|
52
54
|
var _useCxFunctionInXcss = _interopRequireDefault(require("./use-cx-function-in-xcss"));
|
|
53
55
|
var _useDatetimePickerCalendarButton = _interopRequireDefault(require("./use-datetime-picker-calendar-button"));
|
|
54
56
|
var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
|
|
@@ -70,12 +72,13 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
|
|
|
70
72
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
71
73
|
/**
|
|
72
74
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
73
|
-
* @codegen <<SignedSource::
|
|
75
|
+
* @codegen <<SignedSource::3c4282c17de41bbfb755836f00326036>>
|
|
74
76
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
75
77
|
*/
|
|
76
78
|
|
|
77
79
|
var rules = exports.rules = {
|
|
78
80
|
'consistent-css-prop-usage': _consistentCssPropUsage.default,
|
|
81
|
+
'enforce-inline-styles-in-select': _enforceInlineStylesInSelect.default,
|
|
79
82
|
'ensure-design-token-usage': _ensureDesignTokenUsage.default,
|
|
80
83
|
'ensure-design-token-usage/preview': _ensureDesignTokenUsagePreview.default,
|
|
81
84
|
'ensure-icon-color': _ensureIconColor.default,
|
|
@@ -119,6 +122,7 @@ var rules = exports.rules = {
|
|
|
119
122
|
'no-utility-icons': _noUtilityIcons.default,
|
|
120
123
|
'prefer-primitives': _preferPrimitives.default,
|
|
121
124
|
'use-button-group-label': _useButtonGroupLabel.default,
|
|
125
|
+
'use-correct-field': _useCorrectField.default,
|
|
122
126
|
'use-cx-function-in-xcss': _useCxFunctionInXcss.default,
|
|
123
127
|
'use-datetime-picker-calendar-button': _useDatetimePickerCalendarButton.default,
|
|
124
128
|
'use-drawer-label': _useDrawerLabel.default,
|
|
@@ -58,18 +58,21 @@ var getKeyValue = function getKeyValue(node, context) {
|
|
|
58
58
|
}
|
|
59
59
|
return '';
|
|
60
60
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
61
|
+
|
|
62
|
+
// const isWidthMediaQuery = (rawSelector: string): boolean => {
|
|
63
|
+
// const selectors = parseSelector(rawSelector);
|
|
64
|
+
|
|
65
|
+
// if (selectors[0].startsWith('@')) {
|
|
66
|
+
// // If the selector includes a min-width/max-width query, return false - the primitives media object should be used instead:
|
|
67
|
+
// // https://staging.atlassian.design/components/primitives/responsive/breakpoints/examples
|
|
68
|
+
// // Otherwise return true, non-width queries are acceptable
|
|
69
|
+
// return selectors.some(
|
|
70
|
+
// (selector) => selector.includes('min-width') || selector.includes('max-width'),
|
|
71
|
+
// );
|
|
72
|
+
// }
|
|
73
|
+
// return false;
|
|
74
|
+
// };
|
|
75
|
+
|
|
73
76
|
var isAllowedNestedSelector = function isAllowedNestedSelector(rawSelector) {
|
|
74
77
|
if (rawSelector.trim() === '&') {
|
|
75
78
|
// This can be written without the nest.
|
|
@@ -101,7 +104,8 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
101
104
|
severity: 'error'
|
|
102
105
|
},
|
|
103
106
|
messages: {
|
|
104
|
-
noWidthQueries:
|
|
107
|
+
// noWidthQueries:
|
|
108
|
+
// 'Media queries that target min-width or max-width are not allowed. Use the media object provided by the Atlassian Design System instead. https://staging.atlassian.design/components/primitives/responsive/breakpoints/examples',
|
|
105
109
|
noNestedStyles: 'Nested styles are not allowed as they can change unexpectedly when child markup changes and result in duplicates when extracting to CSS.',
|
|
106
110
|
noDirectNestedStyles: "Styles applied with data attributes are not allowed, split them into discrete CSS declarations and apply them conditionally with JavaScript.\n\n```\nconst disabledStyles = css({ opacity: 0.5 });\n\n<div css={isDisabled && disabledStyles} />\n```\n"
|
|
107
111
|
}
|
|
@@ -119,13 +123,16 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
119
123
|
});
|
|
120
124
|
return;
|
|
121
125
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
|
|
127
|
+
// if (isWidthMediaQuery(getKeyValue(node.key as Rule.Node, context))) {
|
|
128
|
+
// context.report({
|
|
129
|
+
// node,
|
|
130
|
+
// messageId: 'noWidthQueries',
|
|
131
|
+
// });
|
|
132
|
+
|
|
133
|
+
// return;
|
|
134
|
+
// }
|
|
135
|
+
|
|
129
136
|
if (!isAllowedNestedSelector(getKeyValue(node.key, context))) {
|
|
130
137
|
context.report({
|
|
131
138
|
node: node,
|
|
@@ -11,7 +11,6 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
|
|
|
11
11
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
12
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
13
|
var specialCases = {
|
|
14
|
-
'@atlaskit/icon/utility/cross': '@atlaskit/icon/core/close',
|
|
15
14
|
'@atlaskit/icon/utility/migration/cross--editor-close': '@atlaskit/icon/core/migration/close--editor-close'
|
|
16
15
|
};
|
|
17
16
|
var iconPropsinNewButton = ['icon', 'iconBefore', 'iconAfter'];
|