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

noUnusedVariableRule should apply the ignorePattern to imports #3187

Merged
merged 1 commit into from
Sep 26, 2017
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
16 changes: 8 additions & 8 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Rule extends Lint.Rules.TypedRule {
* NOTE: this option is experimental and does not work with classes
that use abstract method declarations, among other things.
* \`{"ignore-pattern": "pattern"}\` where pattern is a case-sensitive regexp.
Variable names that match the pattern will be ignored.`,
Variable names and imports that match the pattern will be ignored.`,
options: {
type: "array",
items: {
Expand Down Expand Up @@ -114,6 +114,13 @@ function walk(ctx: Lint.WalkContext<Options>, program: ts.Program): void {

const failure = ts.flattenDiagnosticMessageText(diag.messageText, "\n");

if (ignorePattern !== undefined) {
const varName = /'(.*)'/.exec(failure)![1];
if (ignorePattern.test(varName)) {
continue;
}
}

if (kind === UnusedKind.VARIABLE_OR_PARAMETER) {
const importName = findImport(diag.start, sourceFile);
if (importName !== undefined) {
Expand All @@ -129,13 +136,6 @@ function walk(ctx: Lint.WalkContext<Options>, program: ts.Program): void {
}
}

if (ignorePattern !== undefined) {
const varName = /'(.*)'/.exec(failure)![1];
if (ignorePattern.test(varName)) {
continue;
}
}

ctx.addFailureAt(diag.start, diag.length!, failure);
}

Expand Down
1 change: 1 addition & 0 deletions test/rules/no-unused-variable/ignore-pattern/a.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class _A {}
2 changes: 2 additions & 0 deletions test/rules/no-unused-variable/ignore-pattern/var.ts.lint
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { _A } from './a.test';

var x = 3;

var y = x;
Expand Down