normalizeAllRuleSettings.js 928 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const normalizeRuleSettings = require('./normalizeRuleSettings');
  3. const rules = require('./rules');
  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 = rules[ruleName] || (config.pluginFunctions && config.pluginFunctions[ruleName]);
  16. if (rule) {
  17. normalizedRules[ruleName] = normalizeRuleSettings(
  18. rawRuleSettings,
  19. ruleName,
  20. rule.primaryOptionArray,
  21. );
  22. } else {
  23. normalizedRules[ruleName] = [];
  24. }
  25. }
  26. config.rules = normalizedRules;
  27. return config;
  28. }
  29. module.exports = normalizeAllRuleSettings;