Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: camelcase ignoreGlobals shouldn't apply to undef vars (refs #14857) #14966

Merged
merged 1 commit into from Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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