@atlaskit/eslint-plugin-ui-styling-standard 1.4.6 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +18 -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/presets/recommended-flat.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/no-important-styles/index.js +95 -28
  9. package/dist/cjs/rules/no-unsafe-selectors/constants.js +49 -2
  10. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +10 -5
  11. package/dist/cjs/rules/no-unused-cssmap-properties/index.js +192 -0
  12. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  13. package/dist/es2019/presets/all.codegen.js +2 -1
  14. package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
  15. package/dist/es2019/presets/recommended.codegen.js +2 -1
  16. package/dist/es2019/rules/index.codegen.js +3 -1
  17. package/dist/es2019/rules/no-important-styles/index.js +65 -13
  18. package/dist/es2019/rules/no-unsafe-selectors/constants.js +48 -1
  19. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +10 -5
  20. package/dist/es2019/rules/no-unused-cssmap-properties/index.js +182 -0
  21. package/dist/esm/presets/all-flat.codegen.js +2 -1
  22. package/dist/esm/presets/all.codegen.js +2 -1
  23. package/dist/esm/presets/recommended-flat.codegen.js +2 -1
  24. package/dist/esm/presets/recommended.codegen.js +2 -1
  25. package/dist/esm/rules/index.codegen.js +3 -1
  26. package/dist/esm/rules/no-important-styles/index.js +95 -27
  27. package/dist/esm/rules/no-unsafe-selectors/constants.js +48 -1
  28. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +10 -5
  29. package/dist/esm/rules/no-unused-cssmap-properties/index.js +186 -0
  30. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  31. package/dist/types/presets/all.codegen.d.ts +1 -1
  32. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
  33. package/dist/types/presets/recommended.codegen.d.ts +1 -1
  34. package/dist/types/rules/index.codegen.d.ts +1 -1
  35. package/dist/types/rules/no-array-arguments/index.d.ts +1 -1
  36. package/dist/types/rules/no-classname-prop/index.d.ts +1 -1
  37. package/dist/types/rules/no-container-queries/index.d.ts +1 -1
  38. package/dist/types/rules/no-dynamic-styles/index.d.ts +1 -1
  39. package/dist/types/rules/no-exported-styles/index.d.ts +1 -1
  40. package/dist/types/rules/no-global-styles/index.d.ts +1 -1
  41. package/dist/types/rules/no-important-styles/index.d.ts +1 -1
  42. package/dist/types/rules/no-nested-selectors/index.d.ts +1 -1
  43. package/dist/types/rules/no-styled/index.d.ts +1 -1
  44. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +45 -0
  45. package/dist/types/rules/no-unsafe-values/index.d.ts +1 -1
  46. package/dist/types/rules/no-unused-cssmap-properties/index.d.ts +3 -0
  47. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
  48. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  49. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -1
  50. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
  51. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  52. package/dist/types-ts4.5/rules/no-array-arguments/index.d.ts +1 -1
  53. package/dist/types-ts4.5/rules/no-classname-prop/index.d.ts +1 -1
  54. package/dist/types-ts4.5/rules/no-container-queries/index.d.ts +1 -1
  55. package/dist/types-ts4.5/rules/no-dynamic-styles/index.d.ts +1 -1
  56. package/dist/types-ts4.5/rules/no-exported-styles/index.d.ts +1 -1
  57. package/dist/types-ts4.5/rules/no-global-styles/index.d.ts +1 -1
  58. package/dist/types-ts4.5/rules/no-important-styles/index.d.ts +1 -1
  59. package/dist/types-ts4.5/rules/no-nested-selectors/index.d.ts +1 -1
  60. package/dist/types-ts4.5/rules/no-styled/index.d.ts +1 -1
  61. package/dist/types-ts4.5/rules/no-unsafe-selectors/constants.d.ts +45 -0
  62. package/dist/types-ts4.5/rules/no-unsafe-values/index.d.ts +1 -1
  63. package/dist/types-ts4.5/rules/no-unused-cssmap-properties/index.d.ts +3 -0
  64. package/package.json +2 -2
@@ -1,4 +1,3 @@
1
- import esquery from 'esquery';
2
1
  import { getScope } from '@atlaskit/eslint-utils/context-compat';
3
2
  import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
4
3
  import { importSources } from '@atlaskit/eslint-utils/schema';
