@atlaskit/eslint-plugin-ui-styling-standard 2.4.1 → 3.0.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.
- package/CHANGELOG.md +19 -0
- package/README.md +0 -1
- package/dist/cjs/presets/all-flat.codegen.js +1 -2
- package/dist/cjs/presets/all.codegen.js +1 -2
- package/dist/cjs/rules/index.codegen.js +1 -3
- package/dist/cjs/rules/no-important-styles/index.js +35 -9
- package/dist/cjs/rules/utils/is-type-wrapper.js +23 -0
- package/dist/cjs/rules/utils/walk-style-call-properties.js +24 -11
- package/dist/es2019/presets/all-flat.codegen.js +1 -2
- package/dist/es2019/presets/all.codegen.js +1 -2
- package/dist/es2019/rules/index.codegen.js +1 -3
- package/dist/es2019/rules/no-important-styles/index.js +37 -9
- package/dist/es2019/rules/utils/is-type-wrapper.js +17 -0
- package/dist/es2019/rules/utils/walk-style-call-properties.js +15 -12
- package/dist/esm/presets/all-flat.codegen.js +1 -2
- package/dist/esm/presets/all.codegen.js +1 -2
- package/dist/esm/rules/index.codegen.js +1 -3
- package/dist/esm/rules/no-important-styles/index.js +35 -9
- package/dist/esm/rules/utils/is-type-wrapper.js +17 -0
- package/dist/esm/rules/utils/walk-style-call-properties.js +24 -11
- package/dist/types/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/rules/index.codegen.d.ts +1 -1
- package/dist/types/rules/utils/is-type-wrapper.d.ts +6 -0
- package/dist/types/rules/utils/walk-style-call-properties.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -232
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/index.js +0 -425
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -63
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2415
- package/dist/cjs/rules/utils/walk-style-object-properties.js +0 -47
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -226
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/index.js +0 -382
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -57
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2131
- package/dist/es2019/rules/utils/walk-style-object-properties.js +0 -29
- package/dist/esm/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -226
- package/dist/esm/rules/no-top-layer-unsafe-selectors/index.js +0 -419
- package/dist/esm/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -57
- package/dist/esm/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2409
- package/dist/esm/rules/utils/walk-style-object-properties.js +0 -41
- package/dist/types/rules/no-top-layer-unsafe-selectors/find-template-selectors.d.ts +0 -29
- package/dist/types/rules/no-top-layer-unsafe-selectors/index.d.ts +0 -3
- package/dist/types/rules/no-top-layer-unsafe-selectors/preserve-list-layout.d.ts +0 -12
- package/dist/types/rules/no-top-layer-unsafe-selectors/rewrite-selector.d.ts +0 -164
- package/dist/types/rules/utils/walk-style-object-properties.d.ts +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2a6c8a9e812fc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a6c8a9e812fc) -
|
|
8
|
+
`no-important-styles` now reports `!important` values wrapped in TypeScript expressions, e.g.
|
|
9
|
+
`color: 'red !important' as const`, and values inside wrapped style objects such as
|
|
10
|
+
`css({…} as const)` or `'&:hover': {…} as const`. Previously these were skipped.
|
|
11
|
+
|
|
12
|
+
## 3.0.0
|
|
13
|
+
|
|
14
|
+
### Major Changes
|
|
15
|
+
|
|
16
|
+
- [`947cd9330812c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/947cd9330812c) -
|
|
17
|
+
Remove the `no-top-layer-unsafe-selectors` rule from the plugin. It was in the `all` and
|
|
18
|
+
`all-flat` presets only, not in `recommended`. ESLint reports an unknown rule for any config entry
|
|
19
|
+
or `eslint-disable` comment that names
|
|
20
|
+
`@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors`, so delete those references.
|
|
21
|
+
|
|
3
22
|
## 2.4.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -57,7 +57,6 @@ module.exports = {
|
|
|
57
57
|
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
58
58
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
59
59
|
| <a href="./src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
|
|
60
|
-
| <a href="./src/rules/no-top-layer-unsafe-selectors/README.md">no-top-layer-unsafe-selectors</a> | Disallows selectors that a Design System layering surface rendered in the browser top layer can wrongly match, or wrongly displace. | | Yes | |
|
|
61
60
|
| <a href="./src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
|
|
62
61
|
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
63
62
|
| <a href="./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 | | |
|
|
@@ -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::4d0de15d2213df65666693ea490b4cce>>
|
|
13
13
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -34,7 +34,6 @@ var config = {
|
|
|
34
34
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'error',
|
|
35
35
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'error',
|
|
36
36
|
'@atlaskit/ui-styling-standard/no-styled': 'error',
|
|
37
|
-
'@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors': 'error',
|
|
38
37
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
39
38
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
40
39
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': '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::56ecb290562bdf88a8a5b5388a39e5f9>>
|
|
10
10
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -28,7 +28,6 @@ var config = {
|
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'error',
|
|
29
29
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'error',
|
|
30
30
|
'@atlaskit/ui-styling-standard/no-styled': 'error',
|
|
31
|
-
'@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors': 'error',
|
|
32
31
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
33
32
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
34
33
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
|
|
@@ -20,14 +20,13 @@ var _noImportantStyles = _interopRequireDefault(require("./no-important-styles")
|
|
|
20
20
|
var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
|
|
21
21
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
22
22
|
var _noStyled = _interopRequireDefault(require("./no-styled"));
|
|
23
|
-
var _noTopLayerUnsafeSelectors = _interopRequireDefault(require("./no-top-layer-unsafe-selectors"));
|
|
24
23
|
var _noUnsafeSelectors = _interopRequireDefault(require("./no-unsafe-selectors"));
|
|
25
24
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
26
25
|
var _noUnusedCssmapProperties = _interopRequireDefault(require("./no-unused-cssmap-properties"));
|
|
27
26
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
28
27
|
/**
|
|
29
28
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
30
|
-
* @codegen <<SignedSource::
|
|
29
|
+
* @codegen <<SignedSource::094f8a058153c7e839c5d98d2718ca4e>>
|
|
31
30
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
32
31
|
*/
|
|
33
32
|
|
|
@@ -47,7 +46,6 @@ var rules = exports.rules = {
|
|
|
47
46
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
48
47
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
49
48
|
'no-styled': _noStyled.default,
|
|
50
|
-
'no-top-layer-unsafe-selectors': _noTopLayerUnsafeSelectors.default,
|
|
51
49
|
'no-unsafe-selectors': _noUnsafeSelectors.default,
|
|
52
50
|
'no-unsafe-values': _noUnsafeValues.default,
|
|
53
51
|
'no-unused-cssmap-properties': _noUnusedCssmapProperties.default,
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
8
8
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
9
9
|
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
10
|
+
var _isTypeWrapper = require("../utils/is-type-wrapper");
|
|
10
11
|
var _styleCalls = require("../utils/style-calls");
|
|
11
12
|
var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
12
13
|
meta: {
|
|
@@ -77,10 +78,34 @@ function isInSupportedStyleCall(context, value, importSources) {
|
|
|
77
78
|
return styleCall.node === call && importSources.includes(styleCall.importSource);
|
|
78
79
|
}));
|
|
79
80
|
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
|
|
84
|
+
* outermost wrapper, which is what the next parent refers to, and that parent.
|
|
85
|
+
*/
|
|
86
|
+
function climbTypeWrappers(node) {
|
|
87
|
+
var current = node;
|
|
88
|
+
var parent = current.parent;
|
|
89
|
+
while (parent && (0, _isTypeWrapper.isTypeWrapper)(parent)) {
|
|
90
|
+
current = parent;
|
|
91
|
+
parent = current.parent;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
node: current,
|
|
95
|
+
parent: parent
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Find the style call a value belongs to, looking through TypeScript wrappers at every level:
|
|
101
|
+
* `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
|
|
102
|
+
*/
|
|
80
103
|
function findContainingCall(value) {
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
|
|
104
|
+
var _object;
|
|
105
|
+
var _climbTypeWrappers = climbTypeWrappers(value),
|
|
106
|
+
wrappedValue = _climbTypeWrappers.node,
|
|
107
|
+
property = _climbTypeWrappers.parent;
|
|
108
|
+
if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
|
|
84
109
|
return null;
|
|
85
110
|
}
|
|
86
111
|
var object = property.parent;
|
|
@@ -89,20 +114,21 @@ function findContainingCall(value) {
|
|
|
89
114
|
}
|
|
90
115
|
while (object) {
|
|
91
116
|
var _parent$parent;
|
|
92
|
-
var
|
|
93
|
-
|
|
117
|
+
var _climbTypeWrappers2 = climbTypeWrappers(object),
|
|
118
|
+
wrappedObject = _climbTypeWrappers2.node,
|
|
119
|
+
parent = _climbTypeWrappers2.parent;
|
|
120
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
|
|
94
121
|
var _object2;
|
|
95
|
-
|
|
96
|
-
object = property.parent;
|
|
122
|
+
object = parent.parent;
|
|
97
123
|
if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
|
|
98
124
|
return null;
|
|
99
125
|
}
|
|
100
126
|
continue;
|
|
101
127
|
}
|
|
102
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(
|
|
128
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
|
|
103
129
|
return parent;
|
|
104
130
|
}
|
|
105
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body ===
|
|
131
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
|
|
106
132
|
return parent.parent;
|
|
107
133
|
}
|
|
108
134
|
return null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isTypeWrapper = isTypeWrapper;
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript-only wrappers around an expression that ESTree does not model. None of them change
|
|
9
|
+
* the runtime value, so a rule reading a style key, value or argument should look through them:
|
|
10
|
+
*
|
|
11
|
+
* - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
|
|
12
|
+
* - `color: 'red !important' as const`
|
|
13
|
+
* - `css({…} as const)`
|
|
14
|
+
* - `<T>{…}` and `value!`
|
|
15
|
+
*/
|
|
16
|
+
var TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
|
|
20
|
+
*/
|
|
21
|
+
function isTypeWrapper(node) {
|
|
22
|
+
return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
|
|
23
|
+
}
|
|
@@ -4,29 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.walkStyleCallProperties = walkStyleCallProperties;
|
|
7
|
-
var _walkStyleObjectProperties = require("./walk-style-object-properties");
|
|
8
7
|
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; } } }; }
|
|
9
8
|
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; } }
|
|
10
9
|
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; }
|
|
11
10
|
function walkStyleCallProperties(styleCall, visitor, options) {
|
|
12
11
|
var skipTopLevel = !(options !== null && options !== void 0 && options.includeTopLevel) && (styleCall.styleFunction === 'cssMap' || styleCall.styleFunction === 'keyframes');
|
|
13
|
-
var _ref = options !== null && options !== void 0 ? options : {},
|
|
14
|
-
skipSubtree = _ref.skipSubtree;
|
|
15
12
|
var _iterator = _createForOfIteratorHelper(styleCall.node.arguments),
|
|
16
13
|
_step;
|
|
17
14
|
try {
|
|
18
15
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
19
16
|
var argument = _step.value;
|
|
20
17
|
if (argument.type === 'ObjectExpression') {
|
|
21
|
-
(
|
|
22
|
-
skipTopLevel: skipTopLevel,
|
|
23
|
-
skipSubtree: skipSubtree
|
|
24
|
-
});
|
|
18
|
+
walkStyleObject(argument, visitor, skipTopLevel);
|
|
25
19
|
} else if (argument.type === 'ArrowFunctionExpression' && argument.expression && argument.body.type === 'ObjectExpression') {
|
|
26
|
-
(
|
|
27
|
-
skipTopLevel: skipTopLevel,
|
|
28
|
-
skipSubtree: skipSubtree
|
|
29
|
-
});
|
|
20
|
+
walkStyleObject(argument.body, visitor, skipTopLevel);
|
|
30
21
|
}
|
|
31
22
|
}
|
|
32
23
|
} catch (err) {
|
|
@@ -34,4 +25,26 @@ function walkStyleCallProperties(styleCall, visitor, options) {
|
|
|
34
25
|
} finally {
|
|
35
26
|
_iterator.f();
|
|
36
27
|
}
|
|
28
|
+
}
|
|
29
|
+
function walkStyleObject(object, visitor, skipVisitor) {
|
|
30
|
+
var _iterator2 = _createForOfIteratorHelper(object.properties),
|
|
31
|
+
_step2;
|
|
32
|
+
try {
|
|
33
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
34
|
+
var property = _step2.value;
|
|
35
|
+
if (property.type !== 'Property') {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!skipVisitor) {
|
|
39
|
+
visitor(property);
|
|
40
|
+
}
|
|
41
|
+
if (property.value.type === 'ObjectExpression') {
|
|
42
|
+
walkStyleObject(property.value, visitor, false);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_iterator2.e(err);
|
|
47
|
+
} finally {
|
|
48
|
+
_iterator2.f();
|
|
49
|
+
}
|
|
37
50
|
}
|
|
@@ -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::4d0de15d2213df65666693ea490b4cce>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -26,7 +26,6 @@ const config = {
|
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'error',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'error',
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-styled': 'error',
|
|
29
|
-
'@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors': 'error',
|
|
30
29
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
31
30
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
32
31
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': '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::56ecb290562bdf88a8a5b5388a39e5f9>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -22,7 +22,6 @@ const config = {
|
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'error',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'error',
|
|
24
24
|
'@atlaskit/ui-styling-standard/no-styled': 'error',
|
|
25
|
-
'@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors': 'error',
|
|
26
25
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
27
26
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
28
27
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': '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::094f8a058153c7e839c5d98d2718ca4e>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -19,7 +19,6 @@ import noImportantStyles from './no-important-styles';
|
|
|
19
19
|
import noImportedStyleValues from './no-imported-style-values';
|
|
20
20
|
import noNestedSelectors from './no-nested-selectors';
|
|
21
21
|
import noStyled from './no-styled';
|
|
22
|
-
import noTopLayerUnsafeSelectors from './no-top-layer-unsafe-selectors';
|
|
23
22
|
import noUnsafeSelectors from './no-unsafe-selectors';
|
|
24
23
|
import noUnsafeValues from './no-unsafe-values';
|
|
25
24
|
import noUnusedCssmapProperties from './no-unused-cssmap-properties';
|
|
@@ -40,7 +39,6 @@ export const rules = {
|
|
|
40
39
|
'no-imported-style-values': noImportedStyleValues,
|
|
41
40
|
'no-nested-selectors': noNestedSelectors,
|
|
42
41
|
'no-styled': noStyled,
|
|
43
|
-
'no-top-layer-unsafe-selectors': noTopLayerUnsafeSelectors,
|
|
44
42
|
'no-unsafe-selectors': noUnsafeSelectors,
|
|
45
43
|
'no-unsafe-values': noUnsafeValues,
|
|
46
44
|
'no-unused-cssmap-properties': noUnusedCssmapProperties,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
2
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
3
3
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
4
|
+
import { isTypeWrapper } from '../utils/is-type-wrapper';
|
|
4
5
|
import { getStyleCalls } from '../utils/style-calls';
|
|
5
6
|
const rule = createLintRuleWithTypedConfig({
|
|
6
7
|
meta: {
|
|
@@ -72,10 +73,35 @@ function isInSupportedStyleCall(context, value, importSources) {
|
|
|
72
73
|
const call = findContainingCall(value);
|
|
73
74
|
return Boolean(call && getStyleCalls(context).some(styleCall => styleCall.node === call && importSources.includes(styleCall.importSource)));
|
|
74
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
|
|
79
|
+
* outermost wrapper, which is what the next parent refers to, and that parent.
|
|
80
|
+
*/
|
|
81
|
+
function climbTypeWrappers(node) {
|
|
82
|
+
let current = node;
|
|
83
|
+
let parent = current.parent;
|
|
84
|
+
while (parent && isTypeWrapper(parent)) {
|
|
85
|
+
current = parent;
|
|
86
|
+
parent = current.parent;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
node: current,
|
|
90
|
+
parent
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Find the style call a value belongs to, looking through TypeScript wrappers at every level:
|
|
96
|
+
* `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
|
|
97
|
+
*/
|
|
75
98
|
function findContainingCall(value) {
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
99
|
+
var _object;
|
|
100
|
+
const {
|
|
101
|
+
node: wrappedValue,
|
|
102
|
+
parent: property
|
|
103
|
+
} = climbTypeWrappers(value);
|
|
104
|
+
if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
|
|
79
105
|
return null;
|
|
80
106
|
}
|
|
81
107
|
let object = property.parent;
|
|
@@ -84,20 +110,22 @@ function findContainingCall(value) {
|
|
|
84
110
|
}
|
|
85
111
|
while (object) {
|
|
86
112
|
var _parent$parent;
|
|
87
|
-
const
|
|
88
|
-
|
|
113
|
+
const {
|
|
114
|
+
node: wrappedObject,
|
|
115
|
+
parent
|
|
116
|
+
} = climbTypeWrappers(object);
|
|
117
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
|
|
89
118
|
var _object2;
|
|
90
|
-
|
|
91
|
-
object = property.parent;
|
|
119
|
+
object = parent.parent;
|
|
92
120
|
if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
|
|
93
121
|
return null;
|
|
94
122
|
}
|
|
95
123
|
continue;
|
|
96
124
|
}
|
|
97
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(
|
|
125
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
|
|
98
126
|
return parent;
|
|
99
127
|
}
|
|
100
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body ===
|
|
128
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
|
|
101
129
|
return parent.parent;
|
|
102
130
|
}
|
|
103
131
|
return null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript-only wrappers around an expression that ESTree does not model. None of them change
|
|
3
|
+
* the runtime value, so a rule reading a style key, value or argument should look through them:
|
|
4
|
+
*
|
|
5
|
+
* - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
|
|
6
|
+
* - `color: 'red !important' as const`
|
|
7
|
+
* - `css({…} as const)`
|
|
8
|
+
* - `<T>{…}` and `value!`
|
|
9
|
+
*/
|
|
10
|
+
const TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
|
|
14
|
+
*/
|
|
15
|
+
export function isTypeWrapper(node) {
|
|
16
|
+
return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
|
|
17
|
+
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { walkStyleObjectProperties } from './walk-style-object-properties';
|
|
2
1
|
export function walkStyleCallProperties(styleCall, visitor, options) {
|
|
3
2
|
const skipTopLevel = !(options !== null && options !== void 0 && options.includeTopLevel) && (styleCall.styleFunction === 'cssMap' || styleCall.styleFunction === 'keyframes');
|
|
4
|
-
const {
|
|
5
|
-
skipSubtree
|
|
6
|
-
} = options !== null && options !== void 0 ? options : {};
|
|
7
3
|
for (const argument of styleCall.node.arguments) {
|
|
8
4
|
if (argument.type === 'ObjectExpression') {
|
|
9
|
-
|
|
10
|
-
skipTopLevel,
|
|
11
|
-
skipSubtree
|
|
12
|
-
});
|
|
5
|
+
walkStyleObject(argument, visitor, skipTopLevel);
|
|
13
6
|
} else if (argument.type === 'ArrowFunctionExpression' && argument.expression && argument.body.type === 'ObjectExpression') {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
walkStyleObject(argument.body, visitor, skipTopLevel);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function walkStyleObject(object, visitor, skipVisitor) {
|
|
12
|
+
for (const property of object.properties) {
|
|
13
|
+
if (property.type !== 'Property') {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (!skipVisitor) {
|
|
17
|
+
visitor(property);
|
|
18
|
+
}
|
|
19
|
+
if (property.value.type === 'ObjectExpression') {
|
|
20
|
+
walkStyleObject(property.value, visitor, false);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
}
|
|
@@ -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::4d0de15d2213df65666693ea490b4cce>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -26,7 +26,6 @@ var config = {
|
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'error',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'error',
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-styled': 'error',
|
|
29
|
-
'@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors': 'error',
|
|
30
29
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
31
30
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
32
31
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': '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::56ecb290562bdf88a8a5b5388a39e5f9>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -22,7 +22,6 @@ var config = {
|
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'error',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'error',
|
|
24
24
|
'@atlaskit/ui-styling-standard/no-styled': 'error',
|
|
25
|
-
'@atlaskit/ui-styling-standard/no-top-layer-unsafe-selectors': 'error',
|
|
26
25
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
27
26
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
28
27
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': '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::094f8a058153c7e839c5d98d2718ca4e>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -19,7 +19,6 @@ import noImportantStyles from './no-important-styles';
|
|
|
19
19
|
import noImportedStyleValues from './no-imported-style-values';
|
|
20
20
|
import noNestedSelectors from './no-nested-selectors';
|
|
21
21
|
import noStyled from './no-styled';
|
|
22
|
-
import noTopLayerUnsafeSelectors from './no-top-layer-unsafe-selectors';
|
|
23
22
|
import noUnsafeSelectors from './no-unsafe-selectors';
|
|
24
23
|
import noUnsafeValues from './no-unsafe-values';
|
|
25
24
|
import noUnusedCssmapProperties from './no-unused-cssmap-properties';
|
|
@@ -40,7 +39,6 @@ export var rules = {
|
|
|
40
39
|
'no-imported-style-values': noImportedStyleValues,
|
|
41
40
|
'no-nested-selectors': noNestedSelectors,
|
|
42
41
|
'no-styled': noStyled,
|
|
43
|
-
'no-top-layer-unsafe-selectors': noTopLayerUnsafeSelectors,
|
|
44
42
|
'no-unsafe-selectors': noUnsafeSelectors,
|
|
45
43
|
'no-unsafe-values': noUnsafeValues,
|
|
46
44
|
'no-unused-cssmap-properties': noUnusedCssmapProperties,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
2
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
3
3
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
4
|
+
import { isTypeWrapper } from '../utils/is-type-wrapper';
|
|
4
5
|
import { getStyleCalls } from '../utils/style-calls';
|
|
5
6
|
var rule = createLintRuleWithTypedConfig({
|
|
6
7
|
meta: {
|
|
@@ -71,10 +72,34 @@ function isInSupportedStyleCall(context, value, importSources) {
|
|
|
71
72
|
return styleCall.node === call && importSources.includes(styleCall.importSource);
|
|
72
73
|
}));
|
|
73
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
|
|
78
|
+
* outermost wrapper, which is what the next parent refers to, and that parent.
|
|
79
|
+
*/
|
|
80
|
+
function climbTypeWrappers(node) {
|
|
81
|
+
var current = node;
|
|
82
|
+
var parent = current.parent;
|
|
83
|
+
while (parent && isTypeWrapper(parent)) {
|
|
84
|
+
current = parent;
|
|
85
|
+
parent = current.parent;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
node: current,
|
|
89
|
+
parent: parent
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Find the style call a value belongs to, looking through TypeScript wrappers at every level:
|
|
95
|
+
* `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
|
|
96
|
+
*/
|
|
74
97
|
function findContainingCall(value) {
|
|
75
|
-
var
|
|
76
|
-
var
|
|
77
|
-
|
|
98
|
+
var _object;
|
|
99
|
+
var _climbTypeWrappers = climbTypeWrappers(value),
|
|
100
|
+
wrappedValue = _climbTypeWrappers.node,
|
|
101
|
+
property = _climbTypeWrappers.parent;
|
|
102
|
+
if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
|
|
78
103
|
return null;
|
|
79
104
|
}
|
|
80
105
|
var object = property.parent;
|
|
@@ -83,20 +108,21 @@ function findContainingCall(value) {
|
|
|
83
108
|
}
|
|
84
109
|
while (object) {
|
|
85
110
|
var _parent$parent;
|
|
86
|
-
var
|
|
87
|
-
|
|
111
|
+
var _climbTypeWrappers2 = climbTypeWrappers(object),
|
|
112
|
+
wrappedObject = _climbTypeWrappers2.node,
|
|
113
|
+
parent = _climbTypeWrappers2.parent;
|
|
114
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
|
|
88
115
|
var _object2;
|
|
89
|
-
|
|
90
|
-
object = property.parent;
|
|
116
|
+
object = parent.parent;
|
|
91
117
|
if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
|
|
92
118
|
return null;
|
|
93
119
|
}
|
|
94
120
|
continue;
|
|
95
121
|
}
|
|
96
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(
|
|
122
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
|
|
97
123
|
return parent;
|
|
98
124
|
}
|
|
99
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body ===
|
|
125
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
|
|
100
126
|
return parent.parent;
|
|
101
127
|
}
|
|
102
128
|
return null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript-only wrappers around an expression that ESTree does not model. None of them change
|
|
3
|
+
* the runtime value, so a rule reading a style key, value or argument should look through them:
|
|
4
|
+
*
|
|
5
|
+
* - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
|
|
6
|
+
* - `color: 'red !important' as const`
|
|
7
|
+
* - `css({…} as const)`
|
|
8
|
+
* - `<T>{…}` and `value!`
|
|
9
|
+
*/
|
|
10
|
+
var TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
|
|
14
|
+
*/
|
|
15
|
+
export function isTypeWrapper(node) {
|
|
16
|
+
return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
|
|
17
|
+
}
|