@atlaskit/eslint-plugin-design-system 13.17.2 → 13.17.3

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -1
  4. package/dist/cjs/presets/all.codegen.js +2 -1
  5. package/dist/cjs/rules/enforce-inline-styles-in-select/index.js +76 -0
  6. package/dist/cjs/rules/enforce-inline-styles-in-select/utils.js +231 -0
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/no-nested-styles/index.js +27 -20
  9. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  10. package/dist/es2019/presets/all.codegen.js +2 -1
  11. package/dist/es2019/rules/enforce-inline-styles-in-select/index.js +68 -0
  12. package/dist/es2019/rules/enforce-inline-styles-in-select/utils.js +217 -0
  13. package/dist/es2019/rules/index.codegen.js +3 -1
  14. package/dist/es2019/rules/no-nested-styles/index.js +27 -18
  15. package/dist/esm/presets/all-flat.codegen.js +2 -1
  16. package/dist/esm/presets/all.codegen.js +2 -1
  17. package/dist/esm/rules/enforce-inline-styles-in-select/index.js +70 -0
  18. package/dist/esm/rules/enforce-inline-styles-in-select/utils.js +225 -0
  19. package/dist/esm/rules/index.codegen.js +3 -1
  20. package/dist/esm/rules/no-nested-styles/index.js +27 -20
  21. package/dist/types/index.codegen.d.ts +5 -0
  22. package/dist/types/presets/all-flat.codegen.d.ts +1 -0
  23. package/dist/types/presets/all.codegen.d.ts +1 -0
  24. package/dist/types/rules/enforce-inline-styles-in-select/index.d.ts +3 -0
  25. package/dist/types/rules/enforce-inline-styles-in-select/utils.d.ts +2 -0
  26. package/dist/types/rules/index.codegen.d.ts +1 -0
  27. package/dist/types-ts4.5/index.codegen.d.ts +5 -0
  28. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
  29. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
  30. package/dist/types-ts4.5/rules/enforce-inline-styles-in-select/index.d.ts +3 -0
  31. package/dist/types-ts4.5/rules/enforce-inline-styles-in-select/utils.d.ts +2 -0
  32. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  33. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 13.17.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
3
9
  ## 13.17.2
4
10
 
5
11
  ### 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. | | | |
@@ -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::5ceb45b21744434ca96a850461a3c574>>
9
+ * @codegen <<SignedSource::a8f7f6388f0499adc9db0228b7426aee>>
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',
@@ -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::b96d8bb5115de6e0a230feef152a1365>>
9
+ * @codegen <<SignedSource::aaf4f1ee2f2db236ebed7b77de426181>>
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',
@@ -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"));
@@ -70,12 +71,13 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
70
71
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
71
72
  /**
72
73
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
73
- * @codegen <<SignedSource::3de5d5b44aa01faabdb840bc7fb43d04>>
74
+ * @codegen <<SignedSource::c3ee5646fc648d2510a70195a04d7fe9>>
74
75
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
75
76
  */
76
77
 
77
78
  var rules = exports.rules = {
78
79
  'consistent-css-prop-usage': _consistentCssPropUsage.default,
80
+ 'enforce-inline-styles-in-select': _enforceInlineStylesInSelect.default,
79
81
  'ensure-design-token-usage': _ensureDesignTokenUsage.default,
80
82
  'ensure-design-token-usage/preview': _ensureDesignTokenUsagePreview.default,
81
83
  'ensure-icon-color': _ensureIconColor.default,
@@ -58,18 +58,21 @@ var getKeyValue = function getKeyValue(node, context) {
58
58
  }
59
59
  return '';
60
60
  };
