@atlaskit/eslint-plugin-ui-styling-standard 0.15.1 → 0.16.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 +17 -0
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/dist/cjs/rules/no-nested-selectors/index.js +68 -49
- package/dist/es2019/rules/no-nested-selectors/index.js +63 -45
- package/dist/esm/rules/no-nested-selectors/index.js +64 -49
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +186 -149
- package/src/rules/no-nested-selectors/index.tsx +92 -105
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type: 'string'
|
|
10
|
-
},
|
|
11
|
-
uniqueItems: true
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}];
|
|
15
|
-
var getCssSelector = function getCssSelector(node) {
|
|
16
|
-
if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
|
|
17
|
-
return node.key.value;
|
|
1
|
+
import _toArray from "@babel/runtime/helpers/toArray";
|
|
2
|
+
import cssSelectorParser, { isNesting, isPseudo } from 'postcss-selector-parser';
|
|
3
|
+
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
4
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
5
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
6
|
+
var getCssSelector = function getCssSelector(key) {
|
|
7
|
+
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
8
|
+
return key.value;
|
|
18
9
|
}
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
10
|
+
if (key.type === 'Identifier' && typeof key.name === 'string') {
|
|
11
|
+
return key.name;
|
|
21
12
|
}
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
13
|
+
if (key.type === 'TemplateLiteral') {
|
|
14
|
+
return key.quasis.map(function (quasi) {
|
|
24
15
|
return quasi.value.raw;
|
|
25
16
|
}).join(' ');
|
|
26
17
|
}
|
|
27
18
|
return null;
|
|
28
19
|
};
|
|
29
|
-
|
|
20
|
+
function isAllowedSelector(selector) {
|
|
21
|
+
var _selector$nodes = _toArray(selector.nodes),
|
|
22
|
+
head = _selector$nodes[0],
|
|
23
|
+
tail = _selector$nodes.slice(1);
|
|
24
|
+
|
|
25
|
+
// The first node must be a nesting selector (`&`) or pseudo-selector.
|
|
26
|
+
var isHeadAllowed = isNesting(head) || isPseudo(head);
|
|
27
|
+
|
|
28
|
+
// All remaining nodes must be pseudo selectors.
|
|
29
|
+
var isTailAllowed = tail.every(isPseudo);
|
|
30
|
+
return isHeadAllowed && isTailAllowed;
|
|
31
|
+
}
|
|
32
|
+
var cssSelectorProcessor = cssSelectorParser();
|
|
33
|
+
export var rule = createLintRuleWithTypedConfig({
|
|
30
34
|
meta: {
|
|
31
35
|
name: 'no-nested-selectors',
|
|
32
36
|
docs: {
|
|
@@ -38,37 +42,48 @@ export var rule = createLintRule({
|
|
|
38
42
|
'no-nested-selectors': 'Please avoid setting styles for child elements or elements that require context from other elements.'
|
|
39
43
|
},
|
|
40
44
|
type: 'problem',
|
|
41
|
-
schema:
|
|
45
|
+
schema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
importSources: importSources
|
|
49
|
+
}
|
|
50
|
+
}
|
|
42
51
|
},
|
|
43
|
-
create: function create(context) {
|
|
44
|
-
var importSources =
|
|
52
|
+
create: function create(context, _ref) {
|
|
53
|
+
var importSources = _ref.importSources;
|
|
45
54
|
return {
|
|
46
|
-
|
|
55
|
+
CallExpression: function CallExpression(node) {
|
|
47
56
|
var _context$getScope = context.getScope(),
|
|
48
57
|
references = _context$getScope.references;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
walkStyleProperties(node, references, importSources, function (_ref2) {
|
|
59
|
+
var key = _ref2.key,
|
|
60
|
+
value = _ref2.value;
|
|
61
|
+
if (value.type !== 'ObjectExpression') {
|
|
62
|
+
// If the value is a CSS object, safe to assume we're at a CSS selector
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var selectorText = getCssSelector(key);
|
|
66
|
+
if (selectorText === null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Ignore at-rules
|
|
71
|
+
if (selectorText.includes('@')) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
var selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
76
|
+
if (!selectorList.nodes.every(isAllowedSelector)) {
|
|
77
|
+
context.report({
|
|
78
|
+
messageId: 'no-nested-selectors',
|
|
79
|
+
node: key
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
} catch (_) {
|
|
83
|
+
// If it is not parsable then `no-unsafe-selectors` will give it an error,
|
|
84
|
+
// we can ignore it here.
|
|
85
|
+
}
|
|
86
|
+
});
|
|
72
87
|
}
|
|
73
88
|
};
|
|
74
89
|
}
|
|
@@ -4,10 +4,7 @@ import type { CSSPseudos } from '@compiled/react';
|
|
|
4
4
|
* https://stackoverflow.com/a/71236280
|
|
5
5
|
*/
|
|
6
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 ? {
|
|
7
|
+
type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [infer Head, ...infer Tail] ? Head extends Seen ? {
|
|
11
8
|
ERROR: ['The following key appears more than once in the tuple:', Head];
|
|
12
9
|
} : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen> : [Union] extends [never] ? true : {
|
|
13
10
|
ERROR: ['Some keys are missing from the tuple:', Union];
|
package/index.js
CHANGED
|
@@ -6,19 +6,19 @@ const path = require('path');
|
|
|
6
6
|
const paths = require('tsconfig-paths');
|
|
7
7
|
|
|
8
8
|
if (!require.extensions['.ts']) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
|
|
10
|
+
require('ts-node').register({
|
|
11
|
+
project: path.join(__dirname, 'tsconfig.json'),
|
|
12
|
+
});
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// We programatically register tsconfig paths here so it picks up the tsconfig here
|
|
17
|
+
// instead of in root CWD.
|
|
18
|
+
paths.register(paths.loadConfig(__dirname));
|
|
19
19
|
} catch (e) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.log(e);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
module.exports = require('./src/index');
|
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.16.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.6.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@typescript-eslint/utils": "^5.48.1",
|
|
45
45
|
"ajv": "^6.12.6",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@af/formatting": "*",
|
|
56
56
|
"@atlaskit/ds-lib": "^2.3.0",
|
|
57
|
-
"@atlaskit/eslint-plugin-design-system": "^10.
|
|
57
|
+
"@atlaskit/eslint-plugin-design-system": "^10.6.0",
|
|
58
58
|
"@atlassian/codegen": "*",
|
|
59
59
|
"@compiled/eslint-plugin": "^0.13.6",
|
|
60
60
|
"@types/eslint": "^8.56.6",
|