text: const { parse } = require("postcss-values-parser");
  const {
    createPlugin,
    utils: { report, validateOptions },
  } = require("stylelint");
  
  const createRuleMessages = require("../../utils/createRuleMessages");
  const findScaleByUnit = require("../../utils/findScaleByUnit");
  const getClosest = require("../../utils/getClosest");
  const getValue = require("../../utils/getValue");
  const hasScalesWithUnits = require("../../utils/hasScalesWithUnits");
  const isOnNumericScale = require("../../utils/isOnNumericScale");
  const setValue = require("../../utils/setValue");
  
  const ruleName = "scales/sizes";
  const messages = createRuleMessages(ruleName);
  
  const propertyFilter =
    /^((min|max)-)?(height$|width$|block-size$|inline-size$)/;
  
  const rule = (primary, secondary, { fix }) => {
    return (root, result) => {
      if (
        !validateOptions(result, ruleName, {
          actual: primary,
          possible: hasScalesWithUnits,
        })
      )
        return;
  
      root.walkDecls(propertyFilter, (decl) => {
        const value = getValue(decl);
        let hasFix = false;
  
        const valueRoot = parse(value, {
          ignoreUnknownWords: true,
        });
  
        valueRoot.walkNumerics((node) => {
          check(node);
        });
  
        function check(node) {
          const { value, unit } = node;
  
          const scale = findScaleByUnit(primary, unit);
  
          if (isOnNumericScale(scale, value)) return;
  
          if (fix) {
            node.value = getClosest(scale, value);
            hasFix = true;
            return;
          }
  
          report({
            message: messages.expected(value, scale.join(", "), unit),
            node: decl,
            result,
            ruleName,
            word: value,
          });
        }
  
        if (hasFix) setValue(decl, valueRoot.toString());
      });
    };
  };
  
  rule.primaryOptionArray = true;
  
  module.exports = createPlugin(ruleName, rule);
  module.exports.ruleName = ruleName;
  module.exports.messages = messages;
  