Skip to content

Commit

Permalink
Breaking: validate parserOptions (fixes eslint#9687)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Mar 11, 2019
1 parent e7266c2 commit 90ce79a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/config/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,33 @@ function validate(config, source, ruleMapper, envContext) {
validateConfigSchema(config, source);
validateRules(config.rules, source, ruleMapper);
validateEnvironment(config.env, source, envContext);
validateParserOptions(config.parserOptions, source);

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

/**
* validate parserOptions
* @param {Object} parserOptions the parserOptions to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void}
*/
function validateParserOptions(parserOptions = {}, source) {
if (parserOptions.ecmaVersion) {
if (typeof parserOptions.ecmaVersion !== "number") {
throw new Error(`parserOptions.ecmaVersion must be a number (file:${source})!`);

}

if (parserOptions.ecmaVersion < 6 && parserOptions.sourceType === "module") {
throw new Error("sourceType 'module' is not supported in ecmaVersion < 6 (file:#{source})!");
}
}
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand Down

0 comments on commit 90ce79a

Please sign in to comment.