Skip to content

Commit

Permalink
Fix: camelcase ignoreGlobals shouldn't apply to undef vars (refs #14857
Browse files Browse the repository at this point in the history
…) (#14966)
  • Loading branch information
mdjermanovic committed Aug 24, 2021
1 parent b301069 commit 3409785
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/rules/camelcase.js
Expand Up @@ -240,27 +240,26 @@ module.exports = {

// Report camelcase of global variable references ------------------
Program() {
if (ignoreGlobals) {
return;
}

const scope = context.getScope();

// Defined globals in config files or directive comments.
for (const variable of scope.variables) {
if (
variable.identifiers.length > 0 ||
isGoodName(variable.name)
) {
continue;
}
for (const reference of variable.references) {
if (!ignoreGlobals) {

/*
* For backward compatibility, this rule reports read-only
* references as well.
*/
reportReferenceId(reference.identifier);
// Defined globals in config files or directive comments.
for (const variable of scope.variables) {
if (
variable.identifiers.length > 0 ||
isGoodName(variable.name)
) {
continue;
}
for (const reference of variable.references) {

/*
* For backward compatibility, this rule reports read-only
* references as well.
*/
reportReferenceId(reference.identifier);
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/camelcase.js
Expand Up @@ -1011,6 +1011,28 @@ ruleTester.run("camelcase", rule, {
}
]
},
{
code: "undefined_variable;",
options: [{ ignoreGlobals: true }],
errors: [
{
messageId: "notCamelCase",
data: { name: "undefined_variable" },
type: "Identifier"
}
]
},
{
code: "implicit_global = 1;",
options: [{ ignoreGlobals: true }],
errors: [
{
messageId: "notCamelCase",
data: { name: "implicit_global" },
type: "Identifier"
}
]
},
{
code: "export * as snake_cased from 'mod'",
parserOptions: { ecmaVersion: 2020, sourceType: "module" },
Expand Down

0 comments on commit 3409785

Please sign in to comment.