Sha256: c9a2bb97e202aaef8d70ebc6d907740ec27d29be86637ccb4aa5298e97bcdff7

Contents?: true

Size: 1.72 KB

Versions: 23

Compression:

Stored size: 1.72 KB

Contents

'use strict';

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-quotes';

const messages = ruleMessages(ruleName, {
	expected: (value) => `Expected quotes around "${value}"`,
	rejected: (value) => `Unexpected quotes around "${value}"`,
});

function rule(expectation) {
	return (root, result) => {
		const validOptions = validateOptions(result, ruleName, {
			actual: expectation,
			possible: ['always', 'never'],
		});

		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) => {
					if (!attributeNode.operator) {
						return;
					}

					if (!attributeNode.quoted && expectation === 'always') {
						complain(
							messages.expected(attributeNode.value),
							attributeNode.sourceIndex + attributeNode.offsetOf('value'),
						);
					}

					if (attributeNode.quoted && expectation === 'never') {
						complain(
							messages.rejected(attributeNode.value),
							attributeNode.sourceIndex + attributeNode.offsetOf('value'),
						);
					}
				});
			});

			function complain(message, index) {
				report({
					message,
					index,
					result,
					ruleName,
					node: rule,
				});
			}
		});
	};
}

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