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
…#8745)

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 authored Jun 18, 2017
1 parent c5b4052 commit 7a1bc38
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3905,6 +3905,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 7a1bc38

Please sign in to comment.