@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -0
  3. package/dist/cjs/presets/all-flat.codegen.js +3 -1
  4. package/dist/cjs/presets/all.codegen.js +3 -1
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/enforce-inline-styles-in-select/index.js +76 -0
  8. package/dist/cjs/rules/enforce-inline-styles-in-select/utils.js +231 -0
  9. package/dist/cjs/rules/index.codegen.js +5 -1
  10. package/dist/cjs/rules/no-nested-styles/index.js +27 -20
  11. package/dist/cjs/rules/no-utility-icons/checks.js +0 -1
  12. package/dist/cjs/rules/use-correct-field/index.js +167 -0
  13. package/dist/es2019/presets/all-flat.codegen.js +3 -1
  14. package/dist/es2019/presets/all.codegen.js +3 -1
  15. package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
  16. package/dist/es2019/presets/recommended.codegen.js +2 -1
  17. package/dist/es2019/rules/enforce-inline-styles-in-select/index.js +68 -0
  18. package/dist/es2019/rules/enforce-inline-styles-in-select/utils.js +217 -0
  19. package/dist/es2019/rules/index.codegen.js +5 -1
  20. package/dist/es2019/rules/no-nested-styles/index.js +27 -18
  21. package/dist/es2019/rules/no-utility-icons/checks.js +0 -1
  22. package/dist/es2019/rules/use-correct-field/index.js +153 -0
  23. package/dist/esm/presets/all-flat.codegen.js +3 -1
  24. package/dist/esm/presets/all.codegen.js +3 -1
  25. package/dist/esm/presets/recommended-flat.codegen.js +2 -1
  26. package/dist/esm/presets/recommended.codegen.js +2 -1
  27. package/dist/esm/rules/enforce-inline-styles-in-select/index.js +70 -0
  28. package/dist/esm/rules/enforce-inline-styles-in-select/utils.js +225 -0
  29. package/dist/esm/rules/index.codegen.js +5 -1
  30. package/dist/esm/rules/no-nested-styles/index.js +27 -20
  31. package/dist/esm/rules/no-utility-icons/checks.js +0 -1
  32. package/dist/esm/rules/use-correct-field/index.js +161 -0
  33. package/dist/types/index.codegen.d.ts +14 -0
  34. package/dist/types/presets/all-flat.codegen.d.ts +2 -0
  35. package/dist/types/presets/all.codegen.d.ts +2 -0
  36. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -0
  37. package/dist/types/presets/recommended.codegen.d.ts +1 -0
  38. package/dist/types/rules/enforce-inline-styles-in-select/index.d.ts +3 -0
  39. package/dist/types/rules/enforce-inline-styles-in-select/utils.d.ts +2 -0
  40. package/dist/types/rules/index.codegen.d.ts +2 -0
  41. package/dist/types/rules/use-correct-field/index.d.ts +5 -0
  42. package/dist/types-ts4.5/index.codegen.d.ts +14 -0
  43. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +2 -0
  44. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -0
  45. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -0
  46. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -0
  47. package/dist/types-ts4.5/rules/enforce-inline-styles-in-select/index.d.ts +3 -0
  48. package/dist/types-ts4.5/rules/enforce-inline-styles-in-select/utils.d.ts +2 -0
  49. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  50. package/dist/types-ts4.5/rules/use-correct-field/index.d.ts +5 -0
  51. package/package.json +6 -7
