@atlaskit/eslint-plugin-ui-styling-standard 0.15.0 → 0.15.2
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 +189 -172
- package/constellation/atlaskit-theme/usage.mdx +17 -17
- package/constellation/convert-props-syntax/usage.mdx +14 -14
- package/constellation/enforce-style-prop/usage.mdx +17 -17
- package/constellation/index/overview.mdx +70 -70
- package/constellation/local-cx-xcss/usage.mdx +4 -4
- package/constellation/no-array-arguments/usage.mdx +7 -7
- package/constellation/no-container-queries/usage.mdx +14 -14
- package/constellation/no-dynamic-styles/usage.mdx +19 -19
- package/constellation/no-exported-styles/usage.mdx +15 -15
- package/constellation/no-global-styles/usage.mdx +13 -13
- package/constellation/no-important-styles/usage.mdx +2 -2
- package/constellation/no-imported-style-values/usage.mdx +16 -16
- package/constellation/no-nested-selectors/usage.mdx +18 -18
- package/constellation/no-styled/usage.mdx +6 -6
- package/constellation/no-unsafe-selectors/usage.mdx +90 -90
- package/constellation/no-unsafe-values/usage.mdx +33 -33
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +1 -1
- package/dist/cjs/presets/recommended.codegen.js +1 -1
- package/dist/cjs/rules/index.codegen.js +1 -1
- package/dist/cjs/rules/no-nested-selectors/index.js +68 -49
- package/dist/cjs/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +1 -1
- package/dist/es2019/presets/recommended.codegen.js +1 -1
- package/dist/es2019/rules/index.codegen.js +1 -1
- package/dist/es2019/rules/no-nested-selectors/index.js +63 -45
- package/dist/es2019/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +1 -1
- package/dist/esm/presets/recommended.codegen.js +1 -1
- package/dist/esm/rules/index.codegen.js +1 -1
- package/dist/esm/rules/no-nested-selectors/index.js +64 -49
- package/dist/esm/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/presets/recommended.codegen.d.ts +1 -1
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
- package/package.json +2 -4
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +70 -73
- package/src/presets/recommended.codegen.tsx +70 -73
- package/src/rules/index.codegen.tsx +18 -18
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +93 -56
- package/src/rules/no-nested-selectors/index.tsx +92 -105
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +211 -201
- package/src/rules/no-unsafe-selectors/index.tsx +174 -177
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +128 -141
- package/tsconfig.app.json +45 -45
- package/tsconfig.dev.json +43 -43
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -24,7 +24,7 @@ var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
|
24
24
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
25
25
|
/**
|
|
26
26
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
27
|
-
* @codegen <<SignedSource::
|
|
27
|
+
* @codegen <<SignedSource::6ad0de2d4bdac726387f27681ad9fcf4>>
|
|
28
28
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
29
29
|
*/
|
|
30
30
|
var _default = exports.default = {
|
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.rule = exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
uniqueItems: true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}];
|
|
21
|
-
var getCssSelector = function getCssSelector(node) {
|
|
22
|
-
if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
|
|
23
|
-
return node.key.value;
|
|
9
|
+
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
10
|
+
var _postcssSelectorParser = _interopRequireWildcard(require("postcss-selector-parser"));
|
|
11
|
+
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
12
|
+
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
13
|
+
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
var getCssSelector = function getCssSelector(key) {
|
|
17
|
+
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
18
|
+
return key.value;
|
|
24
19
|
}
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
20
|
+
if (key.type === 'Identifier' && typeof key.name === 'string') {
|
|
21
|
+
return key.name;
|
|
27
22
|
}
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
23
|
+
if (key.type === 'TemplateLiteral') {
|
|
24
|
+
return key.quasis.map(function (quasi) {
|
|
30
25
|
return quasi.value.raw;
|
|
31
26
|
}).join(' ');
|
|
32
27
|
}
|
|
33
28
|
return null;
|
|
34
29
|
};
|
|
35
|
-
|
|
30
|
+
function isAllowedSelector(selector) {
|
|
31
|
+
var _selector$nodes = (0, _toArray2.default)(selector.nodes),
|
|
32
|
+
head = _selector$nodes[0],
|
|
33
|
+
tail = _selector$nodes.slice(1);
|
|
34
|
+
|
|
35
|
+
// The first node must be a nesting selector (`&`) or pseudo-selector.
|
|
36
|
+
var isHeadAllowed = (0, _postcssSelectorParser.isNesting)(head) || (0, _postcssSelectorParser.isPseudo)(head);
|
|
37
|
+
|
|
38
|
+
// All remaining nodes must be pseudo selectors.
|
|
39
|
+
var isTailAllowed = tail.every(_postcssSelectorParser.isPseudo);
|
|
40
|
+
return isHeadAllowed && isTailAllowed;
|
|
41
|
+
}
|
|
42
|
+
var cssSelectorProcessor = (0, _postcssSelectorParser.default)();
|
|
43
|
+
var rule = exports.rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
36
44
|
meta: {
|
|
37
45
|
name: 'no-nested-selectors',
|
|
38
46
|
docs: {
|
|
@@ -44,37 +52,48 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
44
52
|
'no-nested-selectors': 'Please avoid setting styles for child elements or elements that require context from other elements.'
|
|
45
53
|
},
|
|
46
54
|
type: 'problem',
|
|
47
|
-
schema:
|
|
55
|
+
schema: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
importSources: _schema.importSources
|
|
59
|
+
}
|
|
60
|
+
}
|
|
48
61
|
},
|
|
49
|
-
create: function create(context) {
|
|
50
|
-
var importSources =
|
|
62
|
+
create: function create(context, _ref) {
|
|
63
|
+
var importSources = _ref.importSources;
|
|
51
64
|
return {
|
|
52
|
-
|
|
65
|
+
CallExpression: function CallExpression(node) {
|
|
53
66
|
var _context$getScope = context.getScope(),
|
|
54
67
|
references = _context$getScope.references;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
(0, _walkStyleProperties.walkStyleProperties)(node, references, importSources, function (_ref2) {
|
|
69
|
+
var key = _ref2.key,
|
|
70
|
+
value = _ref2.value;
|
|
71
|
+
if (value.type !== 'ObjectExpression') {
|
|
72
|
+
// If the value is a CSS object, safe to assume we're at a CSS selector
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var selectorText = getCssSelector(key);
|
|
76
|
+
if (selectorText === null) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Ignore at-rules
|
|
81
|
+
if (selectorText.includes('@')) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
var selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
86
|
+
if (!selectorList.nodes.every(isAllowedSelector)) {
|
|
87
|
+
context.report({
|
|
88
|
+
messageId: 'no-nested-selectors',
|
|
89
|
+
node: key
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} catch (_) {
|
|
93
|
+
// If it is not parsable then `no-unsafe-selectors` will give it an error,
|
|
94
|
+
// we can ignore it here.
|
|
95
|
+
}
|
|
96
|
+
});
|
|
78
97
|
}
|
|
79
98
|
};
|
|
80
99
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
9
|
+
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
9
10
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
10
11
|
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
11
12
|
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
@@ -94,6 +95,7 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
94
95
|
}(function (node) {
|
|
95
96
|
var _context$getScope = context.getScope(),
|
|
96
97
|
references = _context$getScope.references;
|
|
98
|
+
var isXcssCall = (0, _isSupportedImport.isXcss)(node, references, config.importSources);
|
|
97
99
|
(0, _walkStyleProperties.walkStyleProperties)(node, references, config.importSources, function (_ref) {
|
|
98
100
|
var key = _ref.key,
|
|
99
101
|
value = _ref.value;
|
|
@@ -138,7 +140,8 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
138
140
|
context: context,
|
|
139
141
|
sourceNode: key,
|
|
140
142
|
selector: selector,
|
|
141
|
-
config: config
|
|
143
|
+
config: config,
|
|
144
|
+
isXcssCall: isXcssCall
|
|
142
145
|
});
|
|
143
146
|
});
|
|
144
147
|
} catch (e) {
|
|
@@ -24,7 +24,16 @@ function checkNoAmbiguousPseudos(_ref) {
|
|
|
24
24
|
var context = _ref.context,
|
|
25
25
|
sourceNode = _ref.sourceNode,
|
|
26
26
|
selector = _ref.selector,
|
|
27
|
-
config = _ref.config
|
|
27
|
+
config = _ref.config,
|
|
28
|
+
isXcssCall = _ref.isXcssCall;
|
|
29
|
+
if (isXcssCall) {
|
|
30
|
+
/**
|
|
31
|
+
* The `xcss` API does not currently support a leading `&`.
|
|
32
|
+
*
|
|
33
|
+
* This may change in the future, but we are ignoring `xcss` calls for now.
|
|
34
|
+
*/
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
28
37
|
if (selector.first.type !== 'pseudo') {
|
|
29
38
|
return;
|
|
30
39
|
}
|
|
@@ -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::aff3fad2b8534fad07ba5f0f1b981a55>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import all from './presets/all.codegen';
|
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -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::6ad0de2d4bdac726387f27681ad9fcf4>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
items: {
|
|
9
|
-
type: 'string'
|
|
10
|
-
},
|
|
11
|
-
uniqueItems: true
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}];
|
|
15
|
-
const getCssSelector = node => {
|
|
16
|
-
if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
|
|
17
|
-
return node.key.value;
|
|
1
|
+
import cssSelectorParser, { isNesting, isPseudo } from 'postcss-selector-parser';
|
|
2
|
+
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
3
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
4
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
5
|
+
const getCssSelector = key => {
|
|
6
|
+
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
7
|
+
return key.value;
|
|
18
8
|
}
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
9
|
+
if (key.type === 'Identifier' && typeof key.name === 'string') {
|
|
10
|
+
return key.name;
|
|
21
11
|
}
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
12
|
+
if (key.type === 'TemplateLiteral') {
|
|
13
|
+
return key.quasis.map(quasi => quasi.value.raw).join(' ');
|
|
24
14
|
}
|
|
25
15
|
return null;
|
|
26
16
|
};
|
|
27
|
-
|
|
17
|
+
function isAllowedSelector(selector) {
|
|
18
|
+
const [head, ...tail] = selector.nodes;
|
|
19
|
+
|
|
20
|
+
// The first node must be a nesting selector (`&`) or pseudo-selector.
|
|
21
|
+
const isHeadAllowed = isNesting(head) || isPseudo(head);
|
|
22
|
+
|
|
23
|
+
// All remaining nodes must be pseudo selectors.
|
|
24
|
+
const isTailAllowed = tail.every(isPseudo);
|
|
25
|
+
return isHeadAllowed && isTailAllowed;
|
|
26
|
+
}
|
|
27
|
+
const cssSelectorProcessor = cssSelectorParser();
|
|
28
|
+
export const rule = createLintRuleWithTypedConfig({
|
|
28
29
|
meta: {
|
|
29
30
|
name: 'no-nested-selectors',
|
|
30
31
|
docs: {
|
|
@@ -36,34 +37,51 @@ export const rule = createLintRule({
|
|
|
36
37
|
'no-nested-selectors': 'Please avoid setting styles for child elements or elements that require context from other elements.'
|
|
37
38
|
},
|
|
38
39
|
type: 'problem',
|
|
39
|
-
schema
|
|
40
|
+
schema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
importSources
|
|
44
|
+
}
|
|
45
|
+
}
|
|
40
46
|
},
|
|
41
|
-
create(context
|
|
42
|
-
|
|
47
|
+
create(context, {
|
|
48
|
+
importSources
|
|
49
|
+
}) {
|
|
43
50
|
return {
|
|
44
|
-
|
|
51
|
+
CallExpression(node) {
|
|
45
52
|
const {
|
|
46
53
|
references
|
|
47
54
|
} = context.getScope();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
walkStyleProperties(node, references, importSources, ({
|
|
56
|
+
key,
|
|
57
|
+
value
|
|
58
|
+
}) => {
|
|
59
|
+
if (value.type !== 'ObjectExpression') {
|
|
60
|
+
// If the value is a CSS object, safe to assume we're at a CSS selector
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const selectorText = getCssSelector(key);
|
|
64
|
+
if (selectorText === null) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Ignore at-rules
|
|
69
|
+
if (selectorText.includes('@')) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
74
|
+
if (!selectorList.nodes.every(isAllowedSelector)) {
|
|
75
|
+
context.report({
|
|
76
|
+
messageId: 'no-nested-selectors',
|
|
77
|
+
node: key
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
} catch (_) {
|
|
81
|
+
// If it is not parsable then `no-unsafe-selectors` will give it an error,
|
|
82
|
+
// we can ignore it here.
|
|
83
|
+
}
|
|
84
|
+
});
|
|
67
85
|
}
|
|
68
86
|
};
|
|
69
87
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cssSelectorParser from 'postcss-selector-parser';
|
|
2
|
+
import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
3
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
3
4
|
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
4
5
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
@@ -82,6 +83,7 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
82
83
|
const {
|
|
83
84
|
references
|
|
84
85
|
} = context.getScope();
|
|
86
|
+
const isXcssCall = isXcss(node, references, config.importSources);
|
|
85
87
|
walkStyleProperties(node, references, config.importSources, ({
|
|
86
88
|
key,
|
|
87
89
|
value
|
|
@@ -126,7 +128,8 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
126
128
|
context,
|
|
127
129
|
sourceNode: key,
|
|
128
130
|
selector,
|
|
129
|
-
config
|
|
131
|
+
config,
|
|
132
|
+
isXcssCall
|
|
130
133
|
}));
|
|
131
134
|
} catch (e) {
|
|
132
135
|
context.report({
|
|
@@ -15,8 +15,17 @@ function checkNoAmbiguousPseudos({
|
|
|
15
15
|
context,
|
|
16
16
|
sourceNode,
|
|
17
17
|
selector,
|
|
18
|
-
config
|
|
18
|
+
config,
|
|
19
|
+
isXcssCall
|
|
19
20
|
}) {
|
|
21
|
+
if (isXcssCall) {
|
|
22
|
+
/**
|
|
23
|
+
* The `xcss` API does not currently support a leading `&`.
|
|
24
|
+
*
|
|
25
|
+
* This may change in the future, but we are ignoring `xcss` calls for now.
|
|
26
|
+
*/
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
20
29
|
if (selector.first.type !== 'pseudo') {
|
|
21
30
|
return;
|
|
22
31
|
}
|
|
@@ -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::aff3fad2b8534fad07ba5f0f1b981a55>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import all from './presets/all.codegen';
|
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -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::6ad0de2d4bdac726387f27681ad9fcf4>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cssSelectorParser from 'postcss-selector-parser';
|
|
2
|
+
import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
3
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
3
4
|
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
4
5
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
@@ -87,6 +88,7 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
87
88
|
}(function (node) {
|
|
88
89
|
var _context$getScope = context.getScope(),
|
|
89
90
|
references = _context$getScope.references;
|
|
91
|
+
var isXcssCall = isXcss(node, references, config.importSources);
|
|
90
92
|
walkStyleProperties(node, references, config.importSources, function (_ref) {
|
|
91
93
|
var key = _ref.key,
|
|
92
94
|
value = _ref.value;
|
|
@@ -131,7 +133,8 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
131
133
|
context: context,
|
|
132
134
|
sourceNode: key,
|
|
133
135
|
selector: selector,
|
|
134
|
-
config: config
|
|
136
|
+
config: config,
|
|
137
|
+
isXcssCall: isXcssCall
|
|
135
138
|
});
|
|
136
139
|
});
|
|
137
140
|
} catch (e) {
|
|
@@ -17,7 +17,16 @@ function checkNoAmbiguousPseudos(_ref) {
|
|
|
17
17
|
var context = _ref.context,
|
|
18
18
|
sourceNode = _ref.sourceNode,
|
|
19
19
|
selector = _ref.selector,
|
|
20
|
-
config = _ref.config
|
|
20
|
+
config = _ref.config,
|
|
21
|
+
isXcssCall = _ref.isXcssCall;
|
|
22
|
+
if (isXcssCall) {
|
|
23
|
+
/**
|
|
24
|
+
* The `xcss` API does not currently support a leading `&`.
|
|
25
|
+
*
|
|
26
|
+
* This may change in the future, but we are ignoring `xcss` calls for now.
|
|
27
|
+
*/
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
21
30
|
if (selector.first.type !== 'pseudo') {
|
|
22
31
|
return;
|
|
23
32
|
}
|