@atlaskit/eslint-plugin-ui-styling-standard 2.1.2 → 2.1.4
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-important-styles/index.js +79 -99
- package/dist/cjs/rules/no-nested-selectors/index.js +48 -36
- package/dist/cjs/rules/no-unsafe-selectors/index.js +88 -87
- 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 +30 -0
- 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-important-styles/index.js +79 -70
- package/dist/es2019/rules/no-nested-selectors/index.js +38 -36
- package/dist/es2019/rules/no-unsafe-selectors/index.js +68 -89
- 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 +23 -0
- 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-important-styles/index.js +80 -100
- package/dist/esm/rules/no-nested-selectors/index.js +48 -34
- package/dist/esm/rules/no-unsafe-selectors/index.js +89 -87
- 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 +23 -0
- 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/constants.d.ts +1 -1
- package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +1 -7
- package/dist/types/rules/utils/create-rule-with-typed-config.d.ts +1 -1
- package/dist/types/rules/utils/is-simple-selector.d.ts +11 -0
- package/dist/types/rules/utils/parse-selector.d.ts +9 -0
- 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 +3 -3
|
@@ -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,10 +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
|
-
import
|
|
4
|
-
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
+
import { isNesting, isPseudo } from 'postcss-selector-parser';
|
|
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';
|
|
9
|
+
import { parseSelector } from '../utils/parse-selector';
|
|
10
|
+
import { getStyleCalls } from '../utils/style-calls';
|
|
11
|
+
import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
|
|
8
12
|
var getCssSelector = function getCssSelector(key) {
|
|
9
13
|
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
10
14
|
return key.value;
|
|
@@ -31,7 +35,6 @@ function isAllowedSelector(selector) {
|
|
|
31
35
|
var isTailAllowed = tail.every(isPseudo);
|
|
32
36
|
return isHeadAllowed && isTailAllowed;
|
|
33
37
|
}
|
|
34
|
-
var cssSelectorProcessor = cssSelectorParser();
|
|
35
38
|
var rule = createLintRuleWithTypedConfig({
|
|
36
39
|
meta: {
|
|
37
40
|
name: 'no-nested-selectors',
|
|
@@ -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 = cssSelectorProcessor.astSync(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,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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; }
|
|
4
4
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
5
|
-
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
6
5
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
6
|
+
import { isSimpleSelector } from '../utils/is-simple-selector';
|
|
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',
|
|
12
16
|
// ignored because it's covered by `no-nested-styles`
|
|
13
17
|
'@supports', '@property', '@starting-style']);
|
|
14
|
-
var cssSelectorProcessor = cssSelectorParser();
|
|
15
18
|
var rule = createLintRuleWithTypedConfig({
|
|
16
19
|
meta: {
|
|
17
20
|
name: 'no-unsafe-selectors',
|
|
@@ -57,93 +60,92 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
57
60
|
},
|
|
58
61
|
create: function create(context, config) {
|
|
59
62
|
return {
|
|
60
|
-
Program: function Program(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (type === 'grouped-at-rules') {
|
|
69
|
-
context.report({
|
|
70
|
-
node: node.key,
|
|
71
|
-
messageId: 'no-grouped-at-rules'
|
|
72
|
-
});
|
|
73
|
-
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
|
|
74
71
|
}
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
}
|
|
79
87
|
});
|
|
80
|
-
return;
|
|
81
88
|
}
|
|
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
|
-
|
|
131
|
-
sourceNode: key,
|
|
132
|
-
selector: selector,
|
|
133
|
-
config: config,
|
|
134
|
-
isXcssCall: isXcssCall
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
} catch (_unused) {
|
|
138
|
-
context.report({
|
|
139
|
-
node: key,
|
|
140
|
-
messageId: 'no-unparsable-selectors',
|
|
141
|
-
data: {
|
|
142
|
-
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
|
+
});
|
|
143
138
|
}
|
|
144
139
|
});
|
|
140
|
+
};
|
|
141
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
142
|
+
if (_loop()) continue;
|
|
145
143
|
}
|
|
146
|
-
})
|
|
144
|
+
} catch (err) {
|
|
145
|
+
_iterator.e(err);
|
|
146
|
+
} finally {
|
|
147
|
+
_iterator.f();
|
|
148
|
+
}
|
|
147
149
|
}
|
|
148
150
|
};
|
|
149
151
|
}
|