Skip to content

Commit

Permalink
Fix: don't pass default parserOptions to custom parsers (fixes #8744)
Browse files Browse the repository at this point in the history
afbea78 accidentally introduced a regression where parsers would get passed additional "default" options even when the user did not specify them. This updates the default parserOptions to prevent any unexpected options from getting passed to parsers.
  • Loading branch information
not-an-aardvark committed Jun 16, 2017
1 parent 5f81a68 commit 720d015
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 1 addition & 5 deletions conf/default-config-options.js
Expand Up @@ -25,9 +25,5 @@ module.exports = deepFreeze({
rules: {},
settings: {},
parser: "espree",
parserOptions: {
ecmaVersion: 5,
sourceType: "script",
ecmaFeatures: {}
}
parserOptions: {}
});
4 changes: 2 additions & 2 deletions lib/linter.js
Expand Up @@ -455,8 +455,8 @@ function normalizeEcmaVersion(ecmaVersion, isModule) {
*/
function prepareConfig(config, envContext) {
config.globals = config.globals || {};
const copiedRules = Object.assign({}, defaultConfig.rules);
let parserOptions = Object.assign({}, defaultConfig.parserOptions);
const copiedRules = {};
let parserOptions = {};

if (typeof config.rules === "object") {
Object.keys(config.rules).forEach(k => {
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/parsers/throws-with-options.js
@@ -0,0 +1,10 @@
"use strict";

const espree = require("espree");

exports.parse = (sourceText, options) => {
if (options.ecmaVersion) {
throw new Error("Expected no parserOptions to be used");
}
return espree.parse(sourceText, options);
};
7 changes: 7 additions & 0 deletions tests/lib/eslint.js
Expand Up @@ -3860,6 +3860,13 @@ describe("eslint", () => {
assert.equal(messages[0].message, errorPrefix + require(parser).expectedError);
});

it("should not pass any default parserOptions to the parser", () => {
const parser = path.join(parserFixtures, "throws-with-options.js");

const messages = linter.verify(";", { parser }, "filename");

assert.strictEqual(messages.length, 0);
});
});
}

Expand Down

0 comments on commit 720d015

Please sign in to comment.