@atlaskit/eslint-plugin-ui-styling-standard 1.4.5 → 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 (49) hide show
  1. package/CHANGELOG.md +18 -5
  2. package/README.md +1 -0
  3. package/dist/cjs/index.codegen.js +3 -3
  4. package/dist/cjs/presets/all-flat.codegen.js +6 -3
  5. package/dist/cjs/presets/all.codegen.js +6 -3
  6. package/dist/cjs/presets/recommended-flat.codegen.js +6 -3
  7. package/dist/cjs/presets/recommended.codegen.js +6 -3
  8. package/dist/cjs/rules/index.codegen.js +3 -1
  9. package/dist/cjs/rules/no-important-styles/index.js +95 -28
  10. package/dist/cjs/rules/no-unsafe-selectors/index.js +1 -1
  11. package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +1 -1
  12. package/dist/cjs/rules/no-unused-cssmap-properties/index.js +192 -0
  13. package/dist/es2019/index.codegen.js +4 -5
  14. package/dist/es2019/presets/all-flat.codegen.js +6 -3
  15. package/dist/es2019/presets/all.codegen.js +6 -3
  16. package/dist/es2019/presets/recommended-flat.codegen.js +6 -3
  17. package/dist/es2019/presets/recommended.codegen.js +6 -3
  18. package/dist/es2019/rules/index.codegen.js +4 -1
  19. package/dist/es2019/rules/no-important-styles/index.js +65 -13
  20. package/dist/es2019/rules/no-unsafe-selectors/index.js +1 -1
  21. package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +1 -1
  22. package/dist/es2019/rules/no-unused-cssmap-properties/index.js +182 -0
  23. package/dist/esm/index.codegen.js +4 -4
  24. package/dist/esm/presets/all-flat.codegen.js +6 -3
  25. package/dist/esm/presets/all.codegen.js +6 -3
  26. package/dist/esm/presets/recommended-flat.codegen.js +6 -3
  27. package/dist/esm/presets/recommended.codegen.js +6 -3
  28. package/dist/esm/rules/index.codegen.js +4 -1
  29. package/dist/esm/rules/no-important-styles/index.js +95 -27
  30. package/dist/esm/rules/no-unsafe-selectors/index.js +1 -1
  31. package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +1 -1
  32. package/dist/esm/rules/no-unused-cssmap-properties/index.js +186 -0
  33. package/dist/types/index.codegen.d.ts +9 -718
  34. package/dist/types/presets/all-flat.codegen.d.ts +4 -40
  35. package/dist/types/presets/all.codegen.d.ts +4 -37
  36. package/dist/types/presets/recommended-flat.codegen.d.ts +4 -40
  37. package/dist/types/presets/recommended.codegen.d.ts +4 -37
  38. package/dist/types/rules/index.codegen.d.ts +7 -19
  39. package/dist/types/rules/no-unused-cssmap-properties/index.d.ts +3 -0
  40. package/dist/types/rules/utils/create-rule.d.ts +3 -1
  41. package/dist/types-ts4.5/index.codegen.d.ts +9 -1078
  42. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +4 -61
  43. package/dist/types-ts4.5/presets/all.codegen.d.ts +4 -61
  44. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +4 -61
  45. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +4 -61
  46. package/dist/types-ts4.5/rules/index.codegen.d.ts +7 -19
  47. package/dist/types-ts4.5/rules/no-unused-cssmap-properties/index.d.ts +3 -0
  48. package/dist/types-ts4.5/rules/utils/create-rule.d.ts +3 -1
  49. package/package.json +3 -7
@@ -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
  }
@@ -130,7 +130,7 @@ var rule = createLintRuleWithTypedConfig({
130
130
  isXcssCall: isXcssCall
131
131
  });
132
132
  });
133
- } catch (e) {
133
+ } catch (_unused) {
134
134
  context.report({
135
135
  node: key,
136
136
  messageId: 'no-unparsable-selectors',
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { allowedPseudos, legacyPseudoElements } from './constants';
4
3
  import { isNesting } from 'postcss-selector-parser';
4
+ import { allowedPseudos, legacyPseudoElements } from './constants';
5
5
  import { getRangeFromNode, getSourceLocationFromRange } from './source-position-utils';
6
6
  export function lintSelector(args) {
7
7
  checkNoAmbiguousPseudos(args);
@@ -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;