Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Fixed introduced compile error in rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Goldberg committed Jul 29, 2018
1 parent 9ea3c21 commit e5c7b1e
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/rules/variableNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand All @@ -117,7 +127,10 @@ function walk(ctx: Lint.WalkContext<Options>): 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);
}
}
Expand All @@ -143,7 +156,9 @@ function walk(ctx: Lint.WalkContext<Options>): 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) {
Expand Down

0 comments on commit e5c7b1e

Please sign in to comment.