@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.
- package/CHANGELOG.md +13 -0
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +10 -3
- package/afm-jira/tsconfig.json +28 -0
- package/constellation/index/overview.mdx +29 -28
- package/constellation/no-unsafe-selectors/usage.mdx +244 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-unsafe-selectors/constants.js +30 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +185 -0
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +189 -0
- package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +42 -0
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +186 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-unsafe-selectors/constants.js +22 -0
- package/dist/es2019/rules/no-unsafe-selectors/index.js +173 -0
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +152 -0
- package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +31 -0
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +180 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-unsafe-selectors/constants.js +24 -0
- package/dist/esm/rules/no-unsafe-selectors/index.js +178 -0
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +182 -0
- package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +34 -0
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +179 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +23 -0
- package/dist/types/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +13 -0
- package/dist/types/rules/no-unsafe-selectors/source-position-utils.d.ts +20 -0
- package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/constants.d.ts +84 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +13 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/source-position-utils.d.ts +23 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
- package/package.json +6 -5
- package/scripts/codegen.tsx +3 -4
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/no-classname-prop/index.tsx +1 -1
- package/src/rules/no-nested-selectors/index.tsx +1 -1
- package/src/rules/no-unsafe-selectors/README.md +232 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +358 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +60 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +73 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +40 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +101 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +131 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +132 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +25 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +35 -0
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +238 -0
- package/src/rules/no-unsafe-selectors/constants.tsx +99 -0
- package/src/rules/no-unsafe-selectors/index.tsx +201 -0
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +168 -0
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +55 -0
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +232 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AST, Rule } from 'eslint';
|
|
2
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
3
|
+
import { type Node as SelectorNode } from 'postcss-selector-parser';
|
|
4
|
+
type Range = [number, number];
|
|
5
|
+
export declare function getRangeFromNode({ node, sourceNode, }: {
|
|
6
|
+
/**
|
|
7
|
+
* The selector AST node to get the range of.
|
|
8
|
+
*/
|
|
9
|
+
node: SelectorNode & {
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The source ESTree node whose value was parsed to obtain the selector AST.
|
|
14
|
+
*
|
|
15
|
+
* The range is calculated relative to this node's range.
|
|
16
|
+
*/
|
|
17
|
+
sourceNode: ESTree.Node;
|
|
18
|
+
}): Range;
|
|
19
|
+
export declare function getSourceLocationFromRange(context: Rule.RuleContext, [start, end]: Range): AST.SourceLocation;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This util is intentionally not in `@atlaskit/eslint-utils` at this time.
|
|
3
|
+
*
|
|
4
|
+
* This is because the API is likely to change and should not be considered stable.
|
|
5
|
+
*/
|
|
6
|
+
import type { Rule } from 'eslint';
|
|
7
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
8
|
+
type CssMapVisitorArgs = {
|
|
9
|
+
type: 'variant' | 'declaration' | 'ruleset' | 'selectors';
|
|
10
|
+
node: ESTree.Property;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'grouped-at-rules';
|
|
13
|
+
node: ESTree.Property;
|
|
14
|
+
atRule: string;
|
|
15
|
+
};
|
|
16
|
+
type CssMapVisitor = (args: CssMapVisitorArgs) => void;
|
|
17
|
+
export declare function walkCssMap({ context, importSources, visitor, }: {
|
|
18
|
+
context: Rule.RuleContext;
|
|
19
|
+
program: ESTree.Program;
|
|
20
|
+
importSources: string[];
|
|
21
|
+
visitor: CssMapVisitor;
|
|
22
|
+
}): void;
|
|
23
|
+
export {};
|
|
@@ -17,6 +17,7 @@ export declare const configs: {
|
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
20
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
21
22
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
22
23
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -58,6 +59,7 @@ export declare const configs: {
|
|
|
58
59
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
59
60
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
60
61
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
62
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
61
63
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
62
64
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
63
65
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -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::a4ab25dd4ce24b183125bfbc709e3943>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -20,6 +20,7 @@ declare const _default: {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -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::a4ab25dd4ce24b183125bfbc709e3943>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -20,6 +20,7 @@ declare const _default: {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -13,6 +13,7 @@ declare const _default: {
|
|
|
13
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
15
15
|
'no-styled': import("eslint").Rule.RuleModule;
|
|
16
|
+
'no-unsafe-selectors': import("eslint").Rule.RuleModule;
|
|
16
17
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
17
18
|
'use-compiled': import("eslint").Rule.RuleModule;
|
|
18
19
|
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { CSSPseudos } from '@compiled/react';
|
|
2
|
+
/**
|
|
3
|
+
* Validation approach from
|
|
4
|
+
* https://stackoverflow.com/a/71236280
|
|
5
|
+
*/
|
|
6
|
+
type Validate<T extends true> = T;
|
|
7
|
+
type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
|
|
8
|
+
infer Head,
|
|
9
|
+
...infer Tail
|
|
10
|
+
] ? Head extends Seen ? {
|
|
11
|
+
ERROR: [
|
|
12
|
+
'The following key appears more than once in the tuple:',
|
|
13
|
+
Head
|
|
14
|
+
];
|
|
15
|
+
} : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen> : [
|
|
16
|
+
Union
|
|
17
|
+
] extends [
|
|
18
|
+
never
|
|
19
|
+
] ? true : {
|
|
20
|
+
ERROR: [
|
|
21
|
+
'Some keys are missing from the tuple:',
|
|
22
|
+
Union
|
|
23
|
+
];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Exporting this so it isn't considered unused.
|
|
27
|
+
*/
|
|
28
|
+
export type _ = Validate<HasAllUnique<typeof cssPseudos, CSSPseudos>>;
|
|
29
|
+
declare const cssPseudos: readonly [
|
|
30
|
+
"&:active",
|
|
31
|
+
"&:autofill",
|
|
32
|
+
"&:blank",
|
|
33
|
+
"&:checked",
|
|
34
|
+
"&:default",
|
|
35
|
+
"&:defined",
|
|
36
|
+
"&:disabled",
|
|
37
|
+
"&:empty",
|
|
38
|
+
"&:enabled",
|
|
39
|
+
"&:first",
|
|
40
|
+
"&:focus",
|
|
41
|
+
"&:focus-visible",
|
|
42
|
+
"&:focus-within",
|
|
43
|
+
"&:fullscreen",
|
|
44
|
+
"&:hover",
|
|
45
|
+
"&:in-range",
|
|
46
|
+
"&:indeterminate",
|
|
47
|
+
"&:invalid",
|
|
48
|
+
"&:left",
|
|
49
|
+
"&:link",
|
|
50
|
+
"&:local-link",
|
|
51
|
+
"&:optional",
|
|
52
|
+
"&:out-of-range",
|
|
53
|
+
"&:paused",
|
|
54
|
+
"&:picture-in-picture",
|
|
55
|
+
"&:placeholder-shown",
|
|
56
|
+
"&:playing",
|
|
57
|
+
"&:read-only",
|
|
58
|
+
"&:read-write",
|
|
59
|
+
"&:required",
|
|
60
|
+
"&:right",
|
|
61
|
+
"&:target",
|
|
62
|
+
"&:user-invalid",
|
|
63
|
+
"&:user-valid",
|
|
64
|
+
"&:valid",
|
|
65
|
+
"&:visited",
|
|
66
|
+
"&::after",
|
|
67
|
+
"&::backdrop",
|
|
68
|
+
"&::before",
|
|
69
|
+
"&::cue",
|
|
70
|
+
"&::cue-region",
|
|
71
|
+
"&::first-letter",
|
|
72
|
+
"&::first-line",
|
|
73
|
+
"&::grammar-error",
|
|
74
|
+
"&::marker",
|
|
75
|
+
"&::placeholder",
|
|
76
|
+
"&::selection",
|
|
77
|
+
"&::spelling-error",
|
|
78
|
+
"&::target-text",
|
|
79
|
+
"&::view-transition"
|
|
80
|
+
];
|
|
81
|
+
export declare const allowedPseudos: Set<string>;
|
|
82
|
+
export declare const legacyPseudoElements: Set<string>;
|
|
83
|
+
export declare const ignoredAtRules: Set<string>;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
3
|
+
import { type Selector } from 'postcss-selector-parser';
|
|
4
|
+
type CheckArgs = {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
sourceNode: ESTree.Node;
|
|
7
|
+
selector: Selector;
|
|
8
|
+
config: {
|
|
9
|
+
shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function lintSelector(args: CheckArgs): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AST, Rule } from 'eslint';
|
|
2
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
3
|
+
import { type Node as SelectorNode } from 'postcss-selector-parser';
|
|
4
|
+
type Range = [
|
|
5
|
+
number,
|
|
6
|
+
number
|
|
7
|
+
];
|
|
8
|
+
export declare function getRangeFromNode({ node, sourceNode, }: {
|
|
9
|
+
/**
|
|
10
|
+
* The selector AST node to get the range of.
|
|
11
|
+
*/
|
|
12
|
+
node: SelectorNode & {
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The source ESTree node whose value was parsed to obtain the selector AST.
|
|
17
|
+
*
|
|
18
|
+
* The range is calculated relative to this node's range.
|
|
19
|
+
*/
|
|
20
|
+
sourceNode: ESTree.Node;
|
|
21
|
+
}): Range;
|
|
22
|
+
export declare function getSourceLocationFromRange(context: Rule.RuleContext, [start, end]: Range): AST.SourceLocation;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This util is intentionally not in `@atlaskit/eslint-utils` at this time.
|
|
3
|
+
*
|
|
4
|
+
* This is because the API is likely to change and should not be considered stable.
|
|
5
|
+
*/
|
|
6
|
+
import type { Rule } from 'eslint';
|
|
7
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
8
|
+
type CssMapVisitorArgs = {
|
|
9
|
+
type: 'variant' | 'declaration' | 'ruleset' | 'selectors';
|
|
10
|
+
node: ESTree.Property;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'grouped-at-rules';
|
|
13
|
+
node: ESTree.Property;
|
|
14
|
+
atRule: string;
|
|
15
|
+
};
|
|
16
|
+
type CssMapVisitor = (args: CssMapVisitorArgs) => void;
|
|
17
|
+
export declare function walkCssMap({ context, importSources, visitor, }: {
|
|
18
|
+
context: Rule.RuleContext;
|
|
19
|
+
program: ESTree.Program;
|
|
20
|
+
importSources: string[];
|
|
21
|
+
visitor: CssMapVisitor;
|
|
22
|
+
}): void;
|
|
23
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
".": "./src/index.tsx"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@atlaskit/eslint-utils": "^1.
|
|
42
|
+
"@atlaskit/eslint-utils": "^1.5.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@typescript-eslint/utils": "^5.48.1",
|
|
45
45
|
"ajv": "^6.12.6",
|
|
@@ -47,19 +47,20 @@
|
|
|
47
47
|
"eslint-scope": "^8.0.0",
|
|
48
48
|
"esquery": "^1.5.0",
|
|
49
49
|
"estraverse": "^5.3.0",
|
|
50
|
-
"
|
|
50
|
+
"json-schema-to-ts": "^3.1.0",
|
|
51
|
+
"outdent": "^0.5.0",
|
|
52
|
+
"postcss-selector-parser": "^6.0.16"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@af/formatting": "*",
|
|
54
56
|
"@atlaskit/ds-lib": "^2.3.0",
|
|
55
|
-
"@atlaskit/eslint-plugin-design-system": "^10.
|
|
57
|
+
"@atlaskit/eslint-plugin-design-system": "^10.4.0",
|
|
56
58
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
57
59
|
"@atlassian/codegen": "*",
|
|
58
60
|
"@compiled/eslint-plugin": "^0.13.6",
|
|
59
61
|
"@types/eslint": "^8.56.6",
|
|
60
62
|
"@types/estraverse": "^5.1.7",
|
|
61
63
|
"eslint": "^8.49.0",
|
|
62
|
-
"json-schema-to-ts": "^3.1.0",
|
|
63
64
|
"lodash": "^4.17.21",
|
|
64
65
|
"ts-node": "^10.9.1",
|
|
65
66
|
"tsconfig-paths": "^4.2.0",
|
package/scripts/codegen.tsx
CHANGED
|
@@ -18,7 +18,8 @@ import {
|
|
|
18
18
|
} from '../src/rules/external-rules';
|
|
19
19
|
|
|
20
20
|
const packagePluginName = '@atlaskit/eslint-plugin-ui-styling-standard';
|
|
21
|
-
const pluginName =
|
|
21
|
+
const pluginName = '@atlaskit/ui-styling-standard';
|
|
22
|
+
const pluginPath = 'eslint-plugin-ui-styling-standard';
|
|
22
23
|
const codegenCommand = `yarn workspace ${packagePluginName} codegen`;
|
|
23
24
|
|
|
24
25
|
interface FoundRule {
|
|
@@ -298,9 +299,7 @@ async function generateRuleTable(
|
|
|
298
299
|
let docsPath: string | undefined;
|
|
299
300
|
|
|
300
301
|
if (linkTo === 'docs') {
|
|
301
|
-
|
|
302
|
-
// to resolve to `/components/eslint-plugin-design-system/consistent-css-prop-usage/usage`
|
|
303
|
-
docsPath = `${rule.pathSafeName}/usage`;
|
|
302
|
+
docsPath = `/components/${pluginPath}/${rule.pathSafeName}/usage`;
|
|
304
303
|
} else if (ruleIsInternal(rule)) {
|
|
305
304
|
const result = await ruleDocsPath(rule.pathSafeName);
|
|
306
305
|
docsPath = result.path;
|
|
@@ -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::a4ab25dd4ce24b183125bfbc709e3943>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -20,6 +20,7 @@ export default {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
@@ -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::a4ab25dd4ce24b183125bfbc709e3943>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -20,6 +20,7 @@ export default {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
@@ -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::c907cf4b4e11348239dadaefebe80fca>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -17,6 +17,7 @@ import noImportantStyles from './no-important-styles';
|
|
|
17
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
18
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
19
|
import noStyled from './no-styled';
|
|
20
|
+
import noUnsafeSelectors from './no-unsafe-selectors';
|
|
20
21
|
import noUnsafeValues from './no-unsafe-values';
|
|
21
22
|
import useCompiled from './use-compiled';
|
|
22
23
|
|
|
@@ -35,6 +36,7 @@ export default {
|
|
|
35
36
|
'no-imported-style-values': noImportedStyleValues,
|
|
36
37
|
'no-nested-selectors': noNestedSelectors,
|
|
37
38
|
'no-styled': noStyled,
|
|
39
|
+
'no-unsafe-selectors': noUnsafeSelectors,
|
|
38
40
|
'no-unsafe-values': noUnsafeValues,
|
|
39
41
|
'use-compiled': useCompiled,
|
|
40
42
|
};
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getImportSources,
|
|
8
8
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
9
9
|
import { createLintRule } from '../utils/create-rule';
|
|
10
|
-
import { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
10
|
+
import { type JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
11
11
|
|
|
12
12
|
const schema: JSONSchema4 = [
|
|
13
13
|
{
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Disallows unsafe selectors in CSS-in-JS style objects.
|
|
2
|
+
|
|
3
|
+
This enables static analysis and prevents regressions and incidents when migrating between styling APIs.
|
|
4
|
+
|
|
5
|
+
Use this rule alongside [no-nested-selectors](https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-nested-selectors/usage) as the rules are complementary.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
**No @keyframes at-rules**
|
|
12
|
+
|
|
13
|
+
Use the `keyframes` CSS-in-JS API instead.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
css({
|
|
17
|
+
'@keyframes fadeIn': {
|
|
18
|
+
from: {
|
|
19
|
+
opacity: 0,
|
|
20
|
+
},
|
|
21
|
+
to: {
|
|
22
|
+
opacity: 1,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**No legacy pseudo-element syntax**
|
|
29
|
+
|
|
30
|
+
Use the `::` double colon syntax for pseudo-elements.
|
|
31
|
+
|
|
32
|
+
_Auto-fixer is available for this violation._
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
css({
|
|
36
|
+
':after': {
|
|
37
|
+
content: '""',
|
|
38
|
+
width: 100,
|
|
39
|
+
height: 100,
|
|
40
|
+
backgroundColor: 'red',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**No increased specificity selectors**
|
|
46
|
+
|
|
47
|
+
Use styles that do not require increased specificity.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
css({
|
|
51
|
+
'&&': {
|
|
52
|
+
color: 'red',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**No restricted at-rules**
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
css({
|
|
61
|
+
'@scope (.article-body) to (figure)': {
|
|
62
|
+
img: {
|
|
63
|
+
display: 'block',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**No restricted pseudos**
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
css({
|
|
73
|
+
'&:first-child': {
|
|
74
|
+
width: 100,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**No ambiguous pseudos**
|
|
80
|
+
|
|
81
|
+
A pseudo-selector without a leading selector is ambiguous and is interpreted differently between contexts.
|
|
82
|
+
|
|
83
|
+
Most CSS-in-JS libraries will implicitly add the nesting selector `&` before ambiguous pseudo-selectors. This is often the desired behavior.
|
|
84
|
+
|
|
85
|
+
The CSS nesting specification, CSS pre-processors, newer versions of `styled-components` (version 6+) and potentially future versions of `@emotion/*` will treat ambiguous pseudo-selectors as descendant selectors.
|
|
86
|
+
|
|
87
|
+
Use explicit selectors. Do not rely on implicit behavior for pseudo-selectors.
|
|
88
|
+
|
|
89
|
+
_Auto-fixer is available for this violation. By default a nesting selector `&` is added unless the `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos` option is disabled._
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
css({
|
|
93
|
+
/**
|
|
94
|
+
* This pseudo-class has no leading selector and is ambiguous.
|
|
95
|
+
*/
|
|
96
|
+
':hover': {},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* In some contexts the above is treated as implicitly containing a nesting selector.
|
|
100
|
+
*/
|
|
101
|
+
'&:hover': {},
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* In other contexts it is treated as a descendant selector.
|
|
105
|
+
*
|
|
106
|
+
* (The selectors below are equivalent.)
|
|
107
|
+
*/
|
|
108
|
+
'*:hover': {},
|
|
109
|
+
'& :hover': {},
|
|
110
|
+
'& *:hover': {},
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**No grouped at-rules**
|
|
115
|
+
|
|
116
|
+
Do not group at-rules with the `cssMap` API.
|
|
117
|
+
|
|
118
|
+
Write flattened at-rules instead.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
cssMap({
|
|
122
|
+
success: {
|
|
123
|
+
'@media': {
|
|
124
|
+
'(min-width: 900px)': {},
|
|
125
|
+
'(min-width: 1200px)': {},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**No selectors object**
|
|
132
|
+
|
|
133
|
+
Do not use a selectors object with the `cssMap` API.
|
|
134
|
+
|
|
135
|
+
Refactor your styles so it is not required.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
cssMap({
|
|
139
|
+
success: {
|
|
140
|
+
selectors: {
|
|
141
|
+
'&:not(:active)': {
|
|
142
|
+
backgroundColor: 'white',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Correct
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const fadeIn = keyframes({
|
|
153
|
+
from: {
|
|
154
|
+
opacity: 0,
|
|
155
|
+
},
|
|
156
|
+
to: {
|
|
157
|
+
opacity: 1,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
css({
|
|
162
|
+
animationName: fadeIn,
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
css({
|
|
168
|
+
'::after': {
|
|
169
|
+
content: '""',
|
|
170
|
+
width: 100,
|
|
171
|
+
height: 100,
|
|
172
|
+
backgroundColor: 'red',
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
css({
|
|
179
|
+
'&:first-of-type': {
|
|
180
|
+
width: 100,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
css({
|
|
187
|
+
'&:hover': {},
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
cssMap({
|
|
193
|
+
success: {
|
|
194
|
+
'@media (min-width: 900px)': {},
|
|
195
|
+
'@media (min-width: 1200px)': {},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
cssMap({
|
|
202
|
+
success: {
|
|
203
|
+
backgroundColor: 'white',
|
|
204
|
+
'&:active': {
|
|
205
|
+
backgroundColor: 'green',
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Options
|
|
212
|
+
|
|
213
|
+
### `importSources: string[]`
|
|
214
|
+
|
|
215
|
+
By default, this rule will check `css` usages from:
|
|
216
|
+
|
|
217
|
+
- `@atlaskit/css`
|
|
218
|
+
- `@atlaskit/primitives`
|
|
219
|
+
- `@compiled/react`
|
|
220
|
+
- `@emotion/react`
|
|
221
|
+
- `@emotion/core`
|
|
222
|
+
- `@emotion/styled`
|
|
223
|
+
- `styled-components`
|
|
224
|
+
|
|
225
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
226
|
+
This will override the built-in allow-list.
|
|
227
|
+
|
|
228
|
+
### `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean`
|
|
229
|
+
|
|
230
|
+
By default this rule will always fix ambiguous pseudo-selectors by inserting a leading `&` (nesting selector).
|
|
231
|
+
|
|
232
|
+
Set `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos` to `false` to disable this auto-fix. When disabled, a suggestion will be provided instead of an auto-fix.
|