Sha256: 606a999522570d9fe65aba7d72c34b7379e6a9af9a593ce9c88fb0e77525614b

Contents?: true

Size: 1.42 KB

Versions: 23

Compression:

Stored size: 1.42 KB

Contents

'use strict';

const _ = require('lodash');
const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
const keywordSets = require('../../reference/keywordSets');
const optionsMatches = require('../../utils/optionsMatches');
const postcss = require('postcss');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');

const ruleName = 'at-rule-no-unknown';

const messages = ruleMessages(ruleName, {
	rejected: (atRule) => `Unexpected unknown at-rule "${atRule}"`,
});

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

		if (!validOptions) {
			return;
		}

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

			const name = atRule.name;

			// Return early if at-rule is to be ignored
			if (optionsMatches(options, 'ignoreAtRules', atRule.name)) {
				return;
			}

			if (postcss.vendor.prefix(name) || keywordSets.atRules.has(name.toLowerCase())) {
				return;
			}

			report({
				message: messages.rejected(`@${name}`),
				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-4.1.7 node_modules/stylelint/lib/rules/at-rule-no-unknown/index.js
trusty-cms-4.1.6 node_modules/stylelint/lib/rules/at-rule-no-unknown/index.js
trusty-cms-4.1.5 node_modules/stylelint/lib/rules/at-rule-no-unknown/index.js