@@ -33,31 +32,84 @@ export const rule = createLintRuleWithTypedConfig({
33
32
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
34
33
  return;
35
34
  }
36
- const matches = esquery(node, 'Property');
37
- for (const match of matches) {
38
- if (match.type !== 'Property') {
39
- return;
40
- }
41
- if (isImportant(match.value)) {
35
+ walkProperties(node, propertyNode => {
36
+ if (isImportant(propertyNode.value)) {
42
37
  context.report({
43
- node: match.value,
38
+ node: propertyNode.value,
44
39
  messageId: 'no-important-styles'
45
40
  });
46
41
  }
47
- }
42
+ });
48
43
  }
49
44
  };
50
45
  }
51
46
  });
52
47
  export default rule;
53
- const importantRegex = /!\s*important\s*$/;
48
+ const IMPORTANT_SUFFIX_REGEX = /!\s*important\s*$/;
49
+
50
+ /**
51
+ * Walk through all Property nodes in the AST tree recursively.
52
+ * This is faster than esquery for this specific use case as it avoids
53
+ * selector compilation and executes a simple depth-first traversal.
54
+ */
55
+ function walkProperties(node, callback) {
56
+ var _node$arguments;
57
+ if (node.type === 'Property' && node.value) {
58
+ callback(node);
59
+ }
60
+
61
+ // Iterate through object properties
62
+ if ((_node$arguments = node.arguments) !== null && _node$arguments !== void 0 && _node$arguments.length) {
63
+ for (const arg of node.arguments) {
64
+ if (arg.type === 'ObjectExpression' && arg.properties) {
65
+ for (const prop of arg.properties) {
66
+ walkObjectProperty(prop, callback);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Recursively walk object properties to find nested Property nodes.
75
+ */
76
+ function walkObjectProperty(node, callback) {
77
+ if (node.type === 'Property') {
78
+ var _node$value;
79
+ callback(node);
80
+ // Recursively check nested objects
81
+ if (((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'ObjectExpression' && node.value.properties) {
82
+ for (const prop of node.value.properties) {
83
+ walkObjectProperty(prop, callback);
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Check if a value contains !important flag.
91
+ * Uses fast string checks before regex to avoid regex overhead for common cases.
92
+ */
54
93
  function isImportant(node) {
55
94
  if (node.type === 'Literal') {
56
- return typeof node.value === 'string' && importantRegex.test(node.value);
95
+ if (typeof node.value !== 'string') {
96
+ return false;
97
+ }
98
+ // Fast check: string must end with 'important' (after optional whitespace)
99
+ const len = node.value.length;
100
+ if (len < 10) {
101
+ return false;
102
+ } // "!important" is 10 chars minimum
103
+ return IMPORTANT_SUFFIX_REGEX.test(node.value);
57
104
  }
58
105
  if (node.type === 'TemplateLiteral') {
59
- const joinedRaw = node.quasis.map(element => element.value.raw).join('');
60
- return importantRegex.test(joinedRaw);
106
+ var _node$quasis;
107
+ if (!((_node$quasis = node.quasis) !== null && _node$quasis !== void 0 && _node$quasis.length)) {
108
+ return false;
109
+ }
110
+ // Only check the last quasi's raw value (most likely to contain the !important)
111
+ const lastQuasi = node.quasis[node.quasis.length - 1];
112
+ return IMPORTANT_SUFFIX_REGEX.test(lastQuasi.value.raw);
61
113
  }
62
114
  return false;
63
115
  }
@@ -19,4 +19,51 @@ export const ignoredAtRules = new Set(['@container',
19
19
  // ignored because it's covered by `no-container-queries`
20
20
  '@media',
21
21
  // ignored because it's covered by `no-nested-styles`
22
- '@supports', '@property']);
22
+ '@supports', '@property', '@starting-style']);
23
+
24
+ /**
25
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
26
+ *
27
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
28
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
29
+ *
30
+ * ```typescript
31
+ * // ❌ GROUPED (not allowed for @media):
32
+ * cssMap({
33
+ * variant: {
34
+ * '@media': { // at-rule key with no parameters
35
+ * '(min-width: 900px)': {}, // nested variants
36
+ * '(min-width: 1200px)': {},
37
+ * }
38
+ * }
39
+ * })
40
+ *
41
+ * // ✅ FLAT (preferred for @media):
42
+ * cssMap({
43
+ * variant: {
44
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
45
+ * '@media (min-width: 1200px)': {},
46
+ * }
47
+ * })
48
+ * ```
49
+ *
50
+ * However, some at-rules like `@starting-style` have no parameters and can only be
51
+ * written in the "grouped" form at the variant level:
52
+ *
53
+ * ```typescript
54
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
55
+ * cssMap({
56
+ * fade: {
57
+ * '@starting-style': { // at-rule with no parameters
58
+ * opacity: 0, // styles to apply
59
+ * }
60
+ * }
61
+ * })
62
+ * ```
63
+ *
64
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
65
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
66
+ * `walkStyleRuleset` and are not considered "grouped".
67
+ */
68
+ export const allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
69
+ ]);
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
8
+ import { allowedGroupedAtRules } from './constants';
8
9
  export function walkCssMap({
9
10
  context,
10
11
  importSources,
@@ -102,11 +103,15 @@ function walkCssMapAtRuleGrouping({
102
103
  if (!atRule) {
103
104
  return;
104
105
  }
105
- visitor({
106
- type: 'grouped-at-rules',
107
- node: atRuleGrouping,
108
- atRule
109
- });
106
+
107
+ // Skip reporting if the at-rule is allowed to be grouped
108
+ if (!allowedGroupedAtRules.has(atRule)) {
109
+ visitor({
110
+ type: 'grouped-at-rules',
111
+ node: atRuleGrouping,
112
+ atRule
113
+ });
114
+ }
110
115
  if (atRuleGrouping.value.type !== 'ObjectExpression') {
111
116
  return;
112
117
  }
@@ -0,0 +1,182 @@
1
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
+ import { CSS_IN_JS_IMPORTS, isCssMap } from '@atlaskit/eslint-utils/is-supported-import';
3
+ import { createLintRule } from '../utils/create-rule';
4
+ const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
5
+
6
+ /**
7
+ * Gets the key name from a property node
8
+ */
9
+ function getPropertyKeyName(property) {
10
+ if (property.key.type === 'Identifier') {
11
+ return property.key.name;
12
+ }
13
+ if (property.key.type === 'Literal' && typeof property.key.value === 'string') {
14
+ return property.key.value;
15
+ }
16
+ return null;
17
+ }
18
+
19
+ /**
20
+ * Checks if a variable is exported from the module
21
+ */
22
+ function isExported(node, context) {
23
+ let parent = node.parent;
24
+
25
+ // Walk up to find VariableDeclaration
26
+ while (parent && parent.type !== 'VariableDeclaration') {
27
+ parent = parent.parent;
28
+ }
29
+ if (!parent) {
30
+ return false;
31
+ }
32
+
33
+ // Check if the VariableDeclaration is an ExportNamedDeclaration
34
+ const grandParent = parent.parent;
35
+ if (grandParent && grandParent.type === 'ExportNamedDeclaration') {
36
+ return true;
37
+ }
38
+
39
+ // Check if the variable is exported elsewhere in the file via `export { styles }`
40
+ if (node.id.type === 'Identifier') {
41
+ const scope = getScope(context, node);
42
+ const variableName = node.id.name;
43
+ const variable = scope.variables.find(v => v.name === variableName);
44
+ if (variable) {
45
+ // Check if any reference is a direct export specifier (e.g., `export { styles }`)
46
+ return variable.references.some(ref => {
47
+ const refParent = ref.identifier.parent;
48
+ // Check for direct export: `export { styles }` or `export { styles as something }`
49
+ // In this case, the identifier's parent is an ExportSpecifier
50
+ if (refParent && refParent.type === 'ExportSpecifier') {
51
+ return true;
52
+ }
53
+ // Check for default export: `export default styles`
54
+ if (refParent && refParent.type === 'ExportDefaultDeclaration') {
55
+ return true;
56
+ }
57
+ return false;
58
+ });
59
+ }
60
+ }
61
+ return false;
62
+ }
63
+ export const rule = createLintRule({
64
+ meta: {
65
+ name: 'no-unused-cssmap-properties',
66
+ docs: {
67
+ description: 'Detects unused properties in cssMap style objects that are not exported. Helps maintain clean code by identifying style variants that are defined but never used.',
68
+ recommended: true,
69
+ severity: 'warn'
70
+ },
71
+ messages: {
72
+ 'unused-property': 'The "{{propertyName}}" style is defined but never used.'
73
+ },
74
+ type: 'problem'
75
+ },
76
+ create(context) {
77
+ return {
78
+ VariableDeclarator(node) {
79
+ var _getSourceCode$scopeM;
80
+ if (node.type !== 'VariableDeclarator') {
81
+ return;
82
+ }
83
+
84
+ // Only process if the initializer is a cssMap call
85
+ if (!node.init || node.init.type !== 'CallExpression' || !isCssMap(node.init.callee, getScope(context, node).references, IMPORT_SOURCES)) {
86
+ return;
87
+ }
88
+
89
+ // Skip if the cssMap is exported
90
+ if (isExported(node, context)) {
91
+ return;
92
+ }
93
+
94
+ // Get the cssMap argument (should be an object expression)
95
+ const cssMapArg = node.init.arguments[0];
96
+ if (!cssMapArg || cssMapArg.type !== 'ObjectExpression') {
97
+ return;
98
+ }
99
+
100
+ // Get the variable name
101
+ if (node.id.type !== 'Identifier') {
102
+ return;
103
+ }
104
+ const variableName = node.id.name;
105
+
106
+ // Use getDeclaredVariables to get the variable with all its references
107
+ // across all scopes (including nested function components)
108
+ const declaredVariables = (_getSourceCode$scopeM = getSourceCode(context).scopeManager) === null || _getSourceCode$scopeM === void 0 ? void 0 : _getSourceCode$scopeM.getDeclaredVariables(node);
109
+ const variable = declaredVariables === null || declaredVariables === void 0 ? void 0 : declaredVariables.find(v => v.name === variableName);
110
+ if (!variable) {
111
+ return;
112
+ }
113
+
114
+ // Track which properties are defined
115
+ const definedProperties = new Set();
116
+ cssMapArg.properties.forEach(prop => {
117
+ if (prop.type === 'Property') {
118
+ const keyName = getPropertyKeyName(prop);
119
+ if (keyName) {
120
+ definedProperties.add(keyName);
121
+ }
122
+ }
123
+ });
124
+
125
+ // Track which properties are used
126
+ const usedProperties = new Set();
127
+ let hasNonPropertyAccess = false;
128
+ variable.references.forEach(reference => {
129
+ // Skip the declaration itself
130
+ if (reference.init) {
131
+ return;
132
+ }
133
+ const identifier = reference.identifier;
134
+ const parent = identifier.parent;
135
+
136
+ // Check if it's a member access (e.g., styles.root)
137
+ if (parent && parent.type === 'MemberExpression' && parent.object === identifier) {
138
+ // Check if it's computed (dynamic) property access like styles[dynamicKey]
139
+ if (parent.computed) {
140
+ // Dynamic access - we can't determine which properties are used
141
+ hasNonPropertyAccess = true;
142
+ return;
143
+ }
144
+
145
+ // Static property access
146
+ if (parent.property.type === 'Identifier') {
147
+ usedProperties.add(parent.property.name);
148
+ } else if (parent.property.type === 'Literal' && typeof parent.property.value === 'string') {
149
+ usedProperties.add(parent.property.value);
150
+ }
151
+ } else {
152
+ // The cssMap object is used as a whole (e.g., spread, passed to function, etc.)
153
+ // In this case, we can't determine which properties are used, so mark all as used
154
+ hasNonPropertyAccess = true;
155
+ }
156
+ });
157
+
158
+ // If the object is used as a whole (not just property access), skip checks
159
+ if (hasNonPropertyAccess) {
160
+ return;
161
+ }
162
+
163
+ // Report unused properties
164
+ cssMapArg.properties.forEach(prop => {
165
+ if (prop.type === 'Property') {
166
+ const keyName = getPropertyKeyName(prop);
167
+ if (keyName && !usedProperties.has(keyName)) {
168
+ context.report({
169
+ node: prop.key,
170
+ messageId: 'unused-property',
171
+ data: {
172
+ propertyName: keyName
173
+ }
174
+ });
175
+ }
176
+ }
177
+ });
178
+ }
179
+ };
180
+ }
181
+ });
182
+ 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::a031ffa483e224bf49a4e9eec39acb69>>
3
+ * @codegen <<SignedSource::f99588f71d6b353cefbed97fd172e433>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -27,6 +27,7 @@ var config = {
27
27
  '@atlaskit/ui-styling-standard/no-styled': 'error',
28
28
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
29
29
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
30
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
30
31
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
31
32
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
32
33
  excludeReactComponents: true,
@@ -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::778759f32da9fc9b6d182dba1b796640>>
3
+ * @codegen <<SignedSource::8f28dfef84548edbe33f59201f295cc5>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -23,6 +23,7 @@ var config = {
23
23
  '@atlaskit/ui-styling-standard/no-styled': 'error',
24
24
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
25
25
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
26
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
26
27
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
27
28
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
28
29
  excludeReactComponents: true,
@@ -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::a031ffa483e224bf49a4e9eec39acb69>>
3
+ * @codegen <<SignedSource::f99588f71d6b353cefbed97fd172e433>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -27,6 +27,7 @@ var config = {
27
27
  '@atlaskit/ui-styling-standard/no-styled': 'error',
28
28
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
29
29
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
30
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
30
31
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
31
32
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
32
33
  excludeReactComponents: true,
@@ -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::778759f32da9fc9b6d182dba1b796640>>
3
+ * @codegen <<SignedSource::8f28dfef84548edbe33f59201f295cc5>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -23,6 +23,7 @@ var config = {
23
23
  '@atlaskit/ui-styling-standard/no-styled': 'error',
24
24
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
25
25
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
26
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
26
27
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
27
28
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
28
29
  excludeReactComponents: true,
@@ -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::34a66bfc786bfa49ea7d4ad66ffe81f7>>
3
+ * @codegen <<SignedSource::2eab912b0c44d0fcbdc2f0b79cb42fa9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -20,6 +20,7 @@ import noNestedSelectors from './no-nested-selectors';
20
20
  import noStyled from './no-styled';
21
21
  import noUnsafeSelectors from './no-unsafe-selectors';
22
22
  import noUnsafeValues from './no-unsafe-values';
23
+ import noUnusedCssmapProperties from './no-unused-cssmap-properties';
23
24
  import useCompiled from './use-compiled';
24
25
  export var rules = {
25
26
  'atlaskit-theme': atlaskitTheme,
@@ -38,5 +39,6 @@ export var rules = {
38
39
  'no-styled': noStyled,
39
40
  'no-unsafe-selectors': noUnsafeSelectors,
40
41
  'no-unsafe-values': noUnsafeValues,
42
+ 'no-unused-cssmap-properties': noUnusedCssmapProperties,
41
43
  'use-compiled': useCompiled
42
44
  };
@@ -1,7 +1,6 @@
1
1
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
2
2
  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; } }
3
3
  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; }
4
- import esquery from 'esquery';
5
4
  import { getScope } from '@atlaskit/eslint-utils/context-compat';
6
5
  import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
7
6
  import { importSources } from '@atlaskit/eslint-utils/schema';
@@ -34,42 +33,111 @@ export var rule = createLintRuleWithTypedConfig({
34
33
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
35
34
  return;
36
35
  }
37
- var matches = esquery(node, 'Property');
38
- var _iterator = _createForOfIteratorHelper(matches),
39
- _step;
40
- try {
41
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
- var match = _step.value;
43
- if (match.type !== 'Property') {
44
- return;
45
- }
46
- if (isImportant(match.value)) {
47
- context.report({
48
- node: match.value,
49
- messageId: 'no-important-styles'
50
- });
51
- }
36
+ walkProperties(node, function (propertyNode) {
37
+ if (isImportant(propertyNode.value)) {
38
+ context.report({
39
+ node: propertyNode.value,
40
+ messageId: 'no-important-styles'
41
+ });
52
42
  }
53
- } catch (err) {
54
- _iterator.e(err);
55
- } finally {
56
- _iterator.f();
57
- }
43
+ });
58
44
  }
59
45
  };
60
46
  }
61
47
  });
62
48
  export default rule;
63
- var importantRegex = /!\s*important\s*$/;
49
+ var IMPORTANT_SUFFIX_REGEX = /!\s*important\s*$/;
50
+
51
+ /**
52
+ * Walk through all Property nodes in the AST tree recursively.
53
+ * This is faster than esquery for this specific use case as it avoids
54
+ * selector compilation and executes a simple depth-first traversal.
55
+ */
56
+ function walkProperties(node, callback) {
57
+ var _node$arguments;
58
+ if (node.type === 'Property' && node.value) {
59
+ callback(node);
60
+ }
61
+
62
+ // Iterate through object properties
63
+ if ((_node$arguments = node.arguments) !== null && _node$arguments !== void 0 && _node$arguments.length) {
64
+ var _iterator = _createForOfIteratorHelper(node.arguments),
65
+ _step;
66
+ try {
67
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
68
+ var arg = _step.value;
69
+ if (arg.type === 'ObjectExpression' && arg.properties) {
70
+ var _iterator2 = _createForOfIteratorHelper(arg.properties),
71
+ _step2;
72
+ try {
73
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
74
+ var prop = _step2.value;
75
+ walkObjectProperty(prop, callback);
76
+ }
77
+ } catch (err) {
78
+ _iterator2.e(err);
79
+ } finally {
80
+ _iterator2.f();
81
+ }
82
+ }
83
+ }
84
+ } catch (err) {
85
+ _iterator.e(err);
86
+ } finally {
87
+ _iterator.f();
88
+ }
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Recursively walk object properties to find nested Property nodes.
94
+ */
95
+ function walkObjectProperty(node, callback) {
96
+ if (node.type === 'Property') {
97
+ var _node$value;
98
+ callback(node);
99
+ // Recursively check nested objects
100
+ if (((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'ObjectExpression' && node.value.properties) {
101
+ var _iterator3 = _createForOfIteratorHelper(node.value.properties),
102
+ _step3;
103
+ try {
104
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
105
+ var prop = _step3.value;
106
+ walkObjectProperty(prop, callback);
107
+ }
108
+ } catch (err) {
109
+ _iterator3.e(err);
110
+ } finally {
111
+ _iterator3.f();
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Check if a value contains !important flag.
119
+ * Uses fast string checks before regex to avoid regex overhead for common cases.
120
+ */
64
121
  function isImportant(node) {
65
122
  if (node.type === 'Literal') {
66
- return typeof node.value === 'string' && importantRegex.test(node.value);
123
+ if (typeof node.value !== 'string') {
124
+ return false;
125
+ }
126
+ // Fast check: string must end with 'important' (after optional whitespace)
127
+ var len = node.value.length;
128
+ if (len < 10) {
129
+ return false;
130
+ } // "!important" is 10 chars minimum
131
+ return IMPORTANT_SUFFIX_REGEX.test(node.value);
67
132
  }
68
133
  if (node.type === 'TemplateLiteral') {
69
- var joinedRaw = node.quasis.map(function (element) {
70
- return element.value.raw;
71
- }).join('');
72
- return importantRegex.test(joinedRaw);
134
+ var _node$quasis;
135
+ if (!((_node$quasis = node.quasis) !== null && _node$quasis !== void 0 && _node$quasis.length)) {
136
+ return false;
137
+ }
138
+ // Only check the last quasi's raw value (most likely to contain the !important)
139
+ var lastQuasi = node.quasis[node.quasis.length - 1];
140
+ return IMPORTANT_SUFFIX_REGEX.test(lastQuasi.value.raw);
73
141
  }
74
142
  return false;
75
143
  }
@@ -21,4 +21,51 @@ export var ignoredAtRules = new Set(['@container',
21
21
  // ignored because it's covered by `no-container-queries`
22
22
  '@media',
23
23
  // ignored because it's covered by `no-nested-styles`
24
- '@supports', '@property']);
24
+ '@supports', '@property', '@starting-style']);
25
+
26
+ /**
27
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
28
+ *
29
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
30
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
31
+ *
32
+ * ```typescript
33
+ * // ❌ GROUPED (not allowed for @media):
34
+ * cssMap({
35
+ * variant: {
36
+ * '@media': { // at-rule key with no parameters
37
+ * '(min-width: 900px)': {}, // nested variants
38
+ * '(min-width: 1200px)': {},
39
+ * }
40
+ * }
41
+ * })
42
+ *
43
+ * // ✅ FLAT (preferred for @media):
44
+ * cssMap({
45
+ * variant: {
46
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
47
+ * '@media (min-width: 1200px)': {},
48
+ * }
49
+ * })
50
+ * ```
51
+ *
52
+ * However, some at-rules like `@starting-style` have no parameters and can only be
53
+ * written in the "grouped" form at the variant level:
54
+ *
55
+ * ```typescript
56
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
57
+ * cssMap({
58
+ * fade: {
59
+ * '@starting-style': { // at-rule with no parameters
60
+ * opacity: 0, // styles to apply
61
+ * }
62
+ * }
63
+ * })
64
+ * ```
65
+ *
66
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
67
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
68
+ * `walkStyleRuleset` and are not considered "grouped".
69
+ */
70
+ export var allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
71
+ ]);