@atlaskit/eslint-plugin-ui-styling-standard 1.4.6 → 1.5.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 (36) hide show
  1. package/CHANGELOG.md +11 -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-unused-cssmap-properties/index.js +192 -0
  10. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  11. package/dist/es2019/presets/all.codegen.js +2 -1
  12. package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
  13. package/dist/es2019/presets/recommended.codegen.js +2 -1
  14. package/dist/es2019/rules/index.codegen.js +3 -1
  15. package/dist/es2019/rules/no-important-styles/index.js +65 -13
  16. package/dist/es2019/rules/no-unused-cssmap-properties/index.js +182 -0
  17. package/dist/esm/presets/all-flat.codegen.js +2 -1
  18. package/dist/esm/presets/all.codegen.js +2 -1
  19. package/dist/esm/presets/recommended-flat.codegen.js +2 -1
  20. package/dist/esm/presets/recommended.codegen.js +2 -1
  21. package/dist/esm/rules/index.codegen.js +3 -1
  22. package/dist/esm/rules/no-important-styles/index.js +95 -27
  23. package/dist/esm/rules/no-unused-cssmap-properties/index.js +186 -0
  24. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  25. package/dist/types/presets/all.codegen.d.ts +1 -1
  26. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
  27. package/dist/types/presets/recommended.codegen.d.ts +1 -1
  28. package/dist/types/rules/index.codegen.d.ts +1 -1
  29. package/dist/types/rules/no-unused-cssmap-properties/index.d.ts +3 -0
  30. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
  31. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  32. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -1
  33. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
  34. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  35. package/dist/types-ts4.5/rules/no-unused-cssmap-properties/index.d.ts +3 -0
  36. package/package.json +2 -2
@@ -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
  }
@@ -0,0 +1,186 @@
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
+ var 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
+ var 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
+ var 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
+ var scope = getScope(context, node);
42
+ var variableName = node.id.name;
43
+ var variable = scope.variables.find(function (v) {
44
+ return v.name === variableName;
45
+ });
46
+ if (variable) {
47
+ // Check if any reference is a direct export specifier (e.g., `export { styles }`)
48
+ return variable.references.some(function (ref) {
49
+ var refParent = ref.identifier.parent;
50
+ // Check for direct export: `export { styles }` or `export { styles as something }`
51
+ // In this case, the identifier's parent is an ExportSpecifier
52
+ if (refParent && refParent.type === 'ExportSpecifier') {
53
+ return true;
54
+ }
55
+ // Check for default export: `export default styles`
56
+ if (refParent && refParent.type === 'ExportDefaultDeclaration') {
57
+ return true;
58
+ }
59
+ return false;
60
+ });
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+ export var rule = createLintRule({
66
+ meta: {
67
+ name: 'no-unused-cssmap-properties',
68
+ docs: {
69
+ 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.',
70
+ recommended: true,
71
+ severity: 'warn'
72
+ },
73
+ messages: {
74
+ 'unused-property': 'The "{{propertyName}}" style is defined but never used.'
75
+ },
76
+ type: 'problem'
77
+ },
78
+ create: function create(context) {
79
+ return {
80
+ VariableDeclarator: function VariableDeclarator(node) {
81
+ var _getSourceCode$scopeM;
82
+ if (node.type !== 'VariableDeclarator') {
83
+ return;
84
+ }
85
+
86
+ // Only process if the initializer is a cssMap call
87
+ if (!node.init || node.init.type !== 'CallExpression' || !isCssMap(node.init.callee, getScope(context, node).references, IMPORT_SOURCES)) {
88
+ return;
89
+ }
90
+
91
+ // Skip if the cssMap is exported
92
+ if (isExported(node, context)) {
93
+ return;
94
+ }
95
+
96
+ // Get the cssMap argument (should be an object expression)
97
+ var cssMapArg = node.init.arguments[0];
98
+ if (!cssMapArg || cssMapArg.type !== 'ObjectExpression') {
99
+ return;
100
+ }
101
+
102
+ // Get the variable name
103
+ if (node.id.type !== 'Identifier') {
104
+ return;
105
+ }
106
+ var variableName = node.id.name;
107
+
108
+ // Use getDeclaredVariables to get the variable with all its references
109
+ // across all scopes (including nested function components)
110
+ var declaredVariables = (_getSourceCode$scopeM = getSourceCode(context).scopeManager) === null || _getSourceCode$scopeM === void 0 ? void 0 : _getSourceCode$scopeM.getDeclaredVariables(node);
111
+ var variable = declaredVariables === null || declaredVariables === void 0 ? void 0 : declaredVariables.find(function (v) {
112
+ return v.name === variableName;
113
+ });
114
+ if (!variable) {
115
+ return;
116
+ }
117
+
118
+ // Track which properties are defined
119
+ var definedProperties = new Set();
120
+ cssMapArg.properties.forEach(function (prop) {
121
+ if (prop.type === 'Property') {
122
+ var keyName = getPropertyKeyName(prop);
123
+ if (keyName) {
124
+ definedProperties.add(keyName);
125
+ }
126
+ }
127
+ });
128
+
129
+ // Track which properties are used
130
+ var usedProperties = new Set();
131
+ var hasNonPropertyAccess = false;
132
+ variable.references.forEach(function (reference) {
133
+ // Skip the declaration itself
134
+ if (reference.init) {
135
+ return;
136
+ }
137
+ var identifier = reference.identifier;
138
+ var parent = identifier.parent;
139
+
140
+ // Check if it's a member access (e.g., styles.root)
141
+ if (parent && parent.type === 'MemberExpression' && parent.object === identifier) {
142
+ // Check if it's computed (dynamic) property access like styles[dynamicKey]
143
+ if (parent.computed) {
144
+ // Dynamic access - we can't determine which properties are used
145
+ hasNonPropertyAccess = true;
146
+ return;
147
+ }
148
+
149
+ // Static property access
150
+ if (parent.property.type === 'Identifier') {
151
+ usedProperties.add(parent.property.name);
152
+ } else if (parent.property.type === 'Literal' && typeof parent.property.value === 'string') {
153
+ usedProperties.add(parent.property.value);
154
+ }
155
+ } else {
156
+ // The cssMap object is used as a whole (e.g., spread, passed to function, etc.)
157
+ // In this case, we can't determine which properties are used, so mark all as used
158
+ hasNonPropertyAccess = true;
159
+ }
160
+ });
161
+
162
+ // If the object is used as a whole (not just property access), skip checks
163
+ if (hasNonPropertyAccess) {
164
+ return;
165
+ }
166
+
167
+ // Report unused properties
168
+ cssMapArg.properties.forEach(function (prop) {
169
+ if (prop.type === 'Property') {
170
+ var keyName = getPropertyKeyName(prop);
171
+ if (keyName && !usedProperties.has(keyName)) {
172
+ context.report({
173
+ node: prop.key,
174
+ messageId: 'unused-property',
175
+ data: {
176
+ propertyName: keyName
177
+ }
178
+ });
179
+ }
180
+ }
181
+ });
182
+ }
183
+ };
184
+ }
185
+ });
186
+ 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
  import type { Linter } from 'eslint';
@@ -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
  import type { ESLint } from 'eslint';
@@ -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
  import type { Linter } from 'eslint';
@@ -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
  import type { ESLint } from 'eslint';
@@ -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
  import type { Rule } from 'eslint';
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const rule: Rule.RuleModule;
3
+ 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
  import type { Linter } from 'eslint';
@@ -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
  import type { ESLint } from 'eslint';