From 3409785a41a5bd2b128ed11b8baf7a59f9e412ee Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Tue, 24 Aug 2021 02:39:24 +0200 Subject: [PATCH] Fix: camelcase ignoreGlobals shouldn't apply to undef vars (refs #14857) (#14966) --- lib/rules/camelcase.js | 35 +++++++++++++++++------------------ tests/lib/rules/camelcase.js | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js index 5d2babd9fc7..52d44deb994 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -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); + } } } diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index c336677dc86..514eb85d2ef 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -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" },