-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move function normalizeAllRuleSettings() out to a separate module (#4810
- Loading branch information
1 parent
651b43c
commit 037338d
Showing
2 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const normalizeRuleSettings = require('./normalizeRuleSettings'); | ||
const rules = require('./rules'); | ||
|
||
/** @typedef {import('stylelint').StylelintConfigRules} StylelintConfigRules */ | ||
/** @typedef {import('stylelint').StylelintConfig} StylelintConfig */ | ||
|
||
/** | ||
* @param {StylelintConfig} config | ||
* @return {StylelintConfig} | ||
*/ | ||
function normalizeAllRuleSettings(config) { | ||
/** @type {StylelintConfigRules} */ | ||
const normalizedRules = {}; | ||
|
||
if (!config.rules) return config; | ||
|
||
Object.keys(config.rules).forEach((ruleName) => { | ||
const rawRuleSettings = _.get(config, ['rules', ruleName]); | ||
|
||
const rule = rules[ruleName] || _.get(config, ['pluginFunctions', ruleName]); | ||
|
||
if (!rule) { | ||
normalizedRules[ruleName] = []; | ||
} else { | ||
normalizedRules[ruleName] = normalizeRuleSettings( | ||
rawRuleSettings, | ||
ruleName, | ||
_.get(rule, 'primaryOptionArray'), | ||
); | ||
} | ||
}); | ||
|
||
config.rules = normalizedRules; | ||
|
||
return config; | ||
} | ||
|
||
module.exports = normalizeAllRuleSettings; |