123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 'use strict';
- const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
- const report = require('../../utils/report');
- const ruleMessages = require('../../utils/ruleMessages');
- const validateOptions = require('../../utils/validateOptions');
- const vendor = require('../../utils/vendor');
- const { isString } = require('../../utils/validateTypes');
- const ruleName = 'at-rule-disallowed-list';
- const messages = ruleMessages(ruleName, {
- rejected: (name) => `Unexpected at-rule "${name}"`,
- });
- const meta = {
- url: 'https://stylelint.io/user-guide/rules/list/at-rule-disallowed-list',
- };
- /** @type {import('stylelint').Rule<string | string[]>} */
- const rule = (primary) => {
- return (root, result) => {
- const validOptions = validateOptions(result, ruleName, {
- actual: primary,
- possible: [isString],
- });
- if (!validOptions) {
- return;
- }
- const primaryValues = [primary].flat();
- root.walkAtRules((atRule) => {
- const name = atRule.name;
- if (!isStandardSyntaxAtRule(atRule)) {
- return;
- }
- if (!primaryValues.includes(vendor.unprefixed(name).toLowerCase())) {
- return;
- }
- report({
- message: messages.rejected(name),
- node: atRule,
- result,
- ruleName,
- });
- });
- };
- };
- rule.primaryOptionArray = true;
- rule.ruleName = ruleName;
- rule.messages = messages;
- rule.meta = meta;
- module.exports = rule;
|