@@ -0,0 +1,153 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ const specialFieldsByImport = {
4
+ '@atlaskit/checkbox': {
5
+ component: 'Checkbox',
6
+ field: 'CheckboxField',
7
+ local: undefined
8
+ },
9
+ '@atlaskit/range': {
10
+ component: 'Range',
11
+ field: 'RangeField',
12
+ local: undefined
13
+ },
14
+ '@atlaskit/toggle': {
15
+ component: 'Toggle',
16
+ field: 'CheckboxField',
17
+ local: undefined
18
+ }
19
+ };
20
+ export const useCheckboxFieldMessage = 'Convert Field to CheckboxField';
21
+ export const useRangeFieldMessage = 'Convert Field to RangeField';
22
+ const rule = createLintRule({
23
+ meta: {
24
+ name: 'use-correct-field',
25
+ type: 'suggestion',
26
+ fixable: 'code',
27
+ hasSuggestions: true,
28
+ docs: {
29
+ description: 'Ensure makers use appropriate field component for their respective form elements.',
30
+ recommended: true,
31
+ severity: 'warn'
32
+ },
33
+ messages: {
34
+ useCheckboxField: 'Checkbox components should use the `CheckboxField` component',
35
+ useRangeField: 'Range components should use the `RangeField` component',
36
+ useCheckboxFieldForToggle: 'Toggle components should use the `CheckboxField` component'
37
+ }
38
+ },
39
+ create(context) {
40
+ let fieldImport;
41
+ const allPackages = [];
42
+ return {
43
+ ImportDeclaration(node) {
44
+ const source = node.source.value;
45
+ if (typeof source !== 'string') {
46
+ return;
47
+ }
48
+ if (!node.specifiers.length) {
49
+ return;
50
+ }
51
+ const defaultImport = node.specifiers.filter(spec => isNodeOfType(spec, 'ImportDefaultSpecifier'));
52
+ if (source in specialFieldsByImport) {
53
+ allPackages.push(node);
54
+ // set local to local value
55
+ if (defaultImport.length && isNodeOfType(defaultImport[0], 'ImportDefaultSpecifier') && isNodeOfType(defaultImport[0].local, 'Identifier')) {
56
+ specialFieldsByImport[source].local = defaultImport[0].local.name;
57
+ }
58
+ }
59
+ if ('@atlaskit/form' !== source) {
60
+ return;
61
+ }
62
+ const namedImport = node.specifiers.filter(spec => isNodeOfType(spec, 'ImportSpecifier'));
63
+ if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && namedImport[0].imported.name === 'Field') {
64
+ fieldImport = namedImport[0].local;
65
+ }
66
+ },
67
+ JSXElement(node) {
68
+ if (!isNodeOfType(node, 'JSXElement')) {
69
+ return;
70
+ }
71
+ if (!isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
72
+ return;
73
+ }
74
+ const name = node.openingElement.name.name;
75
+
76
+ // if it's not a field import, skip
77
+ if (!fieldImport || name !== fieldImport.name) {
78
+ return;
79
+ }
80
+
81
+ // If no imports are for the inputs that have special fields, exit early
82
+ if (allPackages.every(n => typeof n.source.value !== 'string' || !Object.keys(specialFieldsByImport).includes(n.source.value))) {
83
+ return;
84
+ }
85
+ const fieldRenderProp = node.children.find(c => isNodeOfType(c, 'JSXExpressionContainer'));
86
+ if (!fieldRenderProp) {
87
+ return;
88
+ }
89
+ // I'm not early exiting because it doesn't work with ts for some reason
90
+ if (isNodeOfType(fieldRenderProp, 'JSXExpressionContainer')) {
91
+ if (!isNodeOfType(fieldRenderProp.expression, 'ArrowFunctionExpression')) {
92
+ return;
93
+ }
94
+ const q = [fieldRenderProp.expression.body];
95
+ let found;
96
+ while (q.length > 0 && !found) {
97
+ const child = q.pop();
98
+ if (!isNodeOfType(child, 'JSXElement') || !isNodeOfType(child.openingElement.name, 'JSXIdentifier')) {
99
+ continue;
100
+ }
101
+ const elementName = child.openingElement.name.name;
102
+ for (const importName in specialFieldsByImport) {
103
+ // if this child is one of the found component names
104
+ // then break out of the while loop and use the found object
105
+ const localName = specialFieldsByImport[importName].local;
106
+ if (localName === elementName) {
107
+ found = specialFieldsByImport[importName].component;
108
+ break;
109
+ }
110
+ }
111
+ }
112
+ if (!found) {
113
+ return;
114
+ }
115
+
116
+ // if checkbox is inside of the field's render prop
117
+ if (found === 'Checkbox' || found === 'Toggle') {
118
+ context.report({
119
+ node: node,
120
+ messageId: found === 'Checkbox' ? 'useCheckboxField' : 'useCheckboxFieldForToggle',
121
+ suggest: [{
122
+ desc: useCheckboxFieldMessage,
123
+ fix(fixer) {
124
+ const fixes = [];
125
+ fixes.push(fixer.insertTextBefore(fieldImport, 'CheckboxField, '));
126
+ fixes.push(fixer.replaceText(node.openingElement.name, 'CheckboxField'));
127
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'CheckboxField'));
128
+ return fixes;
129
+ }
130
+ }]
131
+ });
132
+ } else if (found === 'Range') {
133
+ context.report({
134
+ node: node,
135
+ messageId: 'useRangeField',
136
+ suggest: [{
137
+ desc: useRangeFieldMessage,
138
+ fix(fixer) {
139
+ const fixes = [];
140
+ fixes.push(fixer.insertTextBefore(fieldImport, 'RangeField, '));
141
+ fixes.push(fixer.replaceText(node.openingElement.name, 'RangeField'));
142
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'RangeField'));
143
+ return fixes;
144
+ }
145
+ }]
146
+ });
147
+ }
148
+ }
149
+ }
150
+ };
151
+ }
152
+ });
153
+ export default rule;
@@ -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::8fb6e53ac7d9be7b9252dd64ec022d26>>
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',
@@ -51,6 +52,7 @@ export default {
51
52
  '@atlaskit/design-system/no-utility-icons': 'warn',
52
53
  '@atlaskit/design-system/prefer-primitives': 'warn',
53
54
  '@atlaskit/design-system/use-button-group-label': 'warn',
55
+ '@atlaskit/design-system/use-correct-field': 'warn',
54
56
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
55
57
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
56
58
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -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::b727e6e2b1813b88da0df6ff6083be3c>>
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',
@@ -50,6 +51,7 @@ export default {
50
51
  '@atlaskit/design-system/no-utility-icons': 'warn',
51
52
  '@atlaskit/design-system/prefer-primitives': 'warn',
52
53
  '@atlaskit/design-system/use-button-group-label': 'warn',
54
+ '@atlaskit/design-system/use-correct-field': 'warn',
53
55
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
54
56
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
55
57
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -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::10f372e16c048db9bfb1bc36cf48421c>>
3
+ * @codegen <<SignedSource::af48ffd75d906d008c5701554187b606>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -38,6 +38,7 @@ export default {
38
38
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
39
39
  '@atlaskit/design-system/no-utility-icons': 'warn',
40
40
  '@atlaskit/design-system/use-button-group-label': 'warn',
41
+ '@atlaskit/design-system/use-correct-field': 'warn',
41
42
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
42
43
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
43
44
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -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::608f46f9cc8653226152a8edc34849d6>>
3
+ * @codegen <<SignedSource::96e803ae8ae873736bab690b2af62bed>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -37,6 +37,7 @@ export default {
37
37
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
38
38
  '@atlaskit/design-system/no-utility-icons': 'warn',
39
39
  '@atlaskit/design-system/use-button-group-label': 'warn',
40
+ '@atlaskit/design-system/use-correct-field': 'warn',
40
41
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
41
42
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
42
43
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -0,0 +1,70 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { checkStylesObject } from './utils';
4
+ var 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: function create(context) {
18
+ // Track imports of @atlaskit/select
19
+ var atlaskitSelectImports = new Set();
20
+ return {
21
+ ImportDeclaration: function ImportDeclaration(node) {
22
+ if (node.source.value !== '@atlaskit/select') {
23
+ return;
24
+ }
25
+ node.specifiers.forEach(function (spec) {
26
+ if (isNodeOfType(spec, 'ImportDefaultSpecifier')) {
27
+ atlaskitSelectImports.add(spec.local.name);
28
+ }
29
+ });
30
+ },
31
+ JSXElement: function 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
+ var stylesAttr = node.openingElement.attributes.find(function (attr) {
40
+ return isNodeOfType(attr, 'JSXAttribute') && isNodeOfType(attr.name, 'JSXIdentifier') && attr.name.name === 'styles';
41
+ });
42
+ if (stylesAttr && isNodeOfType(stylesAttr, 'JSXAttribute') && stylesAttr.value) {
43
+ if (isNodeOfType(stylesAttr.value, 'JSXExpressionContainer')) {
44
+ var expression = stylesAttr.value.expression;
45
+
46
+ // Check if it's an inline object expression
47
+ if (isNodeOfType(expression, 'ObjectExpression')) {
48
+ // This is an inline styles object - check for unsupported selectors
49
+ checkStylesObject(node, expression, context);
50
+ } else if (isNodeOfType(expression, 'Identifier')) {
51
+ // This is a variable reference - not allowed
52
+ context.report({
53
+ node: expression,
54
+ messageId: 'noVariableStyles'
55
+ });
56
+ } else {
57
+ // Any other expression type (function calls, member expressions, etc.) - not allowed
58
+ context.report({
59
+ node: expression,
60
+ messageId: 'noVariableStyles'
61
+ });
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ };
68
+ }
69
+ });
70
+ export default rule;
@@ -0,0 +1,225 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ var unsupportedSelectors = [':',
3
+ // pseudo-classes/elements
4
+ '[',
5
+ // attribute selectors
6
+ '>',
7
+ // child combinator
8
+ '+',
9
+ // adjacent sibling combinator
10
+ '~',
11
+ // general sibling combinator
12
+ ' ',
13
+ // descendant combinator
14
+ '*',
15
+ // universal selector
16
+ '#',
17
+ // ID selector
18
+ '.',
19
+ // class selector
20
+ '@',
21
+ // at-rules
22
+ '&',
23
+ // parent selector
24
+ '|',
25
+ // namespace separator
26
+ '^',
27
+ // starts with
28
+ '$',
29
+ // ends with
30
+ '=' // equals
31
+ ];
32
+ function checkForPseudoClasses(node, objectExpression, context) {
33
+ if (!isNodeOfType(objectExpression, 'ObjectExpression')) {
34
+ return;
35
+ }
36
+ objectExpression.properties.forEach(function (prop) {
37
+ if (isNodeOfType(prop, 'Property')) {
38
+ // Check if property key is a pseudo-class
39
+ var keyValue = null;
40
+ if (isNodeOfType(prop.key, 'Literal')) {
41
+ keyValue = prop.key.value;
42
+ } else if (isNodeOfType(prop.key, 'Identifier')) {
43
+ keyValue = prop.key.name;
44
+ }
45
+ if (keyValue && typeof keyValue === 'string' && unsupportedSelectors.some(function (selector) {
46
+ return keyValue.includes(selector);
47
+ })) {
48
+ context.report({
49
+ node: prop.key,
50
+ messageId: 'noPseudoClass',
51
+ data: {
52
+ pseudo: keyValue
53
+ }
54
+ });
55
+ }
56
+
57
+ // Recursively check nested objects (for function return values)
58
+ if (isNodeOfType(prop.value, 'ArrowFunctionExpression') || isNodeOfType(prop.value, 'FunctionExpression')) {
59
+ // Check the function body for returned object expressions
60
+ var body = prop.value.body;
61
+ if (isNodeOfType(body, 'ObjectExpression')) {
62
+ checkForPseudoClasses(node, body, context);
63
+ } else if (isNodeOfType(body, 'BlockStatement')) {
64
+ // Look for return statements
65
+ body.body.forEach(function (stmt) {
66
+ if (isNodeOfType(stmt, 'ReturnStatement') && stmt.argument && isNodeOfType(stmt.argument, 'ObjectExpression')) {
67
+ checkForPseudoClasses(node, stmt.argument, context);
68
+ }
69
+ });
70
+ }
71
+ } else if (isNodeOfType(prop.value, 'ObjectExpression')) {
72
+ checkForPseudoClasses(node, prop.value, context);
73
+ }
74
+ } else if (isNodeOfType(prop, 'SpreadElement')) {
75
+ // Handle spread elements like ...styles or ...conditionalStyles
76
+ checkSpreadElement(node, prop, context);
77
+ }
78
+ });
79
+ }
80
+ function checkSpreadElement(node, spreadElement, context) {
81
+ if (!isNodeOfType(spreadElement, 'SpreadElement')) {
82
+ return;
83
+ }
84
+ var argument = spreadElement.argument;
85
+
86
+ // Handle direct identifier (e.g., ...styles)
87
+ if (isNodeOfType(argument, 'Identifier')) {
88
+ var scope = context.getScope();
89
+ var variable = null;
90
+ var currentScope = scope;
91
+
92
+ // Search through scope chain
93
+ while (currentScope && !variable) {
94
+ variable = currentScope.variables.find(function (v) {
95
+ return v.name === argument.name;
96
+ });
97
+ currentScope = currentScope.upper;
98
+ }
99
+ if (variable && variable.defs.length > 0) {
100
+ var def = variable.defs[0];
101
+ if (isNodeOfType(def.node, 'VariableDeclarator') && def.node.init) {
102
+ if (isNodeOfType(def.node.init, 'ObjectExpression')) {
103
+ checkForPseudoClasses(node, def.node.init, context);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ // Handle conditional expressions (e.g., ...(condition ? { ':hover': ... } : undefined))
109
+ else if (isNodeOfType(argument, 'ConditionalExpression')) {
110
+ // Check both consequent and alternate
111
+ if (isNodeOfType(argument.consequent, 'ObjectExpression')) {
112
+ checkForPseudoClasses(node, argument.consequent, context);
113
+ }
114
+ if (argument.alternate && isNodeOfType(argument.alternate, 'ObjectExpression')) {
115
+ checkForPseudoClasses(node, argument.alternate, context);
116
+ }
117
+ }
118
+ // Handle logical expressions (e.g., ...condition && { ':hover': ... })
119
+ else if (isNodeOfType(argument, 'LogicalExpression')) {
120
+ if (isNodeOfType(argument.right, 'ObjectExpression')) {
121
+ checkForPseudoClasses(node, argument.right, context);
122
+ }
123
+ if (isNodeOfType(argument.left, 'ObjectExpression')) {
124
+ checkForPseudoClasses(node, argument.left, context);
125
+ }
126
+ }
127
+ // Handle direct object expressions (e.g., ...{ ':hover': ... })
128
+ else if (isNodeOfType(argument, 'ObjectExpression')) {
129
+ checkForPseudoClasses(node, argument, context);
130
+ }
131
+ }
132
+ export function checkStylesObject(node, stylesValue, context) {
133
+ if (!stylesValue) {
134
+ return;
135
+ }
136
+ if (isNodeOfType(stylesValue, 'ObjectExpression')) {
137
+ stylesValue.properties.forEach(function (prop) {
138
+ if (!isNodeOfType(prop, 'Property') || !prop.value || !isNodeOfType(prop.value, 'ArrowFunctionExpression') && !isNodeOfType(prop.value, 'FunctionExpression')) {
139
+ return;
140
+ }
141
+ var body = prop.value.body;
142
+ if (isNodeOfType(body, 'ObjectExpression')) {
143
+ checkForPseudoClasses(node, body, context);
144
+ } else if (isNodeOfType(body, 'BlockStatement')) {
145
+ var visitor = {
146
+ ReturnStatement: function ReturnStatement(returnStmt) {
147
+ if (returnStmt.argument && isNodeOfType(returnStmt.argument, 'ObjectExpression')) {
148
+ checkForPseudoClasses(node, returnStmt.argument, context);
149
+ }
150
+ },
151
+ AssignmentExpression: function AssignmentExpression(assignExpr) {
152
+ // Handle cases like styles[':hover'] = { ... }
153
+ var left = assignExpr.left;
154
+ if (!isNodeOfType(left, 'MemberExpression')) {
155
+ return;
156
+ }
157
+ var property = left.property;
158
+ if (!isNodeOfType(property, 'Literal')) {
159
+ return;
160
+ }
161
+ var value = property.value;
162
+ if (typeof value !== 'string') {
163
+ return;
164
+ }
165
+ if (unsupportedSelectors.some(function (selector) {
166
+ return value.includes(selector);
167
+ })) {
168
+ context.report({
169
+ node: property,
170
+ messageId: 'noPseudoClass',
171
+ data: {
172
+ pseudo: value
173
+ }
174
+ });
175
+ }
176
+ }
177
+ };
178
+ body.body.forEach(function (stmt) {
179
+ if (isNodeOfType(stmt, 'ReturnStatement')) {
180
+ visitor.ReturnStatement(stmt);
181
+ } else if (isNodeOfType(stmt, 'ExpressionStatement') && isNodeOfType(stmt.expression, 'AssignmentExpression')) {
182
+ visitor.AssignmentExpression(stmt.expression);
183
+ } else if (isNodeOfType(stmt, 'IfStatement')) {
184
+ var checkBlock = function checkBlock(block) {
185
+ if (isNodeOfType(block, 'BlockStatement')) {
186
+ block.body.forEach(function (innerStmt) {
187
+ if (isNodeOfType(innerStmt, 'ExpressionStatement') && isNodeOfType(innerStmt.expression, 'AssignmentExpression')) {
188
+ visitor.AssignmentExpression(innerStmt.expression);
189
+ }
190
+ });
191
+ } else if (isNodeOfType(block, 'ExpressionStatement') && isNodeOfType(block.expression, 'AssignmentExpression')) {
192
+ visitor.AssignmentExpression(block.expression);
193
+ }
194
+ };
195
+ if (stmt.consequent) {
196
+ checkBlock(stmt.consequent);
197
+ }
198
+ if (stmt.alternate) {
199
+ checkBlock(stmt.alternate);
200
+ }
201
+ }
202
+ });
203
+ }
204
+ });
205
+ } else if (isNodeOfType(stylesValue, 'Identifier')) {
206
+ // track the variable
207
+ var scope = context.getScope();
208
+ var variable = null;
209
+ var currentScope = scope;
210
+
211
+ // Search through scope chain
212
+ while (currentScope && !variable) {
213
+ variable = currentScope.variables.find(function (v) {
214
+ return v.name === stylesValue.name;
215
+ });
216
+ currentScope = currentScope.upper;
217
+ }
218
+ if (variable && variable.defs.length > 0) {
219
+ var def = variable.defs[0];
220
+ if (isNodeOfType(def.node, 'VariableDeclarator') && def.node.init) {
221
+ checkStylesObject(node, def.node.init, context);
222
+ }
223
+ }
224
+ }
225
+ }
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::3de5d5b44aa01faabdb840bc7fb43d04>>
3
+ * @codegen <<SignedSource::3c4282c17de41bbfb755836f00326036>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
7
+ import enforceInlineStylesInSelect from './enforce-inline-styles-in-select';
7
8
  import ensureDesignTokenUsage from './ensure-design-token-usage';
8
9
  import ensureDesignTokenUsagePreview from './ensure-design-token-usage-preview';
9
10
  import ensureIconColor from './ensure-icon-color';
@@ -47,6 +48,7 @@ import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-li
47
48
  import noUtilityIcons from './no-utility-icons';
48
49
  import preferPrimitives from './prefer-primitives';
49
50
  import useButtonGroupLabel from './use-button-group-label';
51
+ import useCorrectField from './use-correct-field';
50
52
  import useCxFunctionInXcss from './use-cx-function-in-xcss';
51
53
  import useDatetimePickerCalendarButton from './use-datetime-picker-calendar-button';
52
54
  import useDrawerLabel from './use-drawer-label';
@@ -68,6 +70,7 @@ import useTokensTypography from './use-tokens-typography';
68
70
  import useVisuallyHidden from './use-visually-hidden';
69
71
  export var rules = {
70
72
  'consistent-css-prop-usage': consistentCssPropUsage,
73
+ 'enforce-inline-styles-in-select': enforceInlineStylesInSelect,
71
74
  'ensure-design-token-usage': ensureDesignTokenUsage,
72
75
  'ensure-design-token-usage/preview': ensureDesignTokenUsagePreview,
73
76
  'ensure-icon-color': ensureIconColor,
@@ -111,6 +114,7 @@ export var rules = {
111
114
  'no-utility-icons': noUtilityIcons,
112
115
  'prefer-primitives': preferPrimitives,
113
116
  'use-button-group-label': useButtonGroupLabel,
117
+ 'use-correct-field': useCorrectField,
114
118
  'use-cx-function-in-xcss': useCxFunctionInXcss,
115
119
  'use-datetime-picker-calendar-button': useDatetimePickerCalendarButton,
116
120
  'use-drawer-label': useDrawerLabel,
@@ -52,18 +52,21 @@ var getKeyValue = function getKeyValue(node, context) {
52
52
  }
53
53
  return '';
54
54
  };
55
- var isWidthMediaQuery = function isWidthMediaQuery(rawSelector) {
56
- var selectors = parseSelector(rawSelector);
57
- if (selectors[0].startsWith('@')) {
58
- // If the selector includes a min-width/max-width query, return false - the primitives media object should be used instead:
59
- // https://staging.atlassian.design/components/primitives/responsive/breakpoints/examples
60
- // Otherwise return true, non-width queries are acceptable
61
- return selectors.some(function (selector) {
62
- return selector.includes('min-width') || selector.includes('max-width');
63
- });
64
- }
65
- return false;
66
- };
55
+
56
+ // const isWidthMediaQuery = (rawSelector: string): boolean => {
57
+ // const selectors = parseSelector(rawSelector);
58
+
59
+ // if (selectors[0].startsWith('@')) {
60
+ // // If the selector includes a min-width/max-width query, return false - the primitives media object should be used instead:
61
+ // // https://staging.atlassian.design/components/primitives/responsive/breakpoints/examples
62
+ // // Otherwise return true, non-width queries are acceptable
63
+ // return selectors.some(
64
+ // (selector) => selector.includes('min-width') || selector.includes('max-width'),
65
+ // );
66
+ // }
67
+ // return false;
68
+ // };
69
+
67
70
  var isAllowedNestedSelector = function isAllowedNestedSelector(rawSelector) {
68
71
  if (rawSelector.trim() === '&') {
69
72
  // This can be written without the nest.
@@ -95,7 +98,8 @@ var rule = createLintRule({
95
98
  severity: 'error'
96
99
  },
97
100
  messages: {
98
- 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',
101
+ // noWidthQueries:
102
+ // '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',
99
103
  noNestedStyles: 'Nested styles are not allowed as they can change unexpectedly when child markup changes and result in duplicates when extracting to CSS.',
100
104
  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"
101
105
  }
@@ -113,13 +117,16 @@ var rule = createLintRule({
113
117
  });
114
118
  return;
115
119
  }
116
- if (isWidthMediaQuery(getKeyValue(node.key, context))) {
117
- context.report({
118
- node: node,
119
- messageId: 'noWidthQueries'
120
- });
121
- return;
122
- }
120
+
121
+ // if (isWidthMediaQuery(getKeyValue(node.key as Rule.Node, context))) {
122
+ // context.report({
123
+ // node,
124
+ // messageId: 'noWidthQueries',
125
+ // });
126
+
127
+ // return;
128
+ // }
129
+
123
130
  if (!isAllowedNestedSelector(getKeyValue(node.key, context))) {
124
131
  context.report({
125
132
  node: node,
@@ -4,7 +4,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
4
4
  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; }
5
5
  import { isNodeOfType } from 'eslint-codemod-utils';
6
6
  var specialCases = {
7
- '@atlaskit/icon/utility/cross': '@atlaskit/icon/core/close',
8
7
  '@atlaskit/icon/utility/migration/cross--editor-close': '@atlaskit/icon/core/migration/close--editor-close'
9
8
  };
10
9
  var iconPropsinNewButton = ['icon', 'iconBefore', 'iconAfter'];