@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.
- package/CHANGELOG.md +11 -0
- package/README.md +1 -0
- package/dist/cjs/presets/all-flat.codegen.js +2 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-important-styles/index.js +95 -28
- package/dist/cjs/rules/no-unused-cssmap-properties/index.js +192 -0
- package/dist/es2019/presets/all-flat.codegen.js +2 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-important-styles/index.js +65 -13
- package/dist/es2019/rules/no-unused-cssmap-properties/index.js +182 -0
- package/dist/esm/presets/all-flat.codegen.js +2 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended-flat.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-important-styles/index.js +95 -27
- package/dist/esm/rules/no-unused-cssmap-properties/index.js +186 -0
- package/dist/types/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
- package/dist/types/presets/recommended.codegen.d.ts +1 -1
- package/dist/types/rules/index.codegen.d.ts +1 -1
- package/dist/types/rules/no-unused-cssmap-properties/index.d.ts +3 -0
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unused-cssmap-properties/index.d.ts +3 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`d2b1c5a27d84a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d2b1c5a27d84a) -
|
|
8
|
+
Fix two bugs in the no-unused-cssmap-properties rule:
|
|
9
|
+
- Use getDeclaredVariables() instead of scope-based lookup to properly track references across
|
|
10
|
+
nested scopes
|
|
11
|
+
- Fix isExported false positive by only checking direct export patterns instead of walking full
|
|
12
|
+
parent tree
|
|
13
|
+
|
|
3
14
|
## 1.4.6
|
|
4
15
|
|
|
5
16
|
### 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::
|
|
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::
|
|
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::
|
|
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::
|
|
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::
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
}
|
|
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
|
|
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
|
-
|
|
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
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
}
|
|
@@ -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::
|
|
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::
|
|
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::
|
|
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::
|
|
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::
|
|
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
|
};
|
|
@@ -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
|
-
|
|
37
|
-
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
}
|