12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- const stylelint = require('stylelint');
- const _ = require('lodash');
- const { getContainingNode, isRuleWithNodes } = require('../../utils');
- const checkNode = require('./checkNode');
- const createOrderInfo = require('./createOrderInfo');
- const validatePrimaryOption = require('./validatePrimaryOption');
- const ruleName = require('./ruleName');
- const messages = require('./messages');
- function rule(primaryOption, options = {}, context = {}) {
- return function ruleBody(root, result) {
- let validOptions = stylelint.utils.validateOptions(
- result,
- ruleName,
- {
- actual: primaryOption,
- possible: validatePrimaryOption,
- },
- {
- actual: options,
- possible: {
- unspecified: ['top', 'bottom', 'ignore'],
- disableFix: _.isBoolean,
- },
- optional: true,
- }
- );
- if (!validOptions) {
- return;
- }
- let disableFix = options.disableFix || false;
- let isFixEnabled = context.fix && !disableFix;
- let unspecified = options.unspecified || 'ignore';
- let orderInfo = createOrderInfo(primaryOption);
- let processedParents = [];
- // Check all rules and at-rules recursively
- root.walk(function processRulesAndAtrules(originalNode) {
- let node = getContainingNode(originalNode);
- // 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,
- originalNode,
- isFixEnabled,
- orderInfo,
- primaryOption,
- result,
- unspecified,
- });
- }
- });
- };
- }
- rule.ruleName = ruleName;
- rule.messages = messages;
- rule.primaryOptionArray = true;
- module.exports = rule;
|