@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`187f8c82f1f1e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/187f8c82f1f1e) -
|
|
8
|
+
Raise `no-atlaskit-theme` from a warning to an error in the recommended config. Imports from
|
|
9
|
+
`@atlaskit/theme` now fail lint unless they are removed or disabled.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`9ca54438f46bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9ca54438f46bf) -
|
|
14
|
+
`no-unsafe-selectors` now honours chained pseudos in its allowlist. `&:focus:not(:focus-visible)`
|
|
15
|
+
was allowlisted but still reported, because each pseudo was checked on its own and `:not` is not
|
|
16
|
+
allowed alone. Other uses of `:not`, such as `&:hover:not(:focus-visible)`, are still reported.
|
|
17
|
+
- [`9ca54438f46bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9ca54438f46bf) -
|
|
18
|
+
`no-unsafe-selectors` now allows the vendor pseudo-elements that have no standard equivalent:
|
|
19
|
+
`::-moz-focus-inner`, `::-moz-focus-outer`, `::-moz-range-progress`, `::-moz-range-thumb`,
|
|
20
|
+
`::-moz-range-track`, `::-webkit-slider-runnable-track`, and `::-webkit-slider-thumb`. Other
|
|
21
|
+
vendor pseudos, such as `::-webkit-scrollbar` and `::-ms-clear`, are still reported.
|
|
22
|
+
|
|
23
|
+
## 2.3.0
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- [`0418e1c376844`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0418e1c376844) -
|
|
28
|
+
Add the `no-top-layer-unsafe-selectors` rule. It reports selectors that a Design System layering
|
|
29
|
+
surface rendered in the browser top layer can wrongly match or wrongly displace, and autofixes
|
|
30
|
+
most of them to a guarded form with the same specificity. Positional pseudo-classes such as
|
|
31
|
+
`:first-child` are reported without a fix, because no guard form for them survives the build.
|
|
32
|
+
|
|
33
|
+
The rule is not in the `recommended` preset, so `recommended` users see no change. It is in the
|
|
34
|
+
`all` and `all-flat` presets at `error`, so users of those presets get new errors.
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies
|
|
39
|
+
|
|
3
40
|
## 2.2.0
|
|
4
41
|
|
|
5
42
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -42,25 +42,26 @@ module.exports = {
|
|
|
42
42
|
|
|
43
43
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
44
44
|
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
45
|
-
| <a href="./
|
|
46
|
-
| <a href="./
|
|
47
|
-
| <a href="./
|
|
48
|
-
| <a href="./
|
|
49
|
-
| <a href="./
|
|
50
|
-
| <a href="./
|
|
51
|
-
| <a href="./
|
|
52
|
-
| <a href="./
|
|
53
|
-
| <a href="./
|
|
54
|
-
| <a href="./
|
|
55
|
-
| <a href="./
|
|
56
|
-
| <a href="./
|
|
57
|
-
| <a href="./
|
|
58
|
-
| <a href="./
|
|
59
|
-
| <a href="./
|
|
60
|
-
| <a href="./
|
|
61
|
-
| <a href="./
|
|
62
|
-
| <a href="./
|
|
63
|
-
| <a href="./
|
|
45
|
+
| <a href="./src/rules/atlaskit-theme/README.md">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
|
|
46
|
+
| <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
|
|
47
|
+
| <a href="./src/rules/enforce-style-prop/README.md">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
|
|
48
|
+
| <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
|
|
49
|
+
| <a href="./src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
|
|
50
|
+
| <a href="./src/rules/no-atlaskit-theme/README.md">no-atlaskit-theme</a> | Disallow imports from `@atlaskit/theme` | Yes | | |
|
|
51
|
+
| <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
52
|
+
| <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
53
|
+
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
54
|
+
| <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
55
|
+
| <a href="./src/rules/no-global-styles/README.md">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
|
|
56
|
+
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
57
|
+
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
58
|
+
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
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
|
+
| <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
|
+
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
63
|
+
| <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 | | |
|
|
64
|
+
| <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
64
65
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
65
66
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
66
67
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -9,7 +9,7 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
|
|
|
9
9
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
10
10
|
/**
|
|
11
11
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
12
|
-
* @codegen <<SignedSource::
|
|
12
|
+
* @codegen <<SignedSource::75b18fe1e3e0e0eeeb87a8dd4ed975ae>>
|
|
13
13
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -24,7 +24,7 @@ var config = {
|
|
|
24
24
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
25
25
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
27
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
27
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
29
29
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
30
30
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -34,6 +34,7 @@ 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',
|
|
37
38
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
38
39
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
39
40
|
'@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::ff2cac75bedd9b12fc1c17bc6cf66c5c>>
|
|
10
10
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ var config = {
|
|
|
18
18
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
19
19
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
21
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
21
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
24
24
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -28,6 +28,7 @@ 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',
|
|
31
32
|
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'error',
|
|
32
33
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'error',
|
|
33
34
|
'@atlaskit/ui-styling-standard/no-unused-cssmap-properties': 'warn',
|
|
@@ -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
|
|
|
@@ -24,7 +24,7 @@ var config = {
|
|
|
24
24
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
25
25
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
27
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
27
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
29
29
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
30
30
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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
|
|
|
@@ -18,7 +18,7 @@ var config = {
|
|
|
18
18
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
19
19
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
21
|
-
'@atlaskit/ui-styling-standard/no-atlaskit-theme': '
|
|
21
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'error',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
24
24
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -20,13 +20,14 @@ 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"));
|
|
23
24
|
var _noUnsafeSelectors = _interopRequireDefault(require("./no-unsafe-selectors"));
|
|
24
25
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
25
26
|
var _noUnusedCssmapProperties = _interopRequireDefault(require("./no-unused-cssmap-properties"));
|
|
26
27
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
27
28
|
/**
|
|
28
29
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
29
|
-
* @codegen <<SignedSource::
|
|
30
|
+
* @codegen <<SignedSource::7b2b0662d0eeb0e3a3e4c844a505d27e>>
|
|
30
31
|
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
31
32
|
*/
|
|
32
33
|
|
|
@@ -46,6 +47,7 @@ var rules = exports.rules = {
|
|
|
46
47
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
47
48
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
48
49
|
'no-styled': _noStyled.default,
|
|
50
|
+
'no-top-layer-unsafe-selectors': _noTopLayerUnsafeSelectors.default,
|
|
49
51
|
'no-unsafe-selectors': _noUnsafeSelectors.default,
|
|
50
52
|
'no-unsafe-values': _noUnsafeValues.default,
|
|
51
53
|
'no-unused-cssmap-properties': _noUnusedCssmapProperties.default,
|
|
@@ -11,7 +11,7 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
11
11
|
docs: {
|
|
12
12
|
description: 'Disallow imports from `@atlaskit/theme`',
|
|
13
13
|
recommended: true,
|
|
14
|
-
severity: '
|
|
14
|
+
severity: 'error'
|
|
15
15
|
},
|
|
16
16
|
messages: {
|
|
17
17
|
'no-atlaskit-theme': 'Do not import `@atlaskit/theme`. Use `@atlaskit/tokens` or Atlassian Design System components instead.'
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findTemplateSelectors = findTemplateSelectors;
|
|
7
|
+
/**
|
|
8
|
+
* Locate the selectors inside a tagged template literal's raw source text.
|
|
9
|
+
*
|
|
10
|
+
* The style-call index only sees call expressions, so `styled.div\`…\`` and `css\`…\`` are
|
|
11
|
+
* invisible to it. This scanner fills that gap: it walks the text between the template's
|
|
12
|
+
* backticks and returns the byte range of every selector, so ranges map 1:1 onto the file and
|
|
13
|
+
* can be handed straight to an ESLint fixer.
|
|
14
|
+
*
|
|
15
|
+
* It deliberately does not try to be a CSS parser. A selector is the text between the last
|
|
16
|
+
* `;`, `{` or `}` and the next `{`. Anything it mis-reads will either fail to parse as a
|
|
17
|
+
* selector — in which case `rewriteSelector` skips it — or be reported for review. What it
|
|
18
|
+
* must not do is mistake a `${…}` interpolation, a quoted string or a comment for CSS
|
|
19
|
+
* structure, so it steps over all three.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function findTemplateSelectors(source, offset) {
|
|
23
|
+
var found = [];
|
|
24
|
+
var segmentStart = 0;
|
|
25
|
+
/**
|
|
26
|
+
* Set when a comment appears after the segment's first non-whitespace character. A selector
|
|
27
|
+
* with a comment inside it — `& /* x */ > div` — cannot be replaced as one contiguous range
|
|
28
|
+
* without eating the comment, so it is skipped rather than mangled. A comment *before* the
|
|
29
|
+
* selector just moves `segmentStart` past it.
|
|
30
|
+
*/
|
|
31
|
+
var commentInsideSegment = false;
|
|
32
|
+
/**
|
|
33
|
+
* How many `(` are open. Inside a function's parentheses `//` is data, not a comment:
|
|
34
|
+
* `url(//cdn.example.com/a.png)` and an unquoted data URI both carry one.
|
|
35
|
+
*/
|
|
36
|
+
var parenthesisDepth = 0;
|
|
37
|
+
/**
|
|
38
|
+
* How many CSS `{` are open. `${…}` braces and parentheses do not count.
|
|
39
|
+
*/
|
|
40
|
+
var braceDepth = 0;
|
|
41
|
+
/**
|
|
42
|
+
* The brace depth at which a `@keyframes` block opened, or `null` outside one. Everything
|
|
43
|
+
* nested inside is an offset (`from`, `50%`), not a selector — each parses as a tag selector,
|
|
44
|
+
* so without this the guard is written onto a keyframe and the animation stops. Skipping the
|
|
45
|
+
* at-rule's own prelude is not enough, because the block's contents open their own segments.
|
|
46
|
+
*/
|
|
47
|
+
var keyframesDepth = null;
|
|
48
|
+
var startSegment = function startSegment(at) {
|
|
49
|
+
segmentStart = at;
|
|
50
|
+
commentInsideSegment = false;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Step over a comment spanning `[start, end)`. A comment before the segment's first
|
|
55
|
+
* non-whitespace character just moves the segment past it; a comment inside the segment
|
|
56
|
+
* marks it unfixable. Returns the index to resume scanning at.
|
|
57
|
+
*/
|
|
58
|
+
var skipComment = function skipComment(start, end) {
|
|
59
|
+
var isLeading = source.slice(segmentStart, start).trim() === '';
|
|
60
|
+
if (isLeading) {
|
|
61
|
+
segmentStart = end;
|
|
62
|
+
} else {
|
|
63
|
+
commentInsideSegment = true;
|
|
64
|
+
}
|
|
65
|
+
return end;
|
|
66
|
+
};
|
|
67
|
+
for (var index = 0; index < source.length; index++) {
|
|
68
|
+
var character = source[index];
|
|
69
|
+
|
|
70
|
+
/* Step over a quoted string — `content: "{"` must not open a block. */
|
|
71
|
+
if (character === '"' || character === "'") {
|
|
72
|
+
index = skipQuoted(source, index);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (character === '/' && source[index + 1] === '*') {
|
|
76
|
+
var close = source.indexOf('*/', index + 2);
|
|
77
|
+
var end = close === -1 ? source.length : close + 2;
|
|
78
|
+
index = skipComment(index, end) - 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A `//` line comment. Emotion and styled-components strip these before the CSS is
|
|
84
|
+
* parsed, so a selector written after one on the next line is real. Inside parentheses
|
|
85
|
+
* the same two characters are part of a URL, so the depth check keeps them.
|
|
86
|
+
*/
|
|
87
|
+
if (character === '/' && source[index + 1] === '/' && parenthesisDepth === 0) {
|
|
88
|
+
var newline = source.indexOf('\n', index + 2);
|
|
89
|
+
var _end = newline === -1 ? source.length : newline + 1;
|
|
90
|
+
index = skipComment(index, _end) - 1;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (character === '(') {
|
|
94
|
+
parenthesisDepth++;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (character === ')') {
|
|
98
|
+
parenthesisDepth = Math.max(0, parenthesisDepth - 1);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Step over a `${…}` interpolation. Its braces are not CSS braces, but the `${…}` text
|
|
103
|
+
* itself stays in the segment so the transform can recognise the selector as dynamic. */
|
|
104
|
+
if (character === '{' && index > 0 && source[index - 1] === '$') {
|
|
105
|
+
var isLeading = source.slice(segmentStart, index - 1).trim() === '';
|
|
106
|
+
index = skipInterpolation(source, index);
|
|
107
|
+
/**
|
|
108
|
+
* A `${mixin}` alone on its line, with no `;` after it, is a statement of its own:
|
|
109
|
+
* the selector on the next line starts a fresh segment rather than inheriting the
|
|
110
|
+
* interpolation and being read as dynamic.
|
|
111
|
+
*/
|
|
112
|
+
if (isLeading && isRestOfLineBlank(source, index + 1)) {
|
|
113
|
+
startSegment(index + 1);
|
|
114
|
+
}
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (character === '{') {
|
|
118
|
+
var raw = source.slice(segmentStart, index);
|
|
119
|
+
var leading = raw.length - raw.trimStart().length;
|
|
120
|
+
var text = raw.trim();
|
|
121
|
+
|
|
122
|
+
/* At-rules are blocks but not selectors; the transform has nothing to say about them. */
|
|
123
|
+
if (text !== '' && !text.startsWith('@') && !commentInsideSegment && keyframesDepth === null) {
|
|
124
|
+
found.push({
|
|
125
|
+
text: text,
|
|
126
|
+
start: offset + segmentStart + leading,
|
|
127
|
+
end: offset + segmentStart + leading + text.length
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (keyframesDepth === null && /^@(-[a-z]+-)?keyframes\b/i.test(text)) {
|
|
131
|
+
keyframesDepth = braceDepth;
|
|
132
|
+
}
|
|
133
|
+
braceDepth++;
|
|
134
|
+
startSegment(index + 1);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (character === '}') {
|
|
138
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
139
|
+
if (keyframesDepth !== null && braceDepth <= keyframesDepth) {
|
|
140
|
+
keyframesDepth = null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (character === '}' || character === ';') {
|
|
144
|
+
startSegment(index + 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return found;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Is everything from `start` to the next newline whitespace? A missing newline does not count:
|
|
152
|
+
* `${selector}` at the very end has nothing after it to separate from.
|
|
153
|
+
*/
|
|
154
|
+
function isRestOfLineBlank(source, start) {
|
|
155
|
+
var newline = source.indexOf('\n', start);
|
|
156
|
+
return newline !== -1 && source.slice(start, newline).trim() === '';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Index of the quote closing the string that opens at `start`, or the end of the source when
|
|
161
|
+
* the string is unterminated.
|
|
162
|
+
*/
|
|
163
|
+
function skipQuoted(source, start) {
|
|
164
|
+
var quote = source[start];
|
|
165
|
+
var index = start + 1;
|
|
166
|
+
while (index < source.length) {
|
|
167
|
+
if (source[index] === '\\') {
|
|
168
|
+
index += 2;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (source[index] === quote) {
|
|
172
|
+
return index;
|
|
173
|
+
}
|
|
174
|
+
index++;
|
|
175
|
+
}
|
|
176
|
+
return source.length;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Index of the `}` closing the interpolation whose `{` is at `start`, or the end of the source
|
|
181
|
+
* when it is unterminated.
|
|
182
|
+
*
|
|
183
|
+
* The interpolation holds JavaScript, so a brace inside one of its string literals is not a
|
|
184
|
+
* brace: `${cond ? '}' : ''}` closes at the last character, not at the quoted one. Quoted
|
|
185
|
+
* strings and template literals are stepped over; a template literal may in turn hold its own
|
|
186
|
+
* interpolations, so the two skips call each other.
|
|
187
|
+
*/
|
|
188
|
+
function skipInterpolation(source, start) {
|
|
189
|
+
var depth = 1;
|
|
190
|
+
var index = start + 1;
|
|
191
|
+
while (index < source.length && depth > 0) {
|
|
192
|
+
var character = source[index];
|
|
193
|
+
if (character === '"' || character === "'") {
|
|
194
|
+
index = skipQuoted(source, index) + 1;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (character === '`') {
|
|
198
|
+
index = skipTemplateLiteral(source, index) + 1;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (character === '{') {
|
|
202
|
+
depth++;
|
|
203
|
+
} else if (character === '}') {
|
|
204
|
+
depth--;
|
|
205
|
+
}
|
|
206
|
+
index++;
|
|
207
|
+
}
|
|
208
|
+
return index - 1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Index of the backtick closing the template literal that opens at `start`, or the end of the
|
|
213
|
+
* source when it is unterminated.
|
|
214
|
+
*/
|
|
215
|
+
function skipTemplateLiteral(source, start) {
|
|
216
|
+
var index = start + 1;
|
|
217
|
+
while (index < source.length) {
|
|
218
|
+
if (source[index] === '\\') {
|
|
219
|
+
index += 2;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (source[index] === '`') {
|
|
223
|
+
return index;
|
|
224
|
+
}
|
|
225
|
+
if (source[index] === '$' && source[index + 1] === '{') {
|
|
226
|
+
index = skipInterpolation(source, index + 1) + 1;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
index++;
|
|
230
|
+
}
|
|
231
|
+
return source.length;
|
|
232
|
+
}
|