Merge pull request babel/babel-eslint#282 from josh/no-implicit-globals-regression

Fix processing sourceType: script
This commit is contained in:
Henry Zhu 2016-03-31 16:49:31 -04:00
parent cccce9d0ab
commit 1fe0d4a94b
2 changed files with 50 additions and 20 deletions

View File

@ -76,7 +76,6 @@ function monkeypatch() {
var analyze = escope.analyze; var analyze = escope.analyze;
escope.analyze = function (ast, opts) { escope.analyze = function (ast, opts) {
opts.ecmaVersion = 6; opts.ecmaVersion = 6;
opts.sourceType = "module";
var results = analyze.call(this, ast, opts); var results = analyze.call(this, ast, opts);
return results; return results;

View File

@ -2,27 +2,32 @@
"use strict"; "use strict";
var eslint = require("eslint"); var eslint = require("eslint");
function verifyAndAssertMessages(code, rules, expectedMessages, sourceType) { function verifyAndAssertMessages(code, rules, expectedMessages, sourceType, overrideConfig) {
var messages = eslint.linter.verify( var config = {
code, parser: require.resolve(".."),
{ rules: rules,
parser: require.resolve(".."), env: {
rules: rules, node: true,
env: { es6: true
node: true, },
es6: true parserOptions: {
ecmaVersion: 6,
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true,
globalReturn: true
}, },
parserOptions: { sourceType: sourceType || "module"
ecmaVersion: 6,
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true,
globalReturn: true
},
sourceType: sourceType || "module"
}
} }
); }
if (overrideConfig) {
for (var key in overrideConfig) {
config[key] = overrideConfig[key]
}
}
var messages = eslint.linter.verify(code, config);
if (messages.length !== expectedMessages.length) { if (messages.length !== expectedMessages.length) {
throw new Error("Expected " + expectedMessages.length + " message(s), got " + messages.length + " " + JSON.stringify(messages)); throw new Error("Expected " + expectedMessages.length + " message(s), got " + messages.length + " " + JSON.stringify(messages));
@ -1137,6 +1142,32 @@ describe("verify", function () {
); );
}); });
it("no-implicit-globals in script", function () {
verifyAndAssertMessages(
"var leakedGlobal = 1;",
{ "no-implicit-globals": 1 },
[ "1:5 Implicit global variable, assign as global property instead. no-implicit-globals" ],
"script",
{
env: {},
parserOptions: { ecmaVersion: 6, sourceType: "script" }
}
);
});
it("no-implicit-globals in module", function () {
verifyAndAssertMessages(
"var leakedGlobal = 1;",
{ "no-implicit-globals": 1 },
[],
"module",
{
env: {},
parserOptions: { ecmaVersion: 6, sourceType: "module" }
}
);
});
// This two tests are disabled, as the feature to visit properties when // This two tests are disabled, as the feature to visit properties when
// there is a spread/rest operator has been removed as it caused problems // there is a spread/rest operator has been removed as it caused problems
// with other rules #249 // with other rules #249