@atlaskit/eslint-plugin-ui-styling-standard 2.1.3 → 2.1.5
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 +16 -0
- package/README.md +18 -18
- package/dist/cjs/rules/no-container-queries/index.js +62 -13
- package/dist/cjs/rules/no-important-styles/index.js +79 -99
- package/dist/cjs/rules/no-nested-selectors/index.js +46 -32
- package/dist/cjs/rules/no-unsafe-selectors/index.js +87 -84
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +140 -101
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +20 -50
- package/dist/cjs/rules/utils/create-rule-with-typed-config.js +29 -10
- package/dist/cjs/rules/utils/is-simple-selector.js +70 -0
- package/dist/cjs/rules/utils/parse-selector.js +3 -4
- package/dist/cjs/rules/utils/style-calls.js +127 -0
- package/dist/cjs/rules/utils/walk-style-call-properties.js +50 -0
- package/dist/es2019/rules/no-container-queries/index.js +53 -14
- package/dist/es2019/rules/no-important-styles/index.js +79 -70
- package/dist/es2019/rules/no-nested-selectors/index.js +36 -34
- package/dist/es2019/rules/no-unsafe-selectors/index.js +67 -87
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +29 -23
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +4 -30
- package/dist/es2019/rules/utils/create-rule-with-typed-config.js +30 -10
- package/dist/es2019/rules/utils/is-simple-selector.js +63 -0
- package/dist/es2019/rules/utils/parse-selector.js +3 -4
- package/dist/es2019/rules/utils/style-calls.js +89 -0
- package/dist/es2019/rules/utils/walk-style-call-properties.js +23 -0
- package/dist/esm/rules/no-container-queries/index.js +63 -14
- package/dist/esm/rules/no-important-styles/index.js +80 -100
- package/dist/esm/rules/no-nested-selectors/index.js +46 -32
- package/dist/esm/rules/no-unsafe-selectors/index.js +88 -85
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +141 -102
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +19 -49
- package/dist/esm/rules/utils/create-rule-with-typed-config.js +30 -10
- package/dist/esm/rules/utils/is-simple-selector.js +64 -0
- package/dist/esm/rules/utils/parse-selector.js +3 -4
- package/dist/esm/rules/utils/style-calls.js +120 -0
- package/dist/esm/rules/utils/walk-style-call-properties.js +44 -0
- package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +1 -7
- package/dist/types/rules/utils/is-simple-selector.d.ts +11 -0
- package/dist/types/rules/utils/parse-selector.d.ts +1 -2
- package/dist/types/rules/utils/style-calls.d.ts +17 -0
- package/dist/types/rules/utils/walk-style-call-properties.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import estraverse from 'estraverse';
|
|
2
|
-
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
3
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
4
|
import { createLintRule } from '../utils/create-rule';
|
|
5
5
|
var schema = [{
|
|
@@ -14,6 +14,60 @@ var schema = [{
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}];
|
|
17
|
+
var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(node) {
|
|
18
|
+
var expression = node;
|
|
19
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
20
|
+
expression = expression.expression;
|
|
21
|
+
}
|
|
22
|
+
return expression;
|
|
23
|
+
};
|
|
24
|
+
var isStaticContainerKey = function isStaticContainerKey(node) {
|
|
25
|
+
var _expression$expressio;
|
|
26
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
27
|
+
if (expression.type === 'Literal') {
|
|
28
|
+
return typeof expression.value === 'string';
|
|
29
|
+
}
|
|
30
|
+
return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
|
|
31
|
+
};
|
|
32
|
+
var isImportedContainerType = function isImportedContainerType(node, context) {
|
|
33
|
+
var expression = node;
|
|
34
|
+
var _loop = function _loop() {
|
|
35
|
+
var _typeAnnotation$typeN;
|
|
36
|
+
var _expression = expression,
|
|
37
|
+
typeAnnotation = _expression.typeAnnotation;
|
|
38
|
+
if ((typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.type) === 'TSTypeReference' && ((_typeAnnotation$typeN = typeAnnotation.typeName) === null || _typeAnnotation$typeN === void 0 ? void 0 : _typeAnnotation$typeN.type) === 'Identifier') {
|
|
39
|
+
var typeName = typeAnnotation.typeName.name;
|
|
40
|
+
var isImported = getSourceCode(context).ast.body.some(function (statement) {
|
|
41
|
+
return statement.type === 'ImportDeclaration' && statement.source.value === '@atlaskit/css/at-rules/container' && statement.specifiers.some(function (specifier) {
|
|
42
|
+
return specifier.type === 'ImportDefaultSpecifier' && specifier.local.name === typeName;
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (isImported) {
|
|
46
|
+
return {
|
|
47
|
+
v: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
expression = expression.expression;
|
|
52
|
+
},
|
|
53
|
+
_ret;
|
|
54
|
+
while (expression.type === 'TSSatisfiesExpression') {
|
|
55
|
+
_ret = _loop();
|
|
56
|
+
if (_ret) return _ret.v;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
var isContainerQuery = function isContainerQuery(node) {
|
|
61
|
+
var _expression$quasis;
|
|
62
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
63
|
+
if (expression.type === 'Literal' && typeof expression.value === 'string') {
|
|
64
|
+
return expression.value.includes('@container');
|
|
65
|
+
}
|
|
66
|
+
return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(function (quasi) {
|
|
67
|
+
var _quasi$value;
|
|
68
|
+
return (_quasi$value = quasi.value) === null || _quasi$value === void 0 || (_quasi$value = _quasi$value.raw) === null || _quasi$value === void 0 ? void 0 : _quasi$value.includes('@container');
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
17
71
|
var rule = createLintRule({
|
|
18
72
|
meta: {
|
|
19
73
|
name: 'no-container-queries',
|
|
@@ -37,25 +91,20 @@ var rule = createLintRule({
|
|
|
37
91
|
if (isCss(node.callee, references, importSources) || isStyled(node.callee, references, importSources) || isKeyframes(node.callee, references, importSources) || isCssMap(node.callee, references, importSources) || isXcss(node.callee, references, importSources)) {
|
|
38
92
|
estraverse.traverse(node, {
|
|
39
93
|
enter: function enter(node) {
|
|
40
|
-
var _node$key$value, _node$key$quasis$;
|
|
41
94
|
if (node.type !== 'Property') {
|
|
42
95
|
return;
|
|
43
96
|
}
|
|
44
|
-
|
|
97
|
+
var key = node.key;
|
|
98
|
+
if (!isContainerQuery(key)) {
|
|
45
99
|
return;
|
|
46
100
|
}
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
node: node.key,
|
|
50
|
-
messageId: 'no-container-queries'
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (node.key.type === 'TemplateLiteral' && (_node$key$quasis$ = node.key.quasis[0]) !== null && _node$key$quasis$ !== void 0 && _node$key$quasis$.value.raw.match(/@container/)) {
|
|
54
|
-
context.report({
|
|
55
|
-
node: node.key,
|
|
56
|
-
messageId: 'no-container-queries'
|
|
57
|
-
});
|
|
101
|
+
if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
|
|
102
|
+
return;
|
|
58
103
|
}
|
|
104
|
+
context.report({
|
|
105
|
+
node: node.key,
|
|
106
|
+
messageId: 'no-container-queries'
|
|
107
|
+
});
|
|
59
108
|
},
|
|
60
109
|
/**
|
|
61
110
|
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
-
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
-
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
6
2
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
3
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
4
|
+
import { getStyleCalls } from '../utils/style-calls';
|
|
8
5
|
var rule = createLintRuleWithTypedConfig({
|
|
9
6
|
meta: {
|
|
10
7
|
name: 'no-important-styles',
|
|
@@ -26,118 +23,101 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
26
23
|
},
|
|
27
24
|
create: function create(context, _ref) {
|
|
28
25
|
var importSources = _ref.importSources;
|
|
26
|
+
var sourceCode = getSourceCode(context);
|
|
27
|
+
if (!sourceCode.text.includes('important')) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
29
30
|
return {
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
Program: function Program() {
|
|
32
|
+
var text = sourceCode.text;
|
|
33
|
+
var reportedValues = new Set();
|
|
34
|
+
var importantIndex = text.indexOf('important');
|
|
35
|
+
while (importantIndex !== -1) {
|
|
36
|
+
var value = findStyleValue(sourceCode, importantIndex);
|
|
37
|
+
if (value && !reportedValues.has(value) && isImportant(value) && isInSupportedStyleCall(context, value, importSources)) {
|
|
38
|
+
reportedValues.add(value);
|
|
38
39
|
context.report({
|
|
39
|
-
node:
|
|
40
|
+
node: value,
|
|
40
41
|
messageId: 'no-important-styles'
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
importantIndex = text.indexOf('important', importantIndex + 9);
|
|
45
|
+
}
|
|
44
46
|
}
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
});
|
|
48
50
|
export default rule;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* Walk through all Property nodes in the AST tree recursively.
|
|
53
|
-
* This is faster than esquery for this specific use case as it avoids
|
|
54
|
-
* selector compilation and executes a simple depth-first traversal.
|
|
55
|
-
*/
|
|
56
|
-
function walkProperties(node, callback) {
|
|
57
|
-
var _node$arguments;
|
|
58
|
-
if (node.type === 'Property' && node.value) {
|
|
59
|
-
callback(node);
|
|
51
|
+
function isImportant(node) {
|
|
52
|
+
if (node.type === 'Literal') {
|
|
53
|
+
return typeof node.value === 'string' && hasImportantSuffix(node.value);
|
|
60
54
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var _iterator = _createForOfIteratorHelper(node.arguments),
|
|
65
|
-
_step;
|
|
66
|
-
try {
|
|
67
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
68
|
-
var arg = _step.value;
|
|
69
|
-
if (arg.type === 'ObjectExpression' && arg.properties) {
|
|
70
|
-
var _iterator2 = _createForOfIteratorHelper(arg.properties),
|
|
71
|
-
_step2;
|
|
72
|
-
try {
|
|
73
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
74
|
-
var prop = _step2.value;
|
|
75
|
-
walkObjectProperty(prop, callback);
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
_iterator2.e(err);
|
|
79
|
-
} finally {
|
|
80
|
-
_iterator2.f();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
_iterator.e(err);
|
|
86
|
-
} finally {
|
|
87
|
-
_iterator.f();
|
|
88
|
-
}
|
|
55
|
+
if (node.type === 'TemplateLiteral') {
|
|
56
|
+
var lastQuasi = node.quasis[node.quasis.length - 1];
|
|
57
|
+
return Boolean(lastQuasi && hasImportantSuffix(lastQuasi.value.raw));
|
|
89
58
|
}
|
|
59
|
+
return false;
|
|
90
60
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
61
|
+
function findStyleValue(sourceCode, index) {
|
|
62
|
+
var node = sourceCode.getNodeByRangeIndex(index);
|
|
63
|
+
while (node && node.type !== 'Literal' && node.type !== 'TemplateLiteral') {
|
|
64
|
+
node = node.parent;
|
|
65
|
+
}
|
|
66
|
+
return node;
|
|
67
|
+
}
|
|
68
|
+
function isInSupportedStyleCall(context, value, importSources) {
|
|
69
|
+
var call = findContainingCall(value);
|
|
70
|
+
return Boolean(call && getStyleCalls(context).some(function (styleCall) {
|
|
71
|
+
return styleCall.node === call && importSources.includes(styleCall.importSource);
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
function findContainingCall(value) {
|
|
75
|
+
var _property, _object;
|
|
76
|
+
var property = value.parent;
|
|
77
|
+
if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
var object = property.parent;
|
|
81
|
+
if (((_object = object) === null || _object === void 0 ? void 0 : _object.type) !== 'ObjectExpression') {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
while (object) {
|
|
85
|
+
var _parent$parent;
|
|
86
|
+
var parent = object.parent;
|
|
87
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
|
|
88
|
+
var _object2;
|
|
89
|
+
property = parent;
|
|
90
|
+
object = property.parent;
|
|
91
|
+
if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
|
|
92
|
+
return null;
|
|
112
93
|
}
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
|
|
97
|
+
return parent;
|
|
113
98
|
}
|
|
99
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
|
|
100
|
+
return parent.parent;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
114
103
|
}
|
|
104
|
+
return null;
|
|
115
105
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
function isImportant(node) {
|
|
122
|
-
if (node.type === 'Literal') {
|
|
123
|
-
if (typeof node.value !== 'string') {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
// Fast check: string must end with 'important' (after optional whitespace)
|
|
127
|
-
var len = node.value.length;
|
|
128
|
-
if (len < 10) {
|
|
129
|
-
return false;
|
|
130
|
-
} // "!important" is 10 chars minimum
|
|
131
|
-
return IMPORTANT_SUFFIX_REGEX.test(node.value);
|
|
106
|
+
function hasImportantSuffix(value) {
|
|
107
|
+
var index = value.length - 1;
|
|
108
|
+
while (index >= 0 && isWhitespace(value.charCodeAt(index))) {
|
|
109
|
+
index--;
|
|
132
110
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
// Only check the last quasi's raw value (most likely to contain the !important)
|
|
139
|
-
var lastQuasi = node.quasis[node.quasis.length - 1];
|
|
140
|
-
return IMPORTANT_SUFFIX_REGEX.test(lastQuasi.value.raw);
|
|
111
|
+
var importantStart = index - 8;
|
|
112
|
+
if (importantStart < 0 || value.slice(importantStart, index + 1) !== 'important') {
|
|
113
|
+
return false;
|
|
141
114
|
}
|
|
142
|
-
|
|
115
|
+
index = importantStart - 1;
|
|
116
|
+
while (index >= 0 && isWhitespace(value.charCodeAt(index))) {
|
|
117
|
+
index--;
|
|
118
|
+
}
|
|
119
|
+
return value.charCodeAt(index) === 33;
|
|
120
|
+
}
|
|
121
|
+
function isWhitespace(character) {
|
|
122
|
+
return character === 32 || character >= 9 && character <= 13;
|
|
143
123
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import _toArray from "@babel/runtime/helpers/toArray";
|
|
2
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
2
4
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
3
5
|
import { isNesting, isPseudo } from 'postcss-selector-parser';
|
|
4
|
-
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
6
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
6
|
-
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
7
7
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
8
|
+
import { isSimpleSelector } from '../utils/is-simple-selector';
|
|
8
9
|
import { parseSelector } from '../utils/parse-selector';
|
|
10
|
+
import { getStyleCalls } from '../utils/style-calls';
|
|
11
|
+
import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
|
|
9
12
|
var getCssSelector = function getCssSelector(key) {
|
|
10
13
|
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
11
14
|
return key.value;
|
|
@@ -54,38 +57,49 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
54
57
|
create: function create(context, _ref) {
|
|
55
58
|
var importSources = _ref.importSources;
|
|
56
59
|
return {
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
var selectorText = getCssSelector(key);
|
|
68
|
-
if (selectorText === null) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Ignore at-rules
|
|
73
|
-
if (selectorText.includes('@')) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
var selectorList = parseSelector(context, selectorText);
|
|
78
|
-
if (!selectorList.nodes.every(isAllowedSelector)) {
|
|
79
|
-
context.report({
|
|
80
|
-
messageId: 'no-nested-selectors',
|
|
81
|
-
node: key
|
|
82
|
-
});
|
|
60
|
+
Program: function Program() {
|
|
61
|
+
var _iterator = _createForOfIteratorHelper(getStyleCalls(context)),
|
|
62
|
+
_step;
|
|
63
|
+
try {
|
|
64
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
65
|
+
var styleCall = _step.value;
|
|
66
|
+
if (!importSources.includes(styleCall.importSource)) {
|
|
67
|
+
continue;
|
|
83
68
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
69
|
+
walkStyleCallProperties(styleCall, function (_ref2) {
|
|
70
|
+
var key = _ref2.key,
|
|
71
|
+
value = _ref2.value;
|
|
72
|
+
if (value.type !== 'ObjectExpression') {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var selectorText = getCssSelector(key);
|
|
76
|
+
if (selectorText === null || selectorText.includes('@')) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (isSimpleSelector(selectorText, {
|
|
80
|
+
allowBareNesting: true,
|
|
81
|
+
allowLeadingPseudo: true
|
|
82
|
+
})) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
var selectorList = parseSelector(context, selectorText);
|
|
87
|
+
if (!selectorList.nodes.every(isAllowedSelector)) {
|
|
88
|
+
context.report({
|
|
89
|
+
messageId: 'no-nested-selectors',
|
|
90
|
+
node: key
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
} catch (_unused) {
|
|
94
|
+
// `no-unsafe-selectors` reports unparsable selectors.
|
|
95
|
+
}
|
|
96
|
+
});
|
|
87
97
|
}
|
|
88
|
-
})
|
|
98
|
+
} catch (err) {
|
|
99
|
+
_iterator.e(err);
|
|
100
|
+
} finally {
|
|
101
|
+
_iterator.f();
|
|
102
|
+
}
|
|
89
103
|
}
|
|
90
104
|
};
|
|
91
105
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
3
4
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
4
|
-
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
5
5
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
6
|
+
import { isSimpleSelector } from '../utils/is-simple-selector';
|
|
6
7
|
import { parseSelector } from '../utils/parse-selector';
|
|
8
|
+
import { getStyleCalls } from '../utils/style-calls';
|
|
9
|
+
import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
|
|
7
10
|
import { lintSelector } from './lint-selector';
|
|
8
|
-
import {
|
|
11
|
+
import { walkCssMapCall } from './walk-css-map';
|
|
12
|
+
import { allowedPseudos } from './constants';
|
|
9
13
|
var ignoredAtRules = new Set(['@container',
|
|
10
14
|
// ignored because it's covered by `no-container-queries`
|
|
11
15
|
'@media',
|
|
@@ -56,93 +60,92 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
56
60
|
},
|
|
57
61
|
create: function create(context, config) {
|
|
58
62
|
return {
|
|
59
|
-
Program: function Program(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (type === 'grouped-at-rules') {
|
|
68
|
-
context.report({
|
|
69
|
-
node: node.key,
|
|
70
|
-
messageId: 'no-grouped-at-rules'
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
63
|
+
Program: function Program() {
|
|
64
|
+
var _iterator = _createForOfIteratorHelper(getStyleCalls(context)),
|
|
65
|
+
_step;
|
|
66
|
+
try {
|
|
67
|
+
var _loop = function _loop() {
|
|
68
|
+
var styleCall = _step.value;
|
|
69
|
+
if (!config.importSources.includes(styleCall.importSource)) {
|
|
70
|
+
return 1; // continue
|
|
73
71
|
}
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
if (styleCall.styleFunction === 'cssMap') {
|
|
73
|
+
walkCssMapCall(styleCall.node, function (property) {
|
|
74
|
+
var type = property.type,
|
|
75
|
+
node = property.node;
|
|
76
|
+
if (type === 'grouped-at-rules') {
|
|
77
|
+
context.report({
|
|
78
|
+
node: node.key,
|
|
79
|
+
messageId: 'no-grouped-at-rules'
|
|
80
|
+
});
|
|
81
|
+
} else if (type === 'selectors') {
|
|
82
|
+
context.report({
|
|
83
|
+
node: node.key,
|
|
84
|
+
messageId: 'no-selectors-object'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
78
87
|
});
|
|
79
|
-
return;
|
|
80
88
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
sourceNode: key,
|
|
131
|
-
selector: selector,
|
|
132
|
-
config: config,
|
|
133
|
-
isXcssCall: isXcssCall
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
} catch (_unused) {
|
|
137
|
-
context.report({
|
|
138
|
-
node: key,
|
|
139
|
-
messageId: 'no-unparsable-selectors',
|
|
140
|
-
data: {
|
|
141
|
-
selectorText: selectorText
|
|
89
|
+
walkStyleCallProperties(styleCall, function (_ref) {
|
|
90
|
+
var key = _ref.key,
|
|
91
|
+
value = _ref.value;
|
|
92
|
+
if (value.type !== 'ObjectExpression' || key.type !== 'Literal' || typeof key.value !== 'string') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
var selectorText = key.value;
|
|
96
|
+
if (selectorText.includes('@')) {
|
|
97
|
+
lintAtRule({
|
|
98
|
+
context: context,
|
|
99
|
+
sourceNode: key,
|
|
100
|
+
atRule: selectorText
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (isSimpleSelector(selectorText, {
|
|
105
|
+
allowedPseudos: allowedPseudos,
|
|
106
|
+
allowLeadingPseudo: styleCall.styleFunction === 'xcss'
|
|
107
|
+
})) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
var selectorList = parseSelector(context, selectorText);
|
|
112
|
+
var _iterator2 = _createForOfIteratorHelper(selectorList.nodes),
|
|
113
|
+
_step2;
|
|
114
|
+
try {
|
|
115
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
116
|
+
var selector = _step2.value;
|
|
117
|
+
lintSelector({
|
|
118
|
+
context: context,
|
|
119
|
+
sourceNode: key,
|
|
120
|
+
selector: selector,
|
|
121
|
+
config: config,
|
|
122
|
+
isXcssCall: styleCall.styleFunction === 'xcss'
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
} catch (err) {
|
|
126
|
+
_iterator2.e(err);
|
|
127
|
+
} finally {
|
|
128
|
+
_iterator2.f();
|
|
129
|
+
}
|
|
130
|
+
} catch (_unused) {
|
|
131
|
+
context.report({
|
|
132
|
+
node: key,
|
|
133
|
+
messageId: 'no-unparsable-selectors',
|
|
134
|
+
data: {
|
|
135
|
+
selectorText: selectorText
|
|
136
|
+
}
|
|
137
|
+
});
|
|
142
138
|
}
|
|
143
139
|
});
|
|
140
|
+
};
|
|
141
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
142
|
+
if (_loop()) continue;
|
|
144
143
|
}
|
|
145
|
-
})
|
|
144
|
+
} catch (err) {
|
|
145
|
+
_iterator.e(err);
|
|
146
|
+
} finally {
|
|
147
|
+
_iterator.f();
|
|
148
|
+
}
|
|
146
149
|
}
|
|
147
150
|
};
|
|
148
151
|
}
|