diff --git a/src/rules/variableNameRule.ts b/src/rules/variableNameRule.ts index 678c5d7a6ea..61c00f98613 100644 --- a/src/rules/variableNameRule.ts +++ b/src/rules/variableNameRule.ts @@ -23,9 +23,19 @@ import * as ts from "typescript"; import * as Lint from "../index"; import { isLowerCase, isUpperCase } from "../utils"; -const BANNED_KEYWORDS = ["any", "Number", "number", "String", "string", "Boolean", "boolean", "Undefined", "undefined"]; +const BANNED_KEYWORDS = [ + "any", + "Number", + "number", + "String", + "string", + "Boolean", + "boolean", + "Undefined", + "undefined" +]; const bannedKeywordsSet = new Set(BANNED_KEYWORDS); -const bannedKeywordsStr = BANNED_KEYWORDS.map((kw) => `\`${kw}\``).join(", "); +const bannedKeywordsStr = BANNED_KEYWORDS.map(kw => `\`${kw}\``).join(", "); const OPTION_LEADING_UNDERSCORE = "allow-leading-underscore"; const OPTION_TRAILING_UNDERSCORE = "allow-trailing-underscore"; @@ -60,15 +70,15 @@ export class Rule extends Lint.Rules.AbstractRule { OPTION_TRAILING_UNDERSCORE, OPTION_ALLOW_PASCAL_CASE, OPTION_ALLOW_SNAKE_CASE, - OPTION_BAN_KEYWORDS, - ], + OPTION_BAN_KEYWORDS + ] }, minLength: 0, - maxLength: 6, + maxLength: 6 }, optionExamples: [[true, "ban-keywords", "check-format", "allow-leading-underscore"]], type: "style", - typescriptOnly: false, + typescriptOnly: false }; public static KEYWORD_FAILURE = "variable name clashes with keyword/type"; @@ -99,7 +109,7 @@ function parseOptions(ruleArguments: string[]): Options { trailingUnderscore: hasOption(OPTION_TRAILING_UNDERSCORE), allCapsForConst: hasOption(OPTION_CONST_ONLY_FOR_CAPS), allowPascalCase: hasOption(OPTION_ALLOW_PASCAL_CASE), - allowSnakeCase: hasOption(OPTION_ALLOW_SNAKE_CASE), + allowSnakeCase: hasOption(OPTION_ALLOW_SNAKE_CASE) }; function hasOption(name: string): boolean { @@ -117,7 +127,10 @@ function walk(ctx: Lint.WalkContext): void { handleVariableNameKeyword(name); // A destructuring pattern that does not rebind an expression is always an alias, e.g. `var {Foo} = ...;`. // Only check if the name is rebound (`var {Foo: bar} = ...;`). - if (node.parent!.kind !== ts.SyntaxKind.ObjectBindingPattern || propertyName !== undefined) { + if ( + node.parent!.kind !== ts.SyntaxKind.ObjectBindingPattern || + propertyName !== undefined + ) { handleVariableNameFormat(name, initializer); } } @@ -143,7 +156,9 @@ function walk(ctx: Lint.WalkContext): void { return ts.forEachChild(node, cb); }); - function handleDeclaredVariable(node: ts.ParameterDeclaration | ts.PropertyDeclaration): void { + function handleDeclaredVariable( + node: ts.ParameterDeclaration | ts.PropertyDeclaration | ts.VariableDeclaration + ): void { const { name, initializer } = node; if (name.kind === ts.SyntaxKind.Identifier) {