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

Commit

Permalink
Merge pull request #995 from palantir/ad/no-unused-variable
Browse files Browse the repository at this point in the history
Save RegExp as class member in no-unused-variable
  • Loading branch information
jkillian committed Feb 23, 2016
2 parents 85cd96d + 1ced9b7 commit 79a0977
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
private skipParameterDeclaration: boolean;
private skipVariableDeclaration: boolean;

private reactImport: ts.NamespaceImport;
private hasSeenJsxElement: boolean;
private ignorePattern: RegExp;
private isReactUsed: boolean;
private reactImport: ts.NamespaceImport;

constructor(sourceFile: ts.SourceFile, options: Lint.IOptions, languageService: ts.LanguageService) {
super(sourceFile, options);
Expand All @@ -52,6 +53,13 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
this.skipParameterDeclaration = false;
this.hasSeenJsxElement = false;
this.isReactUsed = false;

const ignorePatternOption = this.getOptions().filter((option: any) => {
return typeof option === "object" && option["ignore-pattern"] != null;
})[0];
if (ignorePatternOption != null) {
this.ignorePattern = new RegExp(ignorePatternOption["ignore-pattern"]);
}
}

public visitSourceFile(node: ts.SourceFile) {
Expand Down Expand Up @@ -288,14 +296,6 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
}

private isIgnored(name: string) {
const options = this.getOptions();
for (const option of options) {
if (typeof option === "object") {
const {"ignore-pattern": ignorePattern} = option;
if (ignorePattern != null) {
return new RegExp(ignorePattern).test(name);
}
}
}
return this.ignorePattern != null && this.ignorePattern.test(name);
}
}

0 comments on commit 79a0977

Please sign in to comment.