Merge pull request babel/babel-eslint#282 from josh/no-implicit-globals-regression
Fix processing sourceType: script
This commit is contained in:
parent
cccce9d0ab
commit
1fe0d4a94b
@ -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;
|
||||||
|
|||||||
@ -2,10 +2,8 @@
|
|||||||
"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(".."),
|
parser: require.resolve(".."),
|
||||||
rules: rules,
|
rules: rules,
|
||||||
env: {
|
env: {
|
||||||
@ -22,7 +20,14 @@ function verifyAndAssertMessages(code, rules, expectedMessages, sourceType) {
|
|||||||
sourceType: sourceType || "module"
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user