Sha256: 411fedb66a45d02b69c123acc77c77d11c416a9309bafb47564ff89bfc541d28

Contents?: true

Size: 1.5 KB

Versions: 23

Compression:

Stored size: 1.5 KB

Contents

'use strict';

const _ = require('lodash');
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-attribute-operator-blacklist';

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

function rule(blacklistInput) {
	const blacklist = [].concat(blacklistInput);

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

		if (!validOptions) {
			return;
		}

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

			if (!rule.selector.includes('[') || !rule.selector.includes('=')) {
				return;
			}

			parseSelector(rule.selector, result, rule, (selectorTree) => {
				selectorTree.walkAttributes((attributeNode) => {
					const operator = attributeNode.operator;

					if (!operator || (operator && !blacklist.includes(operator))) {
						return;
					}

					report({
						message: messages.rejected(operator),
						node: rule,
						index: attributeNode.sourceIndex + attributeNode.offsetOf('operator'),
						result,
						ruleName,
					});
				});
			});
		});
	};
}

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-attribute-operator-blacklist/index.js
trusty-cms-5.0.6 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-5.0.5 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-5.0.4 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-5.0.3 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-5.0.2 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-5.0.1 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.3.5 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-5.0.0 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.3.4 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.3.3 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.3.2 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.3.1 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.3 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.2.3 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.2.2 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.2.1 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.2 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.1.9 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js
trusty-cms-4.1.8 node_modules/stylelint/lib/rules/selector-attribute-operator-blacklist/index.js