@atlaskit/eslint-plugin-ui-styling-standard 0.14.2 → 0.15.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -0
  3. package/afm-cc/tsconfig.json +10 -3
  4. package/afm-jira/tsconfig.json +28 -0
  5. package/constellation/index/overview.mdx +29 -28
  6. package/constellation/no-unsafe-selectors/usage.mdx +244 -0
  7. package/dist/cjs/presets/all.codegen.js +2 -1
  8. package/dist/cjs/presets/recommended.codegen.js +2 -1
  9. package/dist/cjs/rules/index.codegen.js +3 -1
  10. package/dist/cjs/rules/no-unsafe-selectors/constants.js +30 -0
  11. package/dist/cjs/rules/no-unsafe-selectors/index.js +185 -0
  12. package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +189 -0
  13. package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +42 -0
  14. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +186 -0
  15. package/dist/es2019/presets/all.codegen.js +2 -1
  16. package/dist/es2019/presets/recommended.codegen.js +2 -1
  17. package/dist/es2019/rules/index.codegen.js +3 -1
  18. package/dist/es2019/rules/no-unsafe-selectors/constants.js +22 -0
  19. package/dist/es2019/rules/no-unsafe-selectors/index.js +173 -0
  20. package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +152 -0
  21. package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +31 -0
  22. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +180 -0
  23. package/dist/esm/presets/all.codegen.js +2 -1
  24. package/dist/esm/presets/recommended.codegen.js +2 -1
  25. package/dist/esm/rules/index.codegen.js +3 -1
  26. package/dist/esm/rules/no-unsafe-selectors/constants.js +24 -0
  27. package/dist/esm/rules/no-unsafe-selectors/index.js +178 -0
  28. package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +182 -0
  29. package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +34 -0
  30. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +179 -0
  31. package/dist/types/index.codegen.d.ts +2 -0
  32. package/dist/types/presets/all.codegen.d.ts +2 -1
  33. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  34. package/dist/types/rules/index.codegen.d.ts +1 -0
  35. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +23 -0
  36. package/dist/types/rules/no-unsafe-selectors/index.d.ts +3 -0
  37. package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +13 -0
  38. package/dist/types/rules/no-unsafe-selectors/source-position-utils.d.ts +20 -0
  39. package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
  40. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  41. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  42. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  43. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  44. package/dist/types-ts4.5/rules/no-unsafe-selectors/constants.d.ts +84 -0
  45. package/dist/types-ts4.5/rules/no-unsafe-selectors/index.d.ts +3 -0
  46. package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +13 -0
  47. package/dist/types-ts4.5/rules/no-unsafe-selectors/source-position-utils.d.ts +23 -0
  48. package/dist/types-ts4.5/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
  49. package/package.json +6 -5
  50. package/scripts/codegen.tsx +3 -4
  51. package/src/presets/all.codegen.tsx +2 -1
  52. package/src/presets/recommended.codegen.tsx +2 -1
  53. package/src/rules/index.codegen.tsx +3 -1
  54. package/src/rules/no-classname-prop/index.tsx +1 -1
  55. package/src/rules/no-nested-selectors/index.tsx +1 -1
  56. package/src/rules/no-unsafe-selectors/README.md +232 -0
  57. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +358 -0
  58. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +60 -0
  59. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +73 -0
  60. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +40 -0
  61. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +101 -0
  62. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +131 -0
  63. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +132 -0
  64. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +25 -0
  65. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +35 -0
  66. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +238 -0
  67. package/src/rules/no-unsafe-selectors/constants.tsx +99 -0
  68. package/src/rules/no-unsafe-selectors/index.tsx +201 -0
  69. package/src/rules/no-unsafe-selectors/lint-selector.tsx +168 -0
  70. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +55 -0
  71. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +232 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#100969](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100969)
