Sha256: 1f59ced1130856e952ea79e614eefd3bdbdd5c045350bba847696bdb50529eeb

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

'use strict';

const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');

const ruleName = 'at-rule-name-case';

const messages = ruleMessages(ruleName, {
	expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
});

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

		if (!validOptions) {
			return;
		}

		root.walkAtRules((atRule) => {
			if (!isStandardSyntaxAtRule(atRule)) {
				return;
			}

			const name = atRule.name;

			const expectedName = expectation === 'lower' ? name.toLowerCase() : name.toUpperCase();

			if (name === expectedName) {
				return;
			}

			if (context.fix) {
				atRule.name = expectedName;

				return;
			}

			report({
				message: messages.expected(name, expectedName),
				node: atRule,
				ruleName,
				result,
			});
		});
	};
}

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