@atlaskit/eslint-plugin-design-system 13.18.0 → 13.19.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 +17 -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-unused-css-map/index.js +51 -0
- package/dist/cjs/rules/no-unused-css-map/utils.js +162 -0
- package/dist/cjs/rules/use-correct-field/index.js +19 -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-unused-css-map/index.js +44 -0
- package/dist/es2019/rules/no-unused-css-map/utils.js +101 -0
- package/dist/es2019/rules/use-correct-field/index.js +7 -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-unused-css-map/index.js +45 -0
- package/dist/esm/rules/no-unused-css-map/utils.js +155 -0
- package/dist/esm/rules/use-correct-field/index.js +19 -0
- package/dist/types/index.codegen.d.ts +9 -0
- package/dist/types/presets/all-flat.codegen.d.ts +1 -0
- package/dist/types/presets/all.codegen.d.ts +1 -0
- package/dist/types/presets/recommended-flat.codegen.d.ts +1 -0
- package/dist/types/presets/recommended.codegen.d.ts +1 -0
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-unused-css-map/index.d.ts +3 -0
- package/dist/types/rules/no-unused-css-map/utils.d.ts +15 -0
- package/dist/types-ts4.5/index.codegen.d.ts +9 -0
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -0
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-unused-css-map/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-unused-css-map/utils.d.ts +15 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 13.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#187495](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/187495)
|
|
8
|
+
[`8c0b4fd35134d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8c0b4fd35134d) -
|
|
9
|
+
Introduces new ESLint rule to identify unused variables in cssMap.
|
|
10
|
+
|
|
11
|
+
## 13.18.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#188850](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/188850)
|
|
16
|
+
[`8b19a85abe51e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8b19a85abe51e) -
|
|
17
|
+
Add nmore cases to the new use correct field rule.
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 13.18.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ module.exports = {
|
|
|
91
91
|
| <a href="./packages/design-system/eslint-plugin/src/rules/no-unsafe-design-token-usage/README.md">no-unsafe-design-token-usage</a> | Enforces design token usage is statically and locally analyzable. | Yes | Yes | |
|
|
92
92
|
| <a href="./packages/design-system/eslint-plugin/src/rules/no-unsafe-style-overrides/README.md">no-unsafe-style-overrides</a> | Discourage usage of unsafe style overrides used against the Atlassian Design System. | Yes | | |
|
|
93
93
|
| <a href="./packages/design-system/eslint-plugin/src/rules/no-unsupported-drag-and-drop-libraries/README.md">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
|
|
94
|
+
| <a href="./packages/design-system/eslint-plugin/src/rules/no-unused-css-map/README.md">no-unused-css-map</a> | Detects unused styles in cssMap objects to help keep code clean. | Yes | | |
|
|
94
95
|
| <a href="./packages/design-system/eslint-plugin/src/rules/no-utility-icons/README.md">no-utility-icons</a> | Disallow use of deprecated utility icons, in favor of core icons with `size="small"`. | Yes | Yes | Yes |
|
|
95
96
|
| <a href="./packages/design-system/eslint-plugin/src/rules/prefer-primitives/README.md">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
|
|
96
97
|
| <a href="./packages/design-system/eslint-plugin/src/rules/use-button-group-label/README.md">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
|
|
@@ -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::e075ab709ebd382d6f5e39fd78de9d6d>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -54,6 +54,7 @@ var _default = exports.default = {
|
|
|
54
54
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
55
55
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
56
56
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
57
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
57
58
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
58
59
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
59
60
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
@@ -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::d78f5649534c2e153e3ce48063649a8a>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -53,6 +53,7 @@ var _default = exports.default = {
|
|
|
53
53
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
54
54
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
55
55
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
56
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
56
57
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
57
58
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
58
59
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
@@ -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::310988af3dc2559509bf99f2110134b8>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -41,6 +41,7 @@ var _default = exports.default = {
|
|
|
41
41
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
42
42
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
43
43
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
44
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
44
45
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
45
46
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
46
47
|
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
@@ -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::ce9d9b39fba8bb67d218e48398271109>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -40,6 +40,7 @@ var _default = exports.default = {
|
|
|
40
40
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
41
41
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
42
42
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
43
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
43
44
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
44
45
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
45
46
|
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
@@ -47,6 +47,7 @@ var _noStyledTaggedTemplateExpression = _interopRequireDefault(require("./no-sty
|
|
|
47
47
|
var _noUnsafeDesignTokenUsage = _interopRequireDefault(require("./no-unsafe-design-token-usage"));
|
|
48
48
|
var _noUnsafeStyleOverrides = _interopRequireDefault(require("./no-unsafe-style-overrides"));
|
|
49
49
|
var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-unsupported-drag-and-drop-libraries"));
|
|
50
|
+
var _noUnusedCssMap = _interopRequireDefault(require("./no-unused-css-map"));
|
|
50
51
|
var _noUtilityIcons = _interopRequireDefault(require("./no-utility-icons"));
|
|
51
52
|
var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
|
|
52
53
|
var _useButtonGroupLabel = _interopRequireDefault(require("./use-button-group-label"));
|
|
@@ -72,7 +73,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
|
|
|
72
73
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
73
74
|
/**
|
|
74
75
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
75
|
-
* @codegen <<SignedSource::
|
|
76
|
+
* @codegen <<SignedSource::53ad66d79f989ce9beb46ee0186685b2>>
|
|
76
77
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
77
78
|
*/
|
|
78
79
|
|
|
@@ -119,6 +120,7 @@ var rules = exports.rules = {
|
|
|
119
120
|
'no-unsafe-design-token-usage': _noUnsafeDesignTokenUsage.default,
|
|
120
121
|
'no-unsafe-style-overrides': _noUnsafeStyleOverrides.default,
|
|
121
122
|
'no-unsupported-drag-and-drop-libraries': _noUnsupportedDragAndDropLibraries.default,
|
|
123
|
+
'no-unused-css-map': _noUnusedCssMap.default,
|
|
122
124
|
'no-utility-icons': _noUtilityIcons.default,
|
|
123
125
|
'prefer-primitives': _preferPrimitives.default,
|
|
124
126
|
'use-button-group-label': _useButtonGroupLabel.default,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
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 _utils = require("./utils");
|
|
11
|
+
var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
12
|
+
var createUnusedCssMapRule = function createUnusedCssMapRule(context) {
|
|
13
|
+
var _getSourceCode = (0, _contextCompat.getSourceCode)(context),
|
|
14
|
+
text = _getSourceCode.text;
|
|
15
|
+
if (IMPORT_SOURCES.every(function (importSource) {
|
|
16
|
+
return !text.includes(importSource);
|
|
17
|
+
})) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
CallExpression: function CallExpression(node) {
|
|
22
|
+
var references = (0, _contextCompat.getScope)(context, node).references;
|
|
23
|
+
if (!(0, _isSupportedImport.isCssMap)(node.callee, references, IMPORT_SOURCES)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var cssMapObject = (0, _utils.getCssMapObject)(node);
|
|
27
|
+
if (!cssMapObject) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var unusedCssMapChecker = new _utils.UnusedCssMapChecker(cssMapObject, context, node);
|
|
31
|
+
unusedCssMapChecker.run();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
var noUnusedCssMapRule = (0, _createRule.createLintRule)({
|
|
36
|
+
meta: {
|
|
37
|
+
name: 'no-unused-css-map',
|
|
38
|
+
docs: {
|
|
39
|
+
description: 'Detects unused styles in cssMap objects to help keep code clean.',
|
|
40
|
+
recommended: true,
|
|
41
|
+
severity: 'warn'
|
|
42
|
+
},
|
|
43
|
+
messages: {
|
|
44
|
+
unusedCssMapStyle: 'Unused style "{{styleName}}" in cssMap. Consider removing it if not needed.'
|
|
45
|
+
},
|
|
46
|
+
schema: [],
|
|
47
|
+
type: 'suggestion'
|
|
48
|
+
},
|
|
49
|
+
create: createUnusedCssMapRule
|
|
50
|
+
});
|
|
51
|
+
var _default = exports.default = noUnusedCssMapRule;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getCssMapObject = exports.UnusedCssMapChecker = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
12
|
+
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
13
|
+
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; } } }; }
|
|
14
|
+
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; } }
|
|
15
|
+
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; }
|
|
16
|
+
var getCssMapObject = exports.getCssMapObject = function getCssMapObject(node) {
|
|
17
|
+
// We assume the argument `node` is already a cssMap() call.
|
|
18
|
+
|
|
19
|
+
// Things like the number of arguments to cssMap and the type of
|
|
20
|
+
// cssMap's argument are handled by the TypeScript compiler, so
|
|
21
|
+
// we don't bother with creating eslint errors for these here
|
|
22
|
+
|
|
23
|
+
if (node.arguments.length !== 1 || node.arguments[0].type !== 'ObjectExpression') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return node.arguments[0];
|
|
27
|
+
};
|
|
28
|
+
var UnusedCssMapChecker = exports.UnusedCssMapChecker = /*#__PURE__*/function () {
|
|
29
|
+
function UnusedCssMapChecker(cssMapObject, context, cssMapCallNode) {
|
|
30
|
+
(0, _classCallCheck2.default)(this, UnusedCssMapChecker);
|
|
31
|
+
this.cssMapObject = cssMapObject;
|
|
32
|
+
this.cssMapCallNode = cssMapCallNode;
|
|
33
|
+
this.report = context.report;
|
|
34
|
+
this.context = context;
|
|
35
|
+
}
|
|
36
|
+
return (0, _createClass2.default)(UnusedCssMapChecker, [{
|
|
37
|
+
key: "checkForUnusedStyles",
|
|
38
|
+
value: function checkForUnusedStyles() {
|
|
39
|
+
// Get all defined style keys
|
|
40
|
+
var definedStyles = new Map();
|
|
41
|
+
var _iterator = _createForOfIteratorHelper(this.cssMapObject.properties),
|
|
42
|
+
_step;
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
45
|
+
var _property = _step.value;
|
|
46
|
+
if (_property.type === 'Property' && _property.key.type === 'Identifier') {
|
|
47
|
+
definedStyles.set(_property.key.name, _property);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_iterator.e(err);
|
|
52
|
+
} finally {
|
|
53
|
+
_iterator.f();
|
|
54
|
+
}
|
|
55
|
+
if (definedStyles.size === 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Find the variable that holds the cssMap result
|
|
60
|
+
var cssMapVariable = this.findCssMapVariable();
|
|
61
|
+
if (!cssMapVariable) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Early return if no references - all styles are unused
|
|
66
|
+
if (cssMapVariable.references.length === 0) {
|
|
67
|
+
var _iterator2 = _createForOfIteratorHelper(definedStyles),
|
|
68
|
+
_step2;
|
|
69
|
+
try {
|
|
70
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
71
|
+
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
72
|
+
styleName = _step2$value[0],
|
|
73
|
+
property = _step2$value[1];
|
|
74
|
+
this.report({
|
|
75
|
+
node: property.key,
|
|
76
|
+
messageId: 'unusedCssMapStyle',
|
|
77
|
+
data: {
|
|
78
|
+
styleName: styleName
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
_iterator2.e(err);
|
|
84
|
+
} finally {
|
|
85
|
+
_iterator2.f();
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
var usedStyles = new Set();
|
|
90
|
+
var _iterator3 = _createForOfIteratorHelper(cssMapVariable.references),
|
|
91
|
+
_step3;
|
|
92
|
+
try {
|
|
93
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
94
|
+
var ref = _step3.value;
|
|
95
|
+
var node = ref.identifier;
|
|
96
|
+
var parent = node.parent;
|
|
97
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MemberExpression') {
|
|
98
|
+
if (!parent.computed && parent.property.type === 'Identifier') {
|
|
99
|
+
// Static access: styles.danger (not computed)
|
|
100
|
+
usedStyles.add(parent.property.name);
|
|
101
|
+
|
|
102
|
+
// Early exit if all styles are found
|
|
103
|
+
if (usedStyles.size === definedStyles.size) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
// Dynamic access: styles[key], styles['danger'], etc. (computed)
|
|
108
|
+
// Immediately exit - no styles will be reported as unused
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// No dynamic access - report all unused styles
|
|
115
|
+
} catch (err) {
|
|
116
|
+
_iterator3.e(err);
|
|
117
|
+
} finally {
|
|
118
|
+
_iterator3.f();
|
|
119
|
+
}
|
|
120
|
+
var _iterator4 = _createForOfIteratorHelper(definedStyles),
|
|
121
|
+
_step4;
|
|
122
|
+
try {
|
|
123
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
124
|
+
var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
|
|
125
|
+
_styleName = _step4$value[0],
|
|
126
|
+
_property2 = _step4$value[1];
|
|
127
|
+
if (!usedStyles.has(_styleName)) {
|
|
128
|
+
this.report({
|
|
129
|
+
node: _property2.key,
|
|
130
|
+
messageId: 'unusedCssMapStyle',
|
|
131
|
+
data: {
|
|
132
|
+
styleName: _styleName
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} catch (err) {
|
|
138
|
+
_iterator4.e(err);
|
|
139
|
+
} finally {
|
|
140
|
+
_iterator4.f();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, {
|
|
144
|
+
key: "findCssMapVariable",
|
|
145
|
+
value: function findCssMapVariable() {
|
|
146
|
+
var callNode = this.cssMapCallNode;
|
|
147
|
+
var parent = callNode.parent;
|
|
148
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && parent.id.type === 'Identifier') {
|
|
149
|
+
return (0, _findVariable.findVariable)({
|
|
150
|
+
identifier: parent.id,
|
|
151
|
+
sourceCode: (0, _contextCompat.getSourceCode)(this.context)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "run",
|
|
158
|
+
value: function run() {
|
|
159
|
+
this.checkForUnusedStyles();
|
|
160
|
+
}
|
|
161
|
+
}]);
|
|
162
|
+
}();
|
|
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useRangeFieldMessage = exports.useCheckboxFieldMessage = exports.default = void 0;
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
8
|
var _createRule = require("../utils/create-rule");
|
|
9
|
+
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; } } }; }
|
|
10
|
+
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; } }
|
|
11
|
+
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; }
|
|
9
12
|
var specialFieldsByImport = {
|
|
10
13
|
'@atlaskit/checkbox': {
|
|
11
14
|
component: 'Checkbox',
|
|
@@ -109,6 +112,22 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
109
112
|
var found;
|
|
110
113
|
while (q.length > 0 && !found) {
|
|
111
114
|
var child = q.pop();
|
|
115
|
+
if ('children' in child) {
|
|
116
|
+
var _iterator = _createForOfIteratorHelper(child.children),
|
|
117
|
+
_step;
|
|
118
|
+
try {
|
|
119
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
120
|
+
var innerChild = _step.value;
|
|
121
|
+
q.push(innerChild);
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
_iterator.e(err);
|
|
125
|
+
} finally {
|
|
126
|
+
_iterator.f();
|
|
127
|
+
}
|
|
128
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(child, 'BlockStatement') && (0, _eslintCodemodUtils.isNodeOfType)(child.body[0], 'ExpressionStatement')) {
|
|
129
|
+
q.push(child.body[0].expression);
|
|
130
|
+
}
|
|
112
131
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(child, 'JSXElement') || !(0, _eslintCodemodUtils.isNodeOfType)(child.openingElement.name, 'JSXIdentifier')) {
|
|
113
132
|
continue;
|
|
114
133
|
}
|
|
@@ -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::e075ab709ebd382d6f5e39fd78de9d6d>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -49,6 +49,7 @@ export default {
|
|
|
49
49
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
50
50
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
51
51
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
52
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
52
53
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
53
54
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
54
55
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
@@ -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::d78f5649534c2e153e3ce48063649a8a>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -48,6 +48,7 @@ export default {
|
|
|
48
48
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
49
49
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
50
50
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
51
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
51
52
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
52
53
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
53
54
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
@@ -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::310988af3dc2559509bf99f2110134b8>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -36,6 +36,7 @@ export default {
|
|
|
36
36
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
37
37
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
38
38
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
39
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
39
40
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
40
41
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
41
42
|
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
@@ -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::ce9d9b39fba8bb67d218e48398271109>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -35,6 +35,7 @@ export default {
|
|
|
35
35
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
36
36
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
37
37
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
38
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
38
39
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
39
40
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
40
41
|
'@atlaskit/design-system/use-correct-field': 'warn',
|
|
@@ -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::53ad66d79f989ce9beb46ee0186685b2>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import consistentCssPropUsage from './consistent-css-prop-usage';
|
|
@@ -45,6 +45,7 @@ import noStyledTaggedTemplateExpression from './no-styled-tagged-template-expres
|
|
|
45
45
|
import noUnsafeDesignTokenUsage from './no-unsafe-design-token-usage';
|
|
46
46
|
import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
|
|
47
47
|
import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
|
|
48
|
+
import noUnusedCssMap from './no-unused-css-map';
|
|
48
49
|
import noUtilityIcons from './no-utility-icons';
|
|
49
50
|
import preferPrimitives from './prefer-primitives';
|
|
50
51
|
import useButtonGroupLabel from './use-button-group-label';
|
|
@@ -111,6 +112,7 @@ export const rules = {
|
|
|
111
112
|
'no-unsafe-design-token-usage': noUnsafeDesignTokenUsage,
|
|
112
113
|
'no-unsafe-style-overrides': noUnsafeStyleOverrides,
|
|
113
114
|
'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
|
|
115
|
+
'no-unused-css-map': noUnusedCssMap,
|
|
114
116
|
'no-utility-icons': noUtilityIcons,
|
|
115
117
|
'prefer-primitives': preferPrimitives,
|
|
116
118
|
'use-button-group-label': useButtonGroupLabel,
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
import { getCssMapObject, UnusedCssMapChecker } from './utils';
|
|
5
|
+
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
6
|
+
const createUnusedCssMapRule = context => {
|
|
7
|
+
const {
|
|
8
|
+
text
|
|
9
|
+
} = getSourceCode(context);
|
|
10
|
+
if (IMPORT_SOURCES.every(importSource => !text.includes(importSource))) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
CallExpression(node) {
|
|
15
|
+
const references = getScope(context, node).references;
|
|
16
|
+
if (!isCssMap(node.callee, references, IMPORT_SOURCES)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const cssMapObject = getCssMapObject(node);
|
|
20
|
+
if (!cssMapObject) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const unusedCssMapChecker = new UnusedCssMapChecker(cssMapObject, context, node);
|
|
24
|
+
unusedCssMapChecker.run();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const noUnusedCssMapRule = createLintRule({
|
|
29
|
+
meta: {
|
|
30
|
+
name: 'no-unused-css-map',
|
|
31
|
+
docs: {
|
|
32
|
+
description: 'Detects unused styles in cssMap objects to help keep code clean.',
|
|
33
|
+
recommended: true,
|
|
34
|
+
severity: 'warn'
|
|
35
|
+
},
|
|
36
|
+
messages: {
|
|
37
|
+
unusedCssMapStyle: 'Unused style "{{styleName}}" in cssMap. Consider removing it if not needed.'
|
|
38
|
+
},
|
|
39
|
+
schema: [],
|
|
40
|
+
type: 'suggestion'
|
|
41
|
+
},
|
|
42
|
+
create: createUnusedCssMapRule
|
|
43
|
+
});
|
|
44
|
+
export default noUnusedCssMapRule;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
3
|
+
export const getCssMapObject = node => {
|
|
4
|
+
// We assume the argument `node` is already a cssMap() call.
|
|
5
|
+
|
|
6
|
+
// Things like the number of arguments to cssMap and the type of
|
|
7
|
+
// cssMap's argument are handled by the TypeScript compiler, so
|
|
8
|
+
// we don't bother with creating eslint errors for these here
|
|
9
|
+
|
|
10
|
+
if (node.arguments.length !== 1 || node.arguments[0].type !== 'ObjectExpression') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return node.arguments[0];
|
|
14
|
+
};
|
|
15
|
+
export class UnusedCssMapChecker {
|
|
16
|
+
constructor(cssMapObject, context, cssMapCallNode) {
|
|
17
|
+
this.cssMapObject = cssMapObject;
|
|
18
|
+
this.cssMapCallNode = cssMapCallNode;
|
|
19
|
+
this.report = context.report;
|
|
20
|
+
this.context = context;
|
|
21
|
+
}
|
|
22
|
+
checkForUnusedStyles() {
|
|
23
|
+
// Get all defined style keys
|
|
24
|
+
const definedStyles = new Map();
|
|
25
|
+
for (const property of this.cssMapObject.properties) {
|
|
26
|
+
if (property.type === 'Property' && property.key.type === 'Identifier') {
|
|
27
|
+
definedStyles.set(property.key.name, property);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (definedStyles.size === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Find the variable that holds the cssMap result
|
|
35
|
+
const cssMapVariable = this.findCssMapVariable();
|
|
36
|
+
if (!cssMapVariable) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Early return if no references - all styles are unused
|
|
41
|
+
if (cssMapVariable.references.length === 0) {
|
|
42
|
+
for (const [styleName, property] of definedStyles) {
|
|
43
|
+
this.report({
|
|
44
|
+
node: property.key,
|
|
45
|
+
messageId: 'unusedCssMapStyle',
|
|
46
|
+
data: {
|
|
47
|
+
styleName
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const usedStyles = new Set();
|
|
54
|
+
for (const ref of cssMapVariable.references) {
|
|
55
|
+
const node = ref.identifier;
|
|
56
|
+
const parent = node.parent;
|
|
57
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'MemberExpression') {
|
|
58
|
+
if (!parent.computed && parent.property.type === 'Identifier') {
|
|
59
|
+
// Static access: styles.danger (not computed)
|
|
60
|
+
usedStyles.add(parent.property.name);
|
|
61
|
+
|
|
62
|
+
// Early exit if all styles are found
|
|
63
|
+
if (usedStyles.size === definedStyles.size) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
// Dynamic access: styles[key], styles['danger'], etc. (computed)
|
|
68
|
+
// Immediately exit - no styles will be reported as unused
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// No dynamic access - report all unused styles
|
|
75
|
+
for (const [styleName, property] of definedStyles) {
|
|
76
|
+
if (!usedStyles.has(styleName)) {
|
|
77
|
+
this.report({
|
|
78
|
+
node: property.key,
|
|
79
|
+
messageId: 'unusedCssMapStyle',
|
|
80
|
+
data: {
|
|
81
|
+
styleName
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
findCssMapVariable() {
|
|
88
|
+
const callNode = this.cssMapCallNode;
|
|
89
|
+
const parent = callNode.parent;
|
|
90
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && parent.id.type === 'Identifier') {
|
|
91
|
+
return findVariable({
|
|
92
|
+
identifier: parent.id,
|
|
93
|
+
sourceCode: getSourceCode(this.context)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
run() {
|
|
99
|
+
this.checkForUnusedStyles();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -95,6 +95,13 @@ const rule = createLintRule({
|
|
|
95
95
|
let found;
|
|
96
96
|
while (q.length > 0 && !found) {
|
|
97
97
|
const child = q.pop();
|
|
98
|
+
if ('children' in child) {
|
|
99
|
+
for (const innerChild of child.children) {
|
|
100
|
+
q.push(innerChild);
|
|
101
|
+
}
|
|
102
|
+
} else if (isNodeOfType(child, 'BlockStatement') && isNodeOfType(child.body[0], 'ExpressionStatement')) {
|
|
103
|
+
q.push(child.body[0].expression);
|
|
104
|
+
}
|
|
98
105
|
if (!isNodeOfType(child, 'JSXElement') || !isNodeOfType(child.openingElement.name, 'JSXIdentifier')) {
|
|
99
106
|
continue;
|
|
100
107
|
}
|
|
@@ -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::e075ab709ebd382d6f5e39fd78de9d6d>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -49,6 +49,7 @@ export default {
|
|
|
49
49
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
50
50
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
51
51
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
52
|
+
'@atlaskit/design-system/no-unused-css-map': 'warn',
|
|
52
53
|
'@atlaskit/design-system/no-utility-icons': 'warn',
|
|
53
54
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
54
55
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|