8
+ [`0bdf8e822b2f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0bdf8e822b2f) -
9
+ Added `no-unsafe-selectors` rule to enable static analysis and prevent regressions when
10
+ migrating between styling APIs.
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 0.14.2
4
17
 
5
18
  ### Patch Changes
package/README.md CHANGED
@@ -56,6 +56,7 @@ module.exports = {
56
56
  | <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
57
57
  | <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
58
58
  | <a href="./src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
59
+ | <a href="./src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
59
60
  | <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
60
61
  | <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
61
62
  | <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 | |
@@ -2,10 +2,13 @@
2
2
  "extends": "../../../../tsconfig.entry-points.confluence.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
+ "lib": [
6
+ "ES2021.String"
7
+ ],
8
+ "composite": true,
5
9
  "outDir": "../dist",
6
10
  "rootDir": "../",
7
- "baseUrl": "../",
8
- "composite": true
11
+ "baseUrl": "../"
9
12
  },
10
13
  "include": [
11
14
  "../src/**/*.ts",
@@ -17,5 +20,9 @@
17
20
  "../src/**/*.test.*",
18
21
  "../src/**/test.*"
19
22
  ],
20
- "references": []
23
+ "references": [
24
+ {
25
+ "path": "../../eslint-utils/afm-cc/tsconfig.json"
26
+ }
27
+ ]
21
28
  }
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": "../../../../tsconfig.products.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "lib": [
6
+ "ES2021.String"
7
+ ],
8
+ "outDir": "../../../../../tsDist/@atlaskit__eslint-plugin-ui-styling-standard/app",
9
+ "composite": true,
10
+ "rootDir": "../",
11
+ "baseUrl": "../"
12
+ },
13
+ "include": [
14
+ "../src/**/*.ts",
15
+ "../src/**/*.tsx"
16
+ ],
17
+ "exclude": [
18
+ "../src/**/__tests__/*",
19
+ "../__tests__/*",
20
+ "../src/**/*.test.*",
21
+ "../src/**/test.*"
22
+ ],
23
+ "references": [
24
+ {
25
+ "path": "../../eslint-utils/afm-jira/tsconfig.json"
26
+ }
27
+ ]
28
+ }
@@ -9,34 +9,35 @@ but more are planned to support the standard over time.
9
9
  <!-- START_RULE_TABLE_CODEGEN -->
10
10
  <!-- @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen -->
11
11
 
12
- | Rule | Description | Recommended | Fixable | Suggestions |
13
- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
14
- | <a href="atlaskit-theme/usage">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
15
- | <a href="convert-props-syntax/usage">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 | |
16
- | <a href="enforce-style-prop/usage">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
17
- | <a href="local-cx-xcss/usage">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 | | |
18
- | <a href="no-array-arguments/usage">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
19
- | <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
20
- | <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
21
- | <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
22
- | <a href="no-exported-styles/usage">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
23
- | <a href="no-global-styles/usage">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
24
- | <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
25
- | <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
26
- | <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
27
- | <a href="no-styled/usage">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
28
- | <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
29
- | <a href="use-compiled/usage">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
30
- | <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
31
- | <a href="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 | |
32
- | <a href="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 | |
33
- | <a href="no-styled-tagged-template-expression/usage">@atlaskit/design-system/no-styled-tagged-template-expression</a> | Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
34
- | <a href="no-suppress-xcss/usage">@compiled/no-suppress-xcss</a> | Disallows supressing type violations when using the xcss prop. | Yes | | |
35
- | <a href="no-js-xcss/usage">@compiled/no-js-xcss</a> | Disallows using xcss prop inside JavaScript files. | Yes | | |
36
- | <a href="no-empty-styled-expression/usage">@atlaskit/design-system/no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | Yes | | |
37
- | <a href="no-exported-css/usage">@atlaskit/design-system/no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
38
- | <a href="no-exported-keyframes/usage">@atlaskit/design-system/no-exported-keyframes</a> | Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
39
- | <a href="no-invalid-css-map/usage">@atlaskit/design-system/no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
12
+ | Rule | Description | Recommended | Fixable | Suggestions |
13
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
14
+ | <a href="/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
15
+ | <a href="/components/eslint-plugin-ui-styling-standard/convert-props-syntax/usage">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 | |
16
+ | <a href="/components/eslint-plugin-ui-styling-standard/enforce-style-prop/usage">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
17
+ | <a href="/components/eslint-plugin-ui-styling-standard/local-cx-xcss/usage">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 | | |
18
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-array-arguments/usage">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
19
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
20
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
21
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
22
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-exported-styles/usage">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
23
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-global-styles/usage">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
24
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
25
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
26
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
27
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-styled/usage">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
28
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-unsafe-selectors/usage">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
29
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
30
+ | <a href="/components/eslint-plugin-ui-styling-standard/use-compiled/usage">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
31
+ | <a href="/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 | |
32
+ | <a href="/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 | |
33
+ | <a href="/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 | |
34
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-styled-tagged-template-expression/usage">@atlaskit/design-system/no-styled-tagged-template-expression</a> | Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
35
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-suppress-xcss/usage">@compiled/no-suppress-xcss</a> | Disallows supressing type violations when using the xcss prop. | Yes | | |
36
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-js-xcss/usage">@compiled/no-js-xcss</a> | Disallows using xcss prop inside JavaScript files. | Yes | | |
37
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-empty-styled-expression/usage">@atlaskit/design-system/no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | Yes | | |
38
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-exported-css/usage">@atlaskit/design-system/no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
39
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-exported-keyframes/usage">@atlaskit/design-system/no-exported-keyframes</a> | Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
40
+ | <a href="/components/eslint-plugin-ui-styling-standard/no-invalid-css-map/usage">@atlaskit/design-system/no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
40
41
 
41
42
  <!-- END_RULE_TABLE_CODEGEN -->
42
43
 
@@ -0,0 +1,244 @@
1
+ # no-unsafe-selectors
2
+
3
+ Disallows unsafe selectors in CSS-in-JS style objects.
4
+
5
+ This enables static analysis and prevents regressions and incidents when migrating between styling
6
+ APIs.
7
+
8
+ Use this rule alongside
9
+ [no-nested-selectors](https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-nested-selectors/usage)
10
+ as the rules are complementary.
11
+
12
+ ## Examples
13
+
14
+ ### Incorrect
15
+
16
+ **No @keyframes at-rules**
17
+
18
+ Use the `keyframes` CSS-in-JS API instead.
19
+
20
+ ```ts
21
+ css({
22
+ '@keyframes fadeIn': {
23
+ from: {
24
+ opacity: 0,
25
+ },
26
+ to: {
27
+ opacity: 1,
28
+ },
29
+ },
30
+ });
31
+ ```
32
+
33
+ **No legacy pseudo-element syntax**
34
+
35
+ Use the `::` double colon syntax for pseudo-elements.
36
+
37
+ _Auto-fixer is available for this violation._
38
+
39
+ ```ts
40
+ css({
41
+ ':after': {
42
+ content: '""',
43
+ width: 100,
44
+ height: 100,
45
+ backgroundColor: 'red',
46
+ },
47
+ });
48
+ ```
49
+
50
+ **No increased specificity selectors**
51
+
52
+ Use styles that do not require increased specificity.
53
+
54
+ ```ts
55
+ css({
56
+ '&&': {
57
+ color: 'red',
58
+ },
59
+ });
60
+ ```
61
+
62
+ **No restricted at-rules**
63
+
64
+ ```ts
65
+ css({
66
+ '@scope (.article-body) to (figure)': {
67
+ img: {
68
+ display: 'block',
69
+ },
70
+ },
71
+ });
72
+ ```
73
+
74
+ **No restricted pseudos**
75
+
76
+ ```ts
77
+ css({
78
+ '&:first-child': {
79
+ width: 100,
80
+ },
81
+ });
82
+ ```
83
+
84
+ **No ambiguous pseudos**
85
+
86
+ A pseudo-selector without a leading selector is ambiguous and is interpreted differently between
87
+ contexts.
88
+
89
+ Most CSS-in-JS libraries will implicitly add the nesting selector `&` before ambiguous
90
+ pseudo-selectors. This is often the desired behavior.
91
+
92
+ The CSS nesting specification, CSS pre-processors, newer versions of `styled-components` (version
93
+ 6+) and potentially future versions of `@emotion/*` will treat ambiguous pseudo-selectors as
94
+ descendant selectors.
95
+
96
+ Use explicit selectors. Do not rely on implicit behavior for pseudo-selectors.
97
+
98
+ _Auto-fixer is available for this violation. By default a nesting selector `&` is added unless the
99
+ `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos` option is disabled._
100
+
101
+ ```ts
102
+ css({
103
+ /**
104
+ * This pseudo-class has no leading selector and is ambiguous.
105
+ */
106
+ ':hover': {},
107
+
108
+ /**
109
+ * In some contexts the above is treated as implicitly containing a nesting selector.
110
+ */
111
+ '&:hover': {},
112
+
113
+ /**
114
+ * In other contexts it is treated as a descendant selector.
115
+ *
116
+ * (The selectors below are equivalent.)
117
+ */
118
+ '*:hover': {},
119
+ '& :hover': {},
120
+ '& *:hover': {},
121
+ });
122
+ ```
123
+
124
+ **No grouped at-rules**
125
+
126
+ Do not group at-rules with the `cssMap` API.
127
+
128
+ Write flattened at-rules instead.
129
+
130
+ ```ts
131
+ cssMap({
132
+ success: {
133
+ '@media': {
134
+ '(min-width: 900px)': {},
135
+ '(min-width: 1200px)': {},
136
+ },
137
+ },
138
+ });
139
+ ```
140
+
141
+ **No selectors object**
142
+
143
+ Do not use a selectors object with the `cssMap` API.
144
+
145
+ Refactor your styles so it is not required.
146
+
147
+ ```ts
148
+ cssMap({
149
+ success: {
150
+ selectors: {
151
+ '&:not(:active)': {
152
+ backgroundColor: 'white',
153
+ },
154
+ },
155
+ },
156
+ });
157
+ ```
158
+
159
+ ### Correct
160
+
161
+ ```ts
162
+ const fadeIn = keyframes({
163
+ from: {
164
+ opacity: 0,
165
+ },
166
+ to: {
167
+ opacity: 1,
168
+ },
169
+ });
170
+
171
+ css({
172
+ animationName: fadeIn,
173
+ });
174
+ ```
175
+
176
+ ```ts
177
+ css({
178
+ '::after': {
179
+ content: '""',
180
+ width: 100,
181
+ height: 100,
182
+ backgroundColor: 'red',
183
+ },
184
+ });
185
+ ```
186
+
187
+ ```ts
188
+ css({
189
+ '&:first-of-type': {
190
+ width: 100,
191
+ },
192
+ });
193
+ ```
194
+
195
+ ```ts
196
+ css({
197
+ '&:hover': {},
198
+ });
199
+ ```
200
+
201
+ ```ts
202
+ cssMap({
203
+ success: {
204
+ '@media (min-width: 900px)': {},
205
+ '@media (min-width: 1200px)': {},
206
+ },
207
+ });
208
+ ```
209
+
210
+ ```ts
211
+ cssMap({
212
+ success: {
213
+ backgroundColor: 'white',
214
+ '&:active': {
215
+ backgroundColor: 'green',
216
+ },
217
+ },
218
+ });
219
+ ```
220
+
221
+ ## Options
222
+
223
+ ### `importSources: string[]`
224
+
225
+ By default, this rule will check `css` usages from:
226
+
227
+ - `@atlaskit/css`
228
+ - `@atlaskit/primitives`
229
+ - `@compiled/react`
230
+ - `@emotion/react`
231
+ - `@emotion/core`
232
+ - `@emotion/styled`
233
+ - `styled-components`
234
+
235
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an
236
+ array of package names (strings). This will override the built-in allow-list.
237
+
238
+ ### `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean`
239
+
240
+ By default this rule will always fix ambiguous pseudo-selectors by inserting a leading `&` (nesting
241
+ selector).
242
+
243
+ Set `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos` to `false` to disable this auto-fix. When
244
+ disabled, a suggestion will be provided instead of an auto-fix.
@@ -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::40bdd5a27731185ba04e0b279fc81ac9>>
9
+ * @codegen <<SignedSource::a4ab25dd4ce24b183125bfbc709e3943>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -26,6 +26,7 @@ var _default = exports.default = {
26
26
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
27
27
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
28
28
  '@atlaskit/ui-styling-standard/no-styled': 'warn',
29
+ '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
29
30
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
30
31
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
31
32
  '@atlaskit/design-system/consistent-css-prop-usage': ['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::40bdd5a27731185ba04e0b279fc81ac9>>
9
+ * @codegen <<SignedSource::a4ab25dd4ce24b183125bfbc709e3943>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -26,6 +26,7 @@ var _default = exports.default = {
26
26
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
27
27
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
28
28
  '@atlaskit/ui-styling-standard/no-styled': 'warn',
29
+ '@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
29
30
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
30
31
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
31
32
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -19,11 +19,12 @@ var _noImportantStyles = _interopRequireDefault(require("./no-important-styles")
19
19
  var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
20
20
  var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
21
21
  var _noStyled = _interopRequireDefault(require("./no-styled"));
22
+ var _noUnsafeSelectors = _interopRequireDefault(require("./no-unsafe-selectors"));
22
23
  var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
23
24
  var _useCompiled = _interopRequireDefault(require("./use-compiled"));
24
25
  /**
25
26
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
26
- * @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
27
+ * @codegen <<SignedSource::c907cf4b4e11348239dadaefebe80fca>>
27
28
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
28
29
  */
29
30
  var _default = exports.default = {
@@ -41,6 +42,7 @@ var _default = exports.default = {
41
42
  'no-imported-style-values': _noImportedStyleValues.default,
42
43
  'no-nested-selectors': _noNestedSelectors.default,
43
44
  'no-styled': _noStyled.default,
45
+ 'no-unsafe-selectors': _noUnsafeSelectors.default,
44
46
  'no-unsafe-values': _noUnsafeValues.default,
45
47
  'use-compiled': _useCompiled.default
46
48
  };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.legacyPseudoElements = exports.ignoredAtRules = exports.allowedPseudos = void 0;
7
+ /**
8
+ * Validation approach from
9
+ * https://stackoverflow.com/a/71236280
10
+ */
11
+
12
+ /**
13
+ * Exporting this so it isn't considered unused.
14
+ */
15
+
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', '&: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'];
17
+ var allowedPseudos = exports.allowedPseudos = new Set(
18
+ /**
19
+ * The `&` is included above for type checking reasons,
20
+ * but we don't actually want it when consuming the values.
21
+ */
22
+ cssPseudos.map(function (pseudo) {
23
+ return pseudo.slice(1);
24
+ }));
25
+ var legacyPseudoElements = exports.legacyPseudoElements = new Set([':after', ':before', ':first-letter', ':first-line']);
26
+ var ignoredAtRules = exports.ignoredAtRules = new Set(['@container',
27
+ // ignored because it's covered by `no-container-queries`
28
+ '@media',
29
+ // ignored because it's covered by `no-nested-styles`
30
+ '@supports', '@property']);