@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ceba2f0da51d4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ceba2f0da51d4) -
8
+ Add @starting-style to ESLint ignoredAtRules to allow usage without eslint-disable comments
9
+
10
+ ## 1.5.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`d2b1c5a27d84a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d2b1c5a27d84a) -
15
+ Fix two bugs in the no-unused-cssmap-properties rule:
16
+ - Use getDeclaredVariables() instead of scope-based lookup to properly track references across
17
+ nested scopes
18
+ - Fix isExported false positive by only checking direct export patterns instead of walking full
19
+ parent tree
20
+
3
21
  ## 1.4.6
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -58,6 +58,7 @@ module.exports = {
58
58
  | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
59
59
  | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
60
60
  | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
61
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unused-cssmap-properties/README.md">no-unused-cssmap-properties</a> | 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. | Yes | | |
61
62
  | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries | Yes | Yes | |
62
63
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
63
64
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
@@ -9,7 +9,7 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
9
9
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
10
  /**
11
11
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
12
- * @codegen <<SignedSource::a031ffa483e224bf49a4e9eec39acb69>>
12
+ * @codegen <<SignedSource::f99588f71d6b353cefbed97fd172e433>>
13
13
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
14
14
  */
15
15
 
@@ -35,6 +35,7 @@ var config = {
35
35
  '@atlaskit/ui-styling-standard/no-styled': 'error',
36
36
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
37
37
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
38
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
38
39
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
39
40
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
40
41
  excludeReactComponents: true,
@@ -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::778759f32da9fc9b6d182dba1b796640>>
9
+ * @codegen <<SignedSource::8f28dfef84548edbe33f59201f295cc5>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
 
@@ -29,6 +29,7 @@ var config = {
29
29
  '@atlaskit/ui-styling-standard/no-styled': 'error',
30
30
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
31
31
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
32
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
32
33
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
33
34
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
34
35
  excludeReactComponents: true,
@@ -9,7 +9,7 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
9
9
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
10
  /**
11
11
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
12
- * @codegen <<SignedSource::a031ffa483e224bf49a4e9eec39acb69>>
12
+ * @codegen <<SignedSource::f99588f71d6b353cefbed97fd172e433>>
13
13
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
14
14
  */
15
15
 
@@ -35,6 +35,7 @@ var config = {
35
35
  '@atlaskit/ui-styling-standard/no-styled': 'error',
36
36
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
37
37
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
38
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
38
39
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
39
40
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
40
41
  excludeReactComponents: true,
@@ -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::778759f32da9fc9b6d182dba1b796640>>
9
+ * @codegen <<SignedSource::8f28dfef84548edbe33f59201f295cc5>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
 
@@ -29,6 +29,7 @@ var config = {
29
29
  '@atlaskit/ui-styling-standard/no-styled': 'error',
30
30
  '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
31
31
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
32
+ '@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
32
33
  '@atlaskit/ui-styling-standard/use-compiled': 'error',
33
34
  '@atlaskit/design-system/consistent-css-prop-usage': ['error', {
34
35
  excludeReactComponents: true,
@@ -21,10 +21,11 @@ var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors")
21
21
  var _noStyled = _interopRequireDefault(require("./no-styled"));
22
22
  var _noUnsafeSelectors = _interopRequireDefault(require("./no-unsafe-selectors"));
23
23
  var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
24
+ var _noUnusedCssmapProperties = _interopRequireDefault(require("./no-unused-cssmap-properties"));
24
25
  var _useCompiled = _interopRequireDefault(require("./use-compiled"));
25
26
  /**
26
27
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
27
- * @codegen <<SignedSource::34a66bfc786bfa49ea7d4ad66ffe81f7>>
28
+ * @codegen <<SignedSource::2eab912b0c44d0fcbdc2f0b79cb42fa9>>
28
29
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
29
30
  */
30
31
 
@@ -45,5 +46,6 @@ var rules = exports.rules = {
45
46
  'no-styled': _noStyled.default,
46
47
  'no-unsafe-selectors': _noUnsafeSelectors.default,
47
48
  'no-unsafe-values': _noUnsafeValues.default,
49
+ 'no-unused-cssmap-properties': _noUnusedCssmapProperties.default,
48
50
  'use-compiled': _useCompiled.default
49
51
  };
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.rule = exports.default = void 0;
8
- var _esquery = _interopRequireDefault(require("esquery"));
9
7
  var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
10
8
  var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
11
9
  var _schema = require("@atlaskit/eslint-utils/schema");
@@ -41,42 +39,111 @@ var rule = exports.rule = (0, _createRuleWithTypedConfig.createLintRuleWithTyped
41
39
  if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
42
40
  return;
43
41
  }
44
- var matches = (0, _esquery.default)(node, 'Property');
45
- var _iterator = _createForOfIteratorHelper(matches),
46
- _step;
47
- try {
48
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
- var match = _step.value;
50
- if (match.type !== 'Property') {
51
- return;
52
- }
53
- if (isImportant(match.value)) {
54
- context.report({
55
- node: match.value,
56
- messageId: 'no-important-styles'
57
- });
58
- }
42
+ walkProperties(node, function (propertyNode) {
43
+ if (isImportant(propertyNode.value)) {
44
+ context.report({
45
+ node: propertyNode.value,
46
+ messageId: 'no-important-styles'
47
+ });
59
48
  }
60
- } catch (err) {
61
- _iterator.e(err);
62
- } finally {
63
- _iterator.f();
64
- }
49
+ });
65
50
  }
66
51
  };
67
52
  }
68
53
  });
69
54
  var _default = exports.default = rule;
70
- var importantRegex = /!\s*important\s*$/;
55
+ var IMPORTANT_SUFFIX_REGEX = /!\s*important\s*$/;
56
+
57
+ /**
58
+ * Walk through all Property nodes in the AST tree recursively.
59
+ * This is faster than esquery for this specific use case as it avoids
60
+ * selector compilation and executes a simple depth-first traversal.
61
+ */
62
+ function walkProperties(node, callback) {
63
+ var _node$arguments;
64
+ if (node.type === 'Property' && node.value) {
65
+ callback(node);
66
+ }
67
+
68
+ // Iterate through object properties
69
+ if ((_node$arguments = node.arguments) !== null && _node$arguments !== void 0 && _node$arguments.length) {
70
+ var _iterator = _createForOfIteratorHelper(node.arguments),
71
+ _step;
72
+ try {
73
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
74
+ var arg = _step.value;
75
+ if (arg.type === 'ObjectExpression' && arg.properties) {
76
+ var _iterator2 = _createForOfIteratorHelper(arg.properties),
77
+ _step2;
78
+ try {
79
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
80
+ var prop = _step2.value;
81
+ walkObjectProperty(prop, callback);
82
+ }
83
+ } catch (err) {
84
+ _iterator2.e(err);
85
+ } finally {
86
+ _iterator2.f();
87
+ }
88
+ }
89
+ }
90
+ } catch (err) {
91
+ _iterator.e(err);
92
+ } finally {
93
+ _iterator.f();
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Recursively walk object properties to find nested Property nodes.
100
+ */
101
+ function walkObjectProperty(node, callback) {
102
+ if (node.type === 'Property') {
103
+ var _node$value;
104
+ callback(node);
105
+ // Recursively check nested objects
106
+ if (((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'ObjectExpression' && node.value.properties) {
107
+ var _iterator3 = _createForOfIteratorHelper(node.value.properties),
108
+ _step3;
109
+ try {
110
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
111
+ var prop = _step3.value;
112
+ walkObjectProperty(prop, callback);
113
+ }
114
+ } catch (err) {
115
+ _iterator3.e(err);
116
+ } finally {
117
+ _iterator3.f();
118
+ }
119
+ }
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Check if a value contains !important flag.
125
+ * Uses fast string checks before regex to avoid regex overhead for common cases.
126
+ */
71
127
  function isImportant(node) {
72
128
  if (node.type === 'Literal') {
73
- return typeof node.value === 'string' && importantRegex.test(node.value);
129
+ if (typeof node.value !== 'string') {
130
+ return false;
131
+ }
132
+ // Fast check: string must end with 'important' (after optional whitespace)
133
+ var len = node.value.length;
134
+ if (len < 10) {
135
+ return false;
136
+ } // "!important" is 10 chars minimum
137
+ return IMPORTANT_SUFFIX_REGEX.test(node.value);
74
138
  }
75
139
  if (node.type === 'TemplateLiteral') {
76
- var joinedRaw = node.quasis.map(function (element) {
77
- return element.value.raw;
78
- }).join('');
79
- return importantRegex.test(joinedRaw);
140
+ var _node$quasis;
141
+ if (!((_node$quasis = node.quasis) !== null && _node$quasis !== void 0 && _node$quasis.length)) {
142
+ return false;
143
+ }
144
+ // Only check the last quasi's raw value (most likely to contain the !important)
145
+ var lastQuasi = node.quasis[node.quasis.length - 1];
146
+ return IMPORTANT_SUFFIX_REGEX.test(lastQuasi.value.raw);
80
147
  }
81
148
  return false;
82
149
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.legacyPseudoElements = exports.ignoredAtRules = exports.allowedPseudos = void 0;
6
+ exports.legacyPseudoElements = exports.ignoredAtRules = exports.allowedPseudos = exports.allowedGroupedAtRules = void 0;
7
7
  /**
8
8
  * Validation approach from
9
9
  * https://stackoverflow.com/a/71236280
@@ -27,4 +27,51 @@ var ignoredAtRules = exports.ignoredAtRules = new Set(['@container',
27
27
  // ignored because it's covered by `no-container-queries`
28
28
  '@media',
29
29
  // ignored because it's covered by `no-nested-styles`
30
- '@supports', '@property']);
30
+ '@supports', '@property', '@starting-style']);
31
+
32
+ /**
33
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
34
+ *
35
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
36
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
37
+ *
38
+ * ```typescript
39
+ * // ❌ GROUPED (not allowed for @media):
40
+ * cssMap({
41
+ * variant: {
42
+ * '@media': { // at-rule key with no parameters
43
+ * '(min-width: 900px)': {}, // nested variants
44
+ * '(min-width: 1200px)': {},
45
+ * }
46
+ * }
47
+ * })
48
+ *
49
+ * // ✅ FLAT (preferred for @media):
50
+ * cssMap({
51
+ * variant: {
52
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
53
+ * '@media (min-width: 1200px)': {},
54
+ * }
55
+ * })
56
+ * ```
57
+ *
58
+ * However, some at-rules like `@starting-style` have no parameters and can only be
59
+ * written in the "grouped" form at the variant level:
60
+ *
61
+ * ```typescript
62
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
63
+ * cssMap({
64
+ * fade: {
65
+ * '@starting-style': { // at-rule with no parameters
66
+ * opacity: 0, // styles to apply
67
+ * }
68
+ * }
69
+ * })
70
+ * ```
71
+ *
72
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
73
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
74
+ * `walkStyleRuleset` and are not considered "grouped".
75
+ */
76
+ var allowedGroupedAtRules = exports.allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
77
+ ]);
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.walkCssMap = walkCssMap;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
10
+ var _constants = require("./constants");
10
11
  /**
11
12
  * This util is intentionally not in `@atlaskit/eslint-utils` at this time.
12
13
  *
@@ -110,11 +111,15 @@ function walkCssMapAtRuleGrouping(_ref4) {
110
111
  if (!atRule) {
111
112
  return;
112
113
  }
113
- visitor({
114
- type: 'grouped-at-rules',
115
- node: atRuleGrouping,
116
- atRule: atRule
117
- });
114
+
115
+ // Skip reporting if the at-rule is allowed to be grouped
116
+ if (!_constants.allowedGroupedAtRules.has(atRule)) {
117
+ visitor({
118
+ type: 'grouped-at-rules',
119
+ node: atRuleGrouping,
120
+ atRule: atRule
121
+ });
122
+ }
118
123
  if (atRuleGrouping.value.type !== 'ObjectExpression') {
119
124
  return;
120
125
  }
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rule = exports.default = void 0;
7
+ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
8
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
9
+ var _createRule = require("../utils/create-rule");
10
+ var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss];
11
+
12
+ /**
13
+ * Gets the key name from a property node
14
+ */
15
+ function getPropertyKeyName(property) {
16
+ if (property.key.type === 'Identifier') {
17
+ return property.key.name;
18
+ }
19
+ if (property.key.type === 'Literal' && typeof property.key.value === 'string') {
20
+ return property.key.value;
21
+ }
22
+ return null;
23
+ }
24
+
25
+ /**
26
+ * Checks if a variable is exported from the module
27
+ */
28
+ function isExported(node, context) {
29
+ var parent = node.parent;
30
+
31
+ // Walk up to find VariableDeclaration
32
+ while (parent && parent.type !== 'VariableDeclaration') {
33
+ parent = parent.parent;
34
+ }
35
+ if (!parent) {
36
+ return false;
37
+ }
38
+
39
+ // Check if the VariableDeclaration is an ExportNamedDeclaration
40
+ var grandParent = parent.parent;
41
+ if (grandParent && grandParent.type === 'ExportNamedDeclaration') {
42
+ return true;
43
+ }
44
+
45
+ // Check if the variable is exported elsewhere in the file via `export { styles }`
46
+ if (node.id.type === 'Identifier') {
47
+ var scope = (0, _contextCompat.getScope)(context, node);
48
+ var variableName = node.id.name;
49
+ var variable = scope.variables.find(function (v) {
50
+ return v.name === variableName;
51
+ });
52
+ if (variable) {
53
+ // Check if any reference is a direct export specifier (e.g., `export { styles }`)
54
+ return variable.references.some(function (ref) {
55
+ var refParent = ref.identifier.parent;
56
+ // Check for direct export: `export { styles }` or `export { styles as something }`
57
+ // In this case, the identifier's parent is an ExportSpecifier
58
+ if (refParent && refParent.type === 'ExportSpecifier') {
59
+ return true;
60
+ }
61
+ // Check for default export: `export default styles`
62
+ if (refParent && refParent.type === 'ExportDefaultDeclaration') {
63
+ return true;
64
+ }
65
+ return false;
66
+ });
67
+ }
68
+ }
69
+ return false;
70
+ }
71
+ var rule = exports.rule = (0, _createRule.createLintRule)({
72
+ meta: {
73
+ name: 'no-unused-cssmap-properties',
74
+ docs: {
75
+ 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.',
76
+ recommended: true,
77
+ severity: 'warn'
78
+ },
79
+ messages: {
80
+ 'unused-property': 'The "{{propertyName}}" style is defined but never used.'
81
+ },
82
+ type: 'problem'
83
+ },
84
+ create: function create(context) {
85
+ return {
86
+ VariableDeclarator: function VariableDeclarator(node) {
87
+ var _getSourceCode$scopeM;
88
+ if (node.type !== 'VariableDeclarator') {
89
+ return;
90
+ }
91
+
92
+ // Only process if the initializer is a cssMap call
93
+ if (!node.init || node.init.type !== 'CallExpression' || !(0, _isSupportedImport.isCssMap)(node.init.callee, (0, _contextCompat.getScope)(context, node).references, IMPORT_SOURCES)) {
94
+ return;
95
+ }
96
+
97
+ // Skip if the cssMap is exported
98
+ if (isExported(node, context)) {
99
+ return;
100
+ }
101
+
102
+ // Get the cssMap argument (should be an object expression)
103
+ var cssMapArg = node.init.arguments[0];
104
+ if (!cssMapArg || cssMapArg.type !== 'ObjectExpression') {
105
+ return;
106
+ }
107
+
108
+ // Get the variable name
109
+ if (node.id.type !== 'Identifier') {
110
+ return;
111
+ }
112
+ var variableName = node.id.name;
113
+
114
+ // Use getDeclaredVariables to get the variable with all its references
115
+ // across all scopes (including nested function components)
116
+ var declaredVariables = (_getSourceCode$scopeM = (0, _contextCompat.getSourceCode)(context).scopeManager) === null || _getSourceCode$scopeM === void 0 ? void 0 : _getSourceCode$scopeM.getDeclaredVariables(node);
117
+ var variable = declaredVariables === null || declaredVariables === void 0 ? void 0 : declaredVariables.find(function (v) {
118
+ return v.name === variableName;
119
+ });
120
+ if (!variable) {
121
+ return;
122
+ }
123
+
124
+ // Track which properties are defined
125
+ var definedProperties = new Set();
126
+ cssMapArg.properties.forEach(function (prop) {
127
+ if (prop.type === 'Property') {
128
+ var keyName = getPropertyKeyName(prop);
129
+ if (keyName) {
130
+ definedProperties.add(keyName);
131
+ }
132
+ }
133
+ });
134
+
135
+ // Track which properties are used
136
+ var usedProperties = new Set();
137
+ var hasNonPropertyAccess = false;
138
+ variable.references.forEach(function (reference) {
139
+ // Skip the declaration itself
140
+ if (reference.init) {
141
+ return;
142
+ }
143
+ var identifier = reference.identifier;
144
+ var parent = identifier.parent;
145
+
146
+ // Check if it's a member access (e.g., styles.root)
147
+ if (parent && parent.type === 'MemberExpression' && parent.object === identifier) {
148
+ // Check if it's computed (dynamic) property access like styles[dynamicKey]
149
+ if (parent.computed) {
150
+ // Dynamic access - we can't determine which properties are used
151
+ hasNonPropertyAccess = true;
152
+ return;
153
+ }
154
+
155
+ // Static property access
156
+ if (parent.property.type === 'Identifier') {
157
+ usedProperties.add(parent.property.name);
158
+ } else if (parent.property.type === 'Literal' && typeof parent.property.value === 'string') {
159
+ usedProperties.add(parent.property.value);
160
+ }
161
+ } else {
162
+ // The cssMap object is used as a whole (e.g., spread, passed to function, etc.)
163
+ // In this case, we can't determine which properties are used, so mark all as used
164
+ hasNonPropertyAccess = true;
165
+ }
166
+ });
167
+
168
+ // If the object is used as a whole (not just property access), skip checks
169
+ if (hasNonPropertyAccess) {
170
+ return;
171
+ }
172
+
173
+ // Report unused properties
174
+ cssMapArg.properties.forEach(function (prop) {
175
+ if (prop.type === 'Property') {
176
+ var keyName = getPropertyKeyName(prop);
177
+ if (keyName && !usedProperties.has(keyName)) {
178
+ context.report({
179
+ node: prop.key,
180
+ messageId: 'unused-property',
181
+ data: {
182
+ propertyName: keyName
183
+ }
184
+ });
185
+ }
186
+ }
187
+ });
188
+ }
189
+ };
190
+ }
191
+ });
192
+ var _default = exports.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 @@ const 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 @@ const 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 @@ const 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 @@ const 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 const rules = {
25
26
  'atlaskit-theme': atlaskitTheme,
@@ -38,5 +39,6 @@ export const 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
  };