Skip to content
Permalink
Browse files
Fix: camelcase ignoreGlobals shouldn't apply to undef vars (refs #14857
…) (#14966)
  • Loading branch information
mdjermanovic committed Aug 24, 2021
1 parent b301069 commit 3409785a41a5bd2b128ed11b8baf7a59f9e412ee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
@@ -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);
}
}
}

@@ -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" },

0 comments on commit 3409785

Please sign in to comment.