1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const _ = require('lodash');
|
6 | const isStandardSyntaxCombinator = require('../../utils/isStandardSyntaxCombinator');
|
7 | const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
|
8 | const parseSelector = require('../../utils/parseSelector');
|
9 | const report = require('../../utils/report');
|
10 | const ruleMessages = require('../../utils/ruleMessages');
|
11 | const validateOptions = require('../../utils/validateOptions');
|
12 |
|
13 | const ruleName = 'selector-combinator-blacklist';
|
14 |
|
15 | const messages = ruleMessages(ruleName, {
|
16 | rejected: (combinator) => `Unexpected combinator "${combinator}"`,
|
17 | });
|
18 |
|
19 | function rule(list) {
|
20 | return (root, result) => {
|
21 | const validOptions = validateOptions(result, ruleName, {
|
22 | actual: list,
|
23 | possible: [_.isString],
|
24 | });
|
25 |
|
26 | if (!validOptions) {
|
27 | return;
|
28 | }
|
29 |
|
30 | result.warn(
|
31 | `'${ruleName}' has been deprecated. Instead use 'selector-combinator-disallowed-list'.`,
|
32 | {
|
33 | stylelintType: 'deprecation',
|
34 | stylelintReference: `https://github.com/stylelint/stylelint/blob/13.7.0/lib/rules/${ruleName}/README.md`,
|
35 | },
|
36 | );
|
37 |
|
38 | root.walkRules((rule) => {
|
39 | if (!isStandardSyntaxRule(rule)) {
|
40 | return;
|
41 | }
|
42 |
|
43 | const selector = rule.selector;
|
44 |
|
45 | parseSelector(selector, result, rule, (fullSelector) => {
|
46 | fullSelector.walkCombinators((combinatorNode) => {
|
47 | if (!isStandardSyntaxCombinator(combinatorNode)) {
|
48 | return;
|
49 | }
|
50 |
|
51 | const value = normalizeCombinator(combinatorNode.value);
|
52 |
|
53 | if (!list.includes(value)) {
|
54 | return;
|
55 | }
|
56 |
|
57 | report({
|
58 | result,
|
59 | ruleName,
|
60 | message: messages.rejected(value),
|
61 | node: rule,
|
62 | index: combinatorNode.sourceIndex,
|
63 | });
|
64 | });
|
65 | });
|
66 | });
|
67 | };
|
68 | }
|
69 |
|
70 | function normalizeCombinator(value) {
|
71 | return value.replace(/\s+/g, ' ');
|
72 | }
|
73 |
|
74 | rule.primaryOptionArray = true;
|
75 |
|
76 | rule.ruleName = ruleName;
|
77 | rule.messages = messages;
|
78 | module.exports = rule;
|