61
- var isWidthMediaQuery = function isWidthMediaQuery(rawSelector) {
62
- var selectors = parseSelector(rawSelector);
63
- if (selectors[0].startsWith('@')) {
64
- // If the selector includes a min-width/max-width query, return false - the primitives media object should be used instead:
65
- // https://staging.atlassian.design/components/primitives/responsive/breakpoints/examples
66
- // Otherwise return true, non-width queries are acceptable
67
- return selectors.some(function (selector) {
68
- return selector.includes('min-width') || selector.includes('max-width');
69
- });
70
- }
71
- return false;
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: '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',
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
- if (isWidthMediaQuery(getKeyValue(node.key, context))) {
123
- context.report({
124
- node: node,
125
- messageId: 'noWidthQueries'
126
- });
127
- return;
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,
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::5ceb45b21744434ca96a850461a3c574>>
3
+ * @codegen <<SignedSource::a8f7f6388f0499adc9db0228b7426aee>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -9,6 +9,7 @@ export default {
9
9
  plugins: {},
10
10
  rules: {
11
11
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
12
+ '@atlaskit/design-system/enforce-inline-styles-in-select': 'error',
12
13
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
13
14
  '@atlaskit/design-system/ensure-design-token-usage/preview': 'warn',
14
15
  '@atlaskit/design-system/ensure-icon-color': 'error',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::b96d8bb5115de6e0a230feef152a1365>>
3
+ * @codegen <<SignedSource::aaf4f1ee2f2db236ebed7b77de426181>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -8,6 +8,7 @@ export default {
8
8
  plugins: ['@atlaskit/design-system'],
9
9
  rules: {
10
10
  '@atlaskit/design-system/consistent-css-prop-usage': 'error',
11
+ '@atlaskit/design-system/enforce-inline-styles-in-select': 'error',
11
12
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
12
13
  '@atlaskit/design-system/ensure-design-token-usage/preview': 'warn',
13
14
  '@atlaskit/design-system/ensure-icon-color': 'error',
@@ -0,0 +1,68 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { checkStylesObject } from './utils';
4
+ const rule = createLintRule({
5
+ meta: {
6
+ name: 'enforce-inline-styles-in-select',
7
+ docs: {
8
+ description: 'Disallow unsupported CSS selectors in styles prop for @atlaskit/select and require inline styles only',
9
+ recommended: false,
10
+ severity: 'error'
11
+ },
12
+ messages: {
13
+ noPseudoClass: "This selector '{{pseudo}}' is not allowed in styles for @atlaskit/select. Please use the `components` API in select with `xcss` props.",
14
+ noVariableStyles: 'Variable-defined styles are not allowed for @atlaskit/select. Please use inline styles object or the `components` API with `xcss` props.'
15
+ }
16
+ },
17
+ create(context) {
18
+ // Track imports of @atlaskit/select
19
+ const atlaskitSelectImports = new Set();
20
+ return {
21
+ ImportDeclaration(node) {
22
+ if (node.source.value !== '@atlaskit/select') {
23
+ return;
24
+ }
25
+ node.specifiers.forEach(spec => {
26
+ if (isNodeOfType(spec, 'ImportDefaultSpecifier')) {
27
+ atlaskitSelectImports.add(spec.local.name);
28
+ }
29
+ });
30
+ },
31
+ JSXElement(node) {
32
+ if (!isNodeOfType(node, 'JSXElement')) {
33
+ return;
34
+ }
35
+
36
+ // Check if this is a Select component from @atlaskit/select
37
+ if (isNodeOfType(node.openingElement.name, 'JSXIdentifier') && atlaskitSelectImports.has(node.openingElement.name.name)) {
38
+ // Look for styles prop
39
+ const stylesAttr = node.openingElement.attributes.find(attr => isNodeOfType(attr, 'JSXAttribute') && isNodeOfType(attr.name, 'JSXIdentifier') && attr.name.name === 'styles');
40
+ if (stylesAttr && isNodeOfType(stylesAttr, 'JSXAttribute') && stylesAttr.value) {
41
+ if (isNodeOfType(stylesAttr.value, 'JSXExpressionContainer')) {
42
+ const expression = stylesAttr.value.expression;
43
+
44
+ // Check if it's an inline object expression
45
+ if (isNodeOfType(expression, 'ObjectExpression')) {
46
+ // This is an inline styles object - check for unsupported selectors
47
+ checkStylesObject(node, expression, context);
48
+ } else if (isNodeOfType(expression, 'Identifier')) {
49
+ // This is a variable reference - not allowed
50
+ context.report({
51
+ node: expression,
52
+ messageId: 'noVariableStyles'
53
+ });
54
+ } else {
55
+ // Any other expression type (function calls, member expressions, etc.) - not allowed
56
+ context.report({
57
+ node: expression,
58
+ messageId: 'noVariableStyles'
59
+ });
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ };
66
+ }
67
+ });
68
+ export default rule;