Skip to content

Commit

Permalink
fix: add more invalid tests for global variable leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Oct 13, 2022
1 parent c7b6c6a commit 0c32702
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/lib/rules/no-implicit-globals.js
Expand Up @@ -1551,6 +1551,73 @@ ruleTester.run("no-implicit-globals", rule, {
type: "VariableDeclarator"
}
]
},

// Global variable leaks
{
code: "/* exported foo */ foo = 1",
errors: [
{
message: leakMessage,
type: "AssignmentExpression"
}
]
},
{
code: "/* exported foo */ foo = function() {};",
errors: [
{
message: leakMessage,
type: "AssignmentExpression"
}
]
},
{
code: "/* exported foo */ foo = function*() {};",
parserOptions: { ecmaVersion: 2015 },
errors: [
{
message: leakMessage,
type: "AssignmentExpression"
}
]
},
{
code: "/* exported foo */ window.foo = function() { bar = 1; }",
errors: [
{
message: leakMessage,
type: "AssignmentExpression"
}
]
},
{
code: "/* exported foo */ (function() {}(foo = 1));",
errors: [
{
message: leakMessage,
type: "AssignmentExpression"
}
]
},
{
code: "/* exported foo */ for (foo in {});",
errors: [
{
message: leakMessage,
type: "ForInStatement"
}
]
},
{
code: "/* exported foo */ for (foo of []);",
parserOptions: { ecmaVersion: 2015 },
errors: [
{
message: leakMessage,
type: "ForOfStatement"
}
]
}
]
});

0 comments on commit 0c32702

Please sign in to comment.