Sha256: 27f0bfc2eddcf3749f48373f8c0ac546e6af9fc385afa6b016ca28838f7a7142

Contents?: true

Size: 1.58 KB

Versions: 23

Compression:

Stored size: 1.58 KB

Contents

'use strict';

const _ = require('lodash');
const isStandardSyntaxCombinator = require('../../utils/isStandardSyntaxCombinator');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');

const ruleName = 'selector-combinator-blacklist';

const messages = ruleMessages(ruleName, {
	rejected: (combinator) => `Unexpected combinator "${combinator}"`,
});

function rule(blacklist) {
	return (root, result) => {
		const validOptions = validateOptions(result, ruleName, {
			actual: blacklist,
			possible: [_.isString],
		});

		if (!validOptions) {
			return;
		}

		root.walkRules((rule) => {
			if (!isStandardSyntaxRule(rule)) {
				return;
			}

			const selector = rule.selector;

			parseSelector(selector, result, rule, (fullSelector) => {
				fullSelector.walkCombinators((combinatorNode) => {
					if (!isStandardSyntaxCombinator(combinatorNode)) {
						return;
					}

					const value = normalizeCombinator(combinatorNode.value);

					if (!blacklist.includes(value)) {
						return;
					}

					report({
						result,
						ruleName,
						message: messages.rejected(value),
						node: rule,
						index: combinatorNode.sourceIndex,
					});
				});
			});
		});
	};
}

function normalizeCombinator(value) {
	return value.replace(/\s+/g, ' ');
}

rule.primaryOptionArray = true;

rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trusty-cms-5.0.7 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.6 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.5 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.4 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.3 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.2 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.1 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.3.5 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-5.0.0 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.3.4 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.3.3 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.3.2 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.3.1 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.3 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.2.3 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.2.2 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.2.1 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.2 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.1.9 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js
trusty-cms-4.1.8 node_modules/stylelint/lib/rules/selector-combinator-blacklist/index.js