normalizeAllRuleSettings.js 864 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const normalizeRuleSettings = require('./normalizeRuleSettings');
  3. const getStylelintRule = require('./utils/getStylelintRule');
  4. /** @typedef {import('stylelint').ConfigRules} StylelintConfigRules */
  5. /** @typedef {import('stylelint').Config} StylelintConfig */
  6. /**
  7. * @param {StylelintConfig} config
  8. * @return {StylelintConfig}
  9. */
  10. function normalizeAllRuleSettings(config) {
  11. if (!config.rules) return config;
  12. /** @type {StylelintConfigRules} */
  13. const normalizedRules = {};
  14. for (const [ruleName, rawRuleSettings] of Object.entries(config.rules)) {
  15. const rule = getStylelintRule(ruleName, config);
  16. if (rule) {
  17. normalizedRules[ruleName] = normalizeRuleSettings(rawRuleSettings, rule);
  18. } else {
  19. normalizedRules[ruleName] = [];
  20. }
  21. }
  22. config.rules = normalizedRules;
  23. return config;
  24. }
  25. module.exports = normalizeAllRuleSettings;