Skip to content

Commit

Permalink
Chore: make config validator params more consistent (#11435)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add authored and btmills committed Mar 15, 2019
1 parent d6c1122 commit 0f56dc6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lib/config/config-file.js
Expand Up @@ -541,7 +541,7 @@ function loadFromDisk(resolvedPath, configContext) {
const ruleMap = configContext.linterContext.getRules();

// validate the configuration before continuing
validator.validate(config, resolvedPath.configFullName, ruleMap.get.bind(ruleMap), configContext.linterContext.environments);
validator.validate(config, ruleMap.get.bind(ruleMap), configContext.linterContext.environments, resolvedPath.configFullName);

/*
* If an `extends` property is defined, it represents a configuration file to use as
Expand Down
24 changes: 12 additions & 12 deletions lib/config/config-validator.js
Expand Up @@ -116,7 +116,7 @@ function validateRuleSchema(rule, localOptions) {
* no source is prepended to the message.
* @returns {void}
*/
function validateRuleOptions(rule, ruleId, options, source) {
function validateRuleOptions(rule, ruleId, options, source = null) {
if (!rule) {
return;
}
Expand All @@ -140,11 +140,11 @@ function validateRuleOptions(rule, ruleId, options, source) {
/**
* Validates an environment object
* @param {Object} environment The environment config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {Environments} envContext Env context
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void}
*/
function validateEnvironment(environment, source, envContext) {
function validateEnvironment(environment, envContext, source = null) {

// not having an environment is ok
if (!environment) {
Expand All @@ -163,11 +163,11 @@ function validateEnvironment(environment, source, envContext) {
/**
* Validates a rules config object
* @param {Object} rulesConfig The rules config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {function(string): {create: Function}} ruleMapper A mapper function from strings to loaded rules
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void}
*/
function validateRules(rulesConfig, source, ruleMapper) {
function validateRules(rulesConfig, ruleMapper, source = null) {
if (!rulesConfig) {
return;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void}
*/
function validateConfigSchema(config, source) {
function validateConfigSchema(config, source = null) {
validateSchema = validateSchema || ajv.compile(configSchema);

if (!validateSchema(config)) {
Expand All @@ -252,19 +252,19 @@ function validateConfigSchema(config, source) {
/**
* Validates an entire config object.
* @param {Object} config The config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {function(string): {create: Function}} ruleMapper A mapper function from rule IDs to defined rules
* @param {Environments} envContext The env context
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void}
*/
function validate(config, source, ruleMapper, envContext) {
function validate(config, ruleMapper, envContext, source = null) {
validateConfigSchema(config, source);
validateRules(config.rules, source, ruleMapper);
validateEnvironment(config.env, source, envContext);
validateRules(config.rules, ruleMapper, source);
validateEnvironment(config.env, envContext, source);

for (const override of config.overrides || []) {
validateRules(override.rules, source, ruleMapper);
validateEnvironment(override.env, source, envContext);
validateRules(override.rules, ruleMapper, source);
validateEnvironment(override.env, envContext, source);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/testers/rule-tester.js
Expand Up @@ -379,7 +379,7 @@ class RuleTester {
}
}

validator.validate(config, "rule-tester", ruleMap.get.bind(ruleMap), new Environments());
validator.validate(config, ruleMap.get.bind(ruleMap), new Environments(), "rule-tester");

return {
messages: linter.verify(code, config, filename, true),
Expand Down

0 comments on commit 0f56dc6

Please sign in to comment.