Sha256: e11e389f627d8f6547813ee2b7380c52f98073b1d9e429d05b4a21752b2d6240

Contents?: true

Size: 1.4 KB

Versions: 24

Compression:

Stored size: 1.4 KB

Contents

let stylelint = require('stylelint');
let postcssSorting = require('postcss-sorting');
let { namespace, getContainingNode, isRuleWithNodes } = require('../../utils');
let checkNode = require('./checkNode');

let ruleName = namespace('properties-alphabetical-order');

let messages = stylelint.utils.ruleMessages(ruleName, {
	expected: (first, second) => `Expected ${first} to come before ${second}`,
});

function rule(actual, options = {}, context = {}) {
	return function(root, result) {
		let validOptions = stylelint.utils.validateOptions(
			result,
			ruleName,
			{
				actual,
				possible: Boolean,
			},
			{
				actual: options,
				possible: {
					disableFix: Boolean,
				},
				optional: true,
			}
		);

		if (!validOptions) {
			return;
		}

		let disableFix = options.disableFix || false;

		if (context.fix && !disableFix) {
			postcssSorting({ 'properties-order': 'alphabetical' })(root);

			return;
		}

		let processedParents = [];

		root.walk(function processRulesAndAtrules(input) {
			let node = getContainingNode(input);

			// Avoid warnings duplication, caused by interfering in `root.walk()` algorigthm with `getContainingNode()`
			if (processedParents.includes(node)) {
				return;
			}

			processedParents.push(node);

			if (isRuleWithNodes(node)) {
				checkNode(node, result, ruleName, messages);
			}
		});
	};
}

rule.ruleName = ruleName;
rule.messages = messages;

module.exports = rule;

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.7 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.6 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.5 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.4 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.3 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.2 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.1 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.3.5 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-5.0.0 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.3.4 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.3.3 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.3.2 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.3.1 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.3 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.2.3 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.2.2 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.2.1 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.2 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js
trusty-cms-4.1.9 node_modules/stylelint-order/rules/properties-alphabetical-order/index.js