@atlaskit/eslint-plugin-ui-styling-standard 2.2.0 → 2.4.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 +37 -0
- package/README.md +20 -19
- package/dist/cjs/presets/all-flat.codegen.js +3 -2
- package/dist/cjs/presets/all.codegen.js +3 -2
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -2
- package/dist/cjs/presets/recommended.codegen.js +2 -2
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-atlaskit-theme/index.js +1 -1
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +232 -0
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/index.js +425 -0
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +63 -0
- package/dist/cjs/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +2415 -0
- package/dist/cjs/rules/no-unsafe-selectors/constants.js +4 -1
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +28 -1
- package/dist/cjs/rules/utils/walk-style-call-properties.js +11 -24
- package/dist/cjs/rules/utils/walk-style-object-properties.js +47 -0
- package/dist/es2019/presets/all-flat.codegen.js +3 -2
- package/dist/es2019/presets/all.codegen.js +3 -2
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -2
- package/dist/es2019/presets/recommended.codegen.js +2 -2
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-atlaskit-theme/index.js +1 -1
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +226 -0
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/index.js +382 -0
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +57 -0
- package/dist/es2019/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +2131 -0
- package/dist/es2019/rules/no-unsafe-selectors/constants.js +4 -1
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +26 -1
- package/dist/es2019/rules/utils/walk-style-call-properties.js +12 -15
- package/dist/es2019/rules/utils/walk-style-object-properties.js +29 -0
- package/dist/esm/presets/all-flat.codegen.js +3 -2
- package/dist/esm/presets/all.codegen.js +3 -2
- package/dist/esm/presets/recommended-flat.codegen.js +2 -2
- package/dist/esm/presets/recommended.codegen.js +2 -2
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-atlaskit-theme/index.js +1 -1
- package/dist/esm/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +226 -0
- package/dist/esm/rules/no-top-layer-unsafe-selectors/index.js +419 -0
- package/dist/esm/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +57 -0
- package/dist/esm/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +2409 -0
- package/dist/esm/rules/no-unsafe-selectors/constants.js +4 -1
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +28 -1
- package/dist/esm/rules/utils/walk-style-call-properties.js +11 -24
- package/dist/esm/rules/utils/walk-style-object-properties.js +41 -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-top-layer-unsafe-selectors/find-template-selectors.d.ts +29 -0
- package/dist/types/rules/no-top-layer-unsafe-selectors/index.d.ts +3 -0
- package/dist/types/rules/no-top-layer-unsafe-selectors/preserve-list-layout.d.ts +12 -0
- package/dist/types/rules/no-top-layer-unsafe-selectors/rewrite-selector.d.ts +164 -0
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -1
- package/dist/types/rules/utils/walk-style-call-properties.d.ts +1 -0
- package/dist/types/rules/utils/walk-style-object-properties.d.ts +18 -0
- package/package.json +1 -1
|
@@ -15,7 +15,10 @@ exports.allowedPseudos = void 0;
|
|
|
15
15
|
|
|
16
16
|
var cssPseudos = ['&:active', '&:autofill', '&:blank', '&:checked', '&:default', '&:defined', '&:disabled', '&:empty', '&:enabled', '&:first', '&:focus', '&:focus-visible', '&:focus-within', '&:fullscreen', '&:hover', '&:in-range', '&:indeterminate', '&:invalid', '&:left', '&:link', '&:local-link', '&:optional', '&:out-of-range', '&:paused', '&:picture-in-picture', '&:placeholder-shown', '&:playing', '&:popover-open', '&:read-only', '&:read-write', '&:required', '&:right', '&:target', '&:user-invalid', '&:user-valid', '&:valid', '&:visited', '&::after', '&::backdrop', '&::before', '&::cue', '&::cue-region', '&::first-letter', '&::first-line', '&::grammar-error', '&::marker', '&::placeholder', '&::selection', '&::spelling-error', '&::target-text', '&::view-transition', '&::-webkit-details-marker',
|
|
17
17
|
// Chained pseudos (CSSFlattenedChainedPsuedos from @compiled/react)
|
|
18
|
-
'&:active:visited', '&:focus:not(:focus-visible)', '&:focus::after', '&:focus::before', '&:focus-visible::after', '&:focus-visible::before', '&:focus-within::after', '&:focus-within::before', '&:hover::after', '&:hover::before', '&:visited:active', '&:visited:hover', '&:visited:focus', '&:visited:focus-visible', '&:visited:focus-within'
|
|
18
|
+
'&:active:visited', '&:focus:not(:focus-visible)', '&:focus::after', '&:focus::before', '&:focus-visible::after', '&:focus-visible::before', '&:focus-within::after', '&:focus-within::before', '&:hover::after', '&:hover::before', '&:visited:active', '&:visited:hover', '&:visited:focus', '&:visited:focus-visible', '&:visited:focus-within',
|
|
19
|
+
// Vendor pseudo-elements with no standard equivalent. These are not part of CSSPseudos, so the
|
|
20
|
+
// typed @atlaskit/css and xcss APIs still reject them.
|
|
21
|
+
'&::-moz-focus-inner', '&::-moz-focus-outer', '&::-moz-range-progress', '&::-moz-range-thumb', '&::-moz-range-track', '&::-webkit-slider-runnable-track', '&::-webkit-slider-thumb'];
|
|
19
22
|
var allowedPseudos = exports.allowedPseudos = new Set(
|
|
20
23
|
/**
|
|
21
24
|
* The `&` is included above for type checking reasons,
|
|
@@ -103,7 +103,7 @@ function checkNoRestrictedPseudos(_ref2, pseudos) {
|
|
|
103
103
|
try {
|
|
104
104
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
105
105
|
var pseudo = _step.value;
|
|
106
|
-
if (_constants.allowedPseudos.has(pseudo.value)) {
|
|
106
|
+
if (_constants.allowedPseudos.has(pseudo.value) || isInAllowedPseudoChain(pseudo)) {
|
|
107
107
|
continue;
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -138,6 +138,33 @@ function checkNoRestrictedPseudos(_ref2, pseudos) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* The allowlist includes chained pseudos such as `:focus:not(:focus-visible)` whose parts are not
|
|
143
|
+
* all allowed on their own, so a pseudo is also allowed when a run of adjacent pseudos containing
|
|
144
|
+
* it matches an allowlisted chain.
|
|
145
|
+
*/
|
|
146
|
+
function isInAllowedPseudoChain(pseudo) {
|
|
147
|
+
var chain = [pseudo];
|
|
148
|
+
for (var node = pseudo.prev(); (0, _postcssSelectorParser.isPseudo)(node); node = node.prev()) {
|
|
149
|
+
chain.unshift(node);
|
|
150
|
+
}
|
|
151
|
+
for (var _node = pseudo.next(); (0, _postcssSelectorParser.isPseudo)(_node); _node = _node.next()) {
|
|
152
|
+
chain.push(_node);
|
|
153
|
+
}
|
|
154
|
+
var index = chain.indexOf(pseudo);
|
|
155
|
+
for (var start = 0; start <= index; start++) {
|
|
156
|
+
for (var end = index + 1; end <= chain.length; end++) {
|
|
157
|
+
var text = chain.slice(start, end).map(function (node) {
|
|
158
|
+
return String(node).replace(/\s+/g, '');
|
|
159
|
+
}).join('');
|
|
160
|
+
if (_constants.allowedPseudos.has(text)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
|
|
141
168
|
/**
|
|
142
169
|
* The original four pseudo-elements have a legacy single colon syntax.
|
|
143
170
|
*
|
|
@@ -4,20 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.walkStyleCallProperties = walkStyleCallProperties;
|
|
7
|
+
var _walkStyleObjectProperties = require("./walk-style-object-properties");
|
|
7
8
|
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; } } }; }
|
|
8
9
|
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; } }
|
|
9
10
|
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; }
|
|
10
11
|
function walkStyleCallProperties(styleCall, visitor, options) {
|
|
11
12
|
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;
|
|
12
15
|
var _iterator = _createForOfIteratorHelper(styleCall.node.arguments),
|
|
13
16
|
_step;
|
|
14
17
|
try {
|
|
15
18
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
16
19
|
var argument = _step.value;
|
|
17
20
|
if (argument.type === 'ObjectExpression') {
|
|
18
|
-
|
|
21
|
+
(0, _walkStyleObjectProperties.walkStyleObjectProperties)(argument, visitor, {
|
|
22
|
+
skipTopLevel: skipTopLevel,
|
|
23
|
+
skipSubtree: skipSubtree
|
|
24
|
+
});
|
|
19
25
|
} else if (argument.type === 'ArrowFunctionExpression' && argument.expression && argument.body.type === 'ObjectExpression') {
|
|
20
|
-
|
|
26
|
+
(0, _walkStyleObjectProperties.walkStyleObjectProperties)(argument.body, visitor, {
|
|
27
|
+
skipTopLevel: skipTopLevel,
|
|
28
|
+
skipSubtree: skipSubtree
|
|
29
|
+
});
|
|
21
30
|
}
|
|
22
31
|
}
|
|
23
32
|
} catch (err) {
|
|
@@ -25,26 +34,4 @@ function walkStyleCallProperties(styleCall, visitor, options) {
|
|
|
25
34
|
} finally {
|
|
26
35
|
_iterator.f();
|
|
27
36
|
}
|
|
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
|
-
}
|
|
50
37
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.walkStyleObjectProperties = walkStyleObjectProperties;
|
|
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; } } }; }
|
|
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; } }
|
|
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; }
|
|
10
|
+
/**
|
|
11
|
+
* Walk one style object's properties at every depth. With `skipTopLevel` the top-level
|
|
12
|
+
* properties are walked into but not visited, which is how a `cssMap` or `keyframes` argument
|
|
13
|
+
* hides its variant or block names. Nested objects are always visited in full. Use this directly
|
|
14
|
+
* for a style object that is not the argument of a style call, such as the value of a `css` prop.
|
|
15
|
+
*
|
|
16
|
+
* `skipSubtree` stops the descent into a property's value, so its children are never visited.
|
|
17
|
+
* A caller needs this when a nested block's keys are not the same kind of thing as its own key:
|
|
18
|
+
* the children of an `@keyframes` block are offsets (`from`, `50%`), not selectors, and a rule
|
|
19
|
+
* that treats them as selectors will report — or worse, fix — a keyframe offset. Declining to
|
|
20
|
+
* visit the at-rule property itself is not enough, because the walk into its value is what
|
|
21
|
+
* exposes the offsets. Omit it and the walk behaves exactly as before.
|
|
22
|
+
*/
|
|
23
|
+
function walkStyleObjectProperties(object, visitor, options) {
|
|
24
|
+
walk(object, visitor, Boolean(options === null || options === void 0 ? void 0 : options.skipTopLevel), options === null || options === void 0 ? void 0 : options.skipSubtree);
|
|
25
|
+
}
|
|
26
|
+
function walk(object, visitor, skipVisitor, skipSubtree) {
|
|
27
|
+
var _iterator = _createForOfIteratorHelper(object.properties),
|
|
28
|
+
_step;
|
|
29
|
+
try {
|
|
30
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
31
|
+
var property = _step.value;
|
|
32
|
+
if (property.type !== 'Property') {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!skipVisitor) {
|
|
36
|
+
visitor(property);
|
|
37
|
+
}
|
|
38
|
+
if (property.value.type === 'ObjectExpression' && !(skipSubtree !== null && skipSubtree !== void 0 && skipSubtree(property))) {
|
|
39
|
+
walk(property.value, visitor, false, skipSubtree);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -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::75b18fe1e3e0e0eeeb87a8dd4ed975ae>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ const config = {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
17
17
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
19
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -26,6 +26,7 @@ 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',
|
|
29
30
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
30
31
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
31
32
|
'@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::ff2cac75bedd9b12fc1c17bc6cf66c5c>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ const config = {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
13
13
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
15
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -22,6 +22,7 @@ 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',
|
|
25
26
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
26
27
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
27
28
|
'@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::4d0de15d2213df65666693ea490b4cce>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ const config = {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
17
17
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
19
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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
|
|
|
@@ -12,7 +12,7 @@ const config = {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
13
13
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
15
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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::7b2b0662d0eeb0e3a3e4c844a505d27e>>
|
|
4
4
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -19,6 +19,7 @@ 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';
|
|
22
23
|
import noUnsafeSelectors from './no-unsafe-selectors';
|
|
23
24
|
import noUnsafeValues from './no-unsafe-values';
|
|
24
25
|
import noUnusedCssmapProperties from './no-unused-cssmap-properties';
|
|
@@ -39,6 +40,7 @@ export const rules = {
|
|
|
39
40
|
'no-imported-style-values': noImportedStyleValues,
|
|
40
41
|
'no-nested-selectors': noNestedSelectors,
|
|
41
42
|
'no-styled': noStyled,
|
|
43
|
+
'no-top-layer-unsafe-selectors': noTopLayerUnsafeSelectors,
|
|
42
44
|
'no-unsafe-selectors': noUnsafeSelectors,
|
|
43
45
|
'no-unsafe-values': noUnsafeValues,
|
|
44
46
|
'no-unused-cssmap-properties': noUnusedCssmapProperties,
|
|
@@ -5,7 +5,7 @@ const rule = createLintRule({
|
|
|
5
5
|
docs: {
|
|
6
6
|
description: 'Disallow imports from `@atlaskit/theme`',
|
|
7
7
|
recommended: true,
|
|
8
|
-
severity: '
|
|
8
|
+
severity: 'error'
|
|
9
9
|
},
|
|
10
10
|
messages: {
|
|
11
11
|
'no-atlaskit-theme': 'Do not import `@atlaskit/theme`. Use `@atlaskit/tokens` or Atlassian Design System components instead.'
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locate the selectors inside a tagged template literal's raw source text.
|
|
3
|
+
*
|
|
4
|
+
* The style-call index only sees call expressions, so `styled.div\`…\`` and `css\`…\`` are
|
|
5
|
+
* invisible to it. This scanner fills that gap: it walks the text between the template's
|
|
6
|
+
* backticks and returns the byte range of every selector, so ranges map 1:1 onto the file and
|
|
7
|
+
* can be handed straight to an ESLint fixer.
|
|
8
|
+
*
|
|
9
|
+
* It deliberately does not try to be a CSS parser. A selector is the text between the last
|
|
10
|
+
* `;`, `{` or `}` and the next `{`. Anything it mis-reads will either fail to parse as a
|
|
11
|
+
* selector — in which case `rewriteSelector` skips it — or be reported for review. What it
|
|
12
|
+
* must not do is mistake a `${…}` interpolation, a quoted string or a comment for CSS
|
|
13
|
+
* structure, so it steps over all three.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function findTemplateSelectors(source, offset) {
|
|
17
|
+
const found = [];
|
|
18
|
+
let segmentStart = 0;
|
|
19
|
+
/**
|
|
20
|
+
* Set when a comment appears after the segment's first non-whitespace character. A selector
|
|
21
|
+
* with a comment inside it — `& /* x */ > div` — cannot be replaced as one contiguous range
|
|
22
|
+
* without eating the comment, so it is skipped rather than mangled. A comment *before* the
|
|
23
|
+
* selector just moves `segmentStart` past it.
|
|
24
|
+
*/
|
|
25
|
+
let commentInsideSegment = false;
|
|
26
|
+
/**
|
|
27
|
+
* How many `(` are open. Inside a function's parentheses `//` is data, not a comment:
|
|
28
|
+
* `url(//cdn.example.com/a.png)` and an unquoted data URI both carry one.
|
|
29
|
+
*/
|
|
30
|
+
let parenthesisDepth = 0;
|
|
31
|
+
/**
|
|
32
|
+
* How many CSS `{` are open. `${…}` braces and parentheses do not count.
|
|
33
|
+
*/
|
|
34
|
+
let braceDepth = 0;
|
|
35
|
+
/**
|
|
36
|
+
* The brace depth at which a `@keyframes` block opened, or `null` outside one. Everything
|
|
37
|
+
* nested inside is an offset (`from`, `50%`), not a selector — each parses as a tag selector,
|
|
38
|
+
* so without this the guard is written onto a keyframe and the animation stops. Skipping the
|
|
39
|
+
* at-rule's own prelude is not enough, because the block's contents open their own segments.
|
|
40
|
+
*/
|
|
41
|
+
let keyframesDepth = null;
|
|
42
|
+
const startSegment = at => {
|
|
43
|
+
segmentStart = at;
|
|
44
|
+
commentInsideSegment = false;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Step over a comment spanning `[start, end)`. A comment before the segment's first
|
|
49
|
+
* non-whitespace character just moves the segment past it; a comment inside the segment
|
|
50
|
+
* marks it unfixable. Returns the index to resume scanning at.
|
|
51
|
+
*/
|
|
52
|
+
const skipComment = (start, end) => {
|
|
53
|
+
const isLeading = source.slice(segmentStart, start).trim() === '';
|
|
54
|
+
if (isLeading) {
|
|
55
|
+
segmentStart = end;
|
|
56
|
+
} else {
|
|
57
|
+
commentInsideSegment = true;
|
|
58
|
+
}
|
|
59
|
+
return end;
|
|
60
|
+
};
|
|
61
|
+
for (let index = 0; index < source.length; index++) {
|
|
62
|
+
const character = source[index];
|
|
63
|
+
|
|
64
|
+
/* Step over a quoted string — `content: "{"` must not open a block. */
|
|
65
|
+
if (character === '"' || character === "'") {
|
|
66
|
+
index = skipQuoted(source, index);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (character === '/' && source[index + 1] === '*') {
|
|
70
|
+
const close = source.indexOf('*/', index + 2);
|
|
71
|
+
const end = close === -1 ? source.length : close + 2;
|
|
72
|
+
index = skipComment(index, end) - 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A `//` line comment. Emotion and styled-components strip these before the CSS is
|
|
78
|
+
* parsed, so a selector written after one on the next line is real. Inside parentheses
|
|
79
|
+
* the same two characters are part of a URL, so the depth check keeps them.
|
|
80
|
+
*/
|
|
81
|
+
if (character === '/' && source[index + 1] === '/' && parenthesisDepth === 0) {
|
|
82
|
+
const newline = source.indexOf('\n', index + 2);
|
|
83
|
+
const end = newline === -1 ? source.length : newline + 1;
|
|
84
|
+
index = skipComment(index, end) - 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (character === '(') {
|
|
88
|
+
parenthesisDepth++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (character === ')') {
|
|
92
|
+
parenthesisDepth = Math.max(0, parenthesisDepth - 1);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* Step over a `${…}` interpolation. Its braces are not CSS braces, but the `${…}` text
|
|
97
|
+
* itself stays in the segment so the transform can recognise the selector as dynamic. */
|
|
98
|
+
if (character === '{' && index > 0 && source[index - 1] === '$') {
|
|
99
|
+
const isLeading = source.slice(segmentStart, index - 1).trim() === '';
|
|
100
|
+
index = skipInterpolation(source, index);
|
|
101
|
+
/**
|
|
102
|
+
* A `${mixin}` alone on its line, with no `;` after it, is a statement of its own:
|
|
103
|
+
* the selector on the next line starts a fresh segment rather than inheriting the
|
|
104
|
+
* interpolation and being read as dynamic.
|
|
105
|
+
*/
|
|
106
|
+
if (isLeading && isRestOfLineBlank(source, index + 1)) {
|
|
107
|
+
startSegment(index + 1);
|
|
108
|
+
}
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (character === '{') {
|
|
112
|
+
const raw = source.slice(segmentStart, index);
|
|
113
|
+
const leading = raw.length - raw.trimStart().length;
|
|
114
|
+
const text = raw.trim();
|
|
115
|
+
|
|
116
|
+
/* At-rules are blocks but not selectors; the transform has nothing to say about them. */
|
|
117
|
+
if (text !== '' && !text.startsWith('@') && !commentInsideSegment && keyframesDepth === null) {
|
|
118
|
+
found.push({
|
|
119
|
+
text,
|
|
120
|
+
start: offset + segmentStart + leading,
|
|
121
|
+
end: offset + segmentStart + leading + text.length
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (keyframesDepth === null && /^@(-[a-z]+-)?keyframes\b/i.test(text)) {
|
|
125
|
+
keyframesDepth = braceDepth;
|
|
126
|
+
}
|
|
127
|
+
braceDepth++;
|
|
128
|
+
startSegment(index + 1);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (character === '}') {
|
|
132
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
133
|
+
if (keyframesDepth !== null && braceDepth <= keyframesDepth) {
|
|
134
|
+
keyframesDepth = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (character === '}' || character === ';') {
|
|
138
|
+
startSegment(index + 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return found;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Is everything from `start` to the next newline whitespace? A missing newline does not count:
|
|
146
|
+
* `${selector}` at the very end has nothing after it to separate from.
|
|
147
|
+
*/
|
|
148
|
+
function isRestOfLineBlank(source, start) {
|
|
149
|
+
const newline = source.indexOf('\n', start);
|
|
150
|
+
return newline !== -1 && source.slice(start, newline).trim() === '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Index of the quote closing the string that opens at `start`, or the end of the source when
|
|
155
|
+
* the string is unterminated.
|
|
156
|
+
*/
|
|
157
|
+
function skipQuoted(source, start) {
|
|
158
|
+
const quote = source[start];
|
|
159
|
+
let index = start + 1;
|
|
160
|
+
while (index < source.length) {
|
|
161
|
+
if (source[index] === '\\') {
|
|
162
|
+
index += 2;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (source[index] === quote) {
|
|
166
|
+
return index;
|
|
167
|
+
}
|
|
168
|
+
index++;
|
|
169
|
+
}
|
|
170
|
+
return source.length;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Index of the `}` closing the interpolation whose `{` is at `start`, or the end of the source
|
|
175
|
+
* when it is unterminated.
|
|
176
|
+
*
|
|
177
|
+
* The interpolation holds JavaScript, so a brace inside one of its string literals is not a
|
|
178
|
+
* brace: `${cond ? '}' : ''}` closes at the last character, not at the quoted one. Quoted
|
|
179
|
+
* strings and template literals are stepped over; a template literal may in turn hold its own
|
|
180
|
+
* interpolations, so the two skips call each other.
|
|
181
|
+
*/
|
|
182
|
+
function skipInterpolation(source, start) {
|
|
183
|
+
let depth = 1;
|
|
184
|
+
let index = start + 1;
|
|
185
|
+
while (index < source.length && depth > 0) {
|
|
186
|
+
const character = source[index];
|
|
187
|
+
if (character === '"' || character === "'") {
|
|
188
|
+
index = skipQuoted(source, index) + 1;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (character === '`') {
|
|
192
|
+
index = skipTemplateLiteral(source, index) + 1;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (character === '{') {
|
|
196
|
+
depth++;
|
|
197
|
+
} else if (character === '}') {
|
|
198
|
+
depth--;
|
|
199
|
+
}
|
|
200
|
+
index++;
|
|
201
|
+
}
|
|
202
|
+
return index - 1;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Index of the backtick closing the template literal that opens at `start`, or the end of the
|
|
207
|
+
* source when it is unterminated.
|
|
208
|
+
*/
|
|
209
|
+
function skipTemplateLiteral(source, start) {
|
|
210
|
+
let index = start + 1;
|
|
211
|
+
while (index < source.length) {
|
|
212
|
+
if (source[index] === '\\') {
|
|
213
|
+
index += 2;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (source[index] === '`') {
|
|
217
|
+
return index;
|
|
218
|
+
}
|
|
219
|
+
if (source[index] === '$' && source[index + 1] === '{') {
|
|
220
|
+
index = skipInterpolation(source, index + 1) + 1;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
index++;
|
|
224
|
+
}
|
|
225
|
+
return source.length;
|
|
226
|
+
}
|