aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/noUnusedVariableRule.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/rules/noUnusedVariableRule.js')
-rw-r--r--node_modules/tslint/lib/rules/noUnusedVariableRule.js24
1 files changed, 10 insertions, 14 deletions
diff --git a/node_modules/tslint/lib/rules/noUnusedVariableRule.js b/node_modules/tslint/lib/rules/noUnusedVariableRule.js
index 02506f434..b7b9f6fe4 100644
--- a/node_modules/tslint/lib/rules/noUnusedVariableRule.js
+++ b/node_modules/tslint/lib/rules/noUnusedVariableRule.js
@@ -29,19 +29,15 @@ var Rule = /** @class */ (function (_super) {
}
/* tslint:enable:object-literal-sort-keys */
Rule.prototype.applyWithProgram = function (sourceFile, program) {
- var x = program.getCompilerOptions();
- if (x.noUnusedLocals && x.noUnusedParameters) {
- console.warn("WARNING: 'no-unused-variable' lint rule does not need to be set if " +
- "the 'no-unused-locals' and 'no-unused-parameters' compiler options are enabled.");
- }
return this.applyWithFunction(sourceFile, walk, parseOptions(this.ruleArguments), program);
};
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-unused-variable",
description: (_a = ["Disallows unused imports, variables, functions and\n private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals\n options, but does not interrupt code compilation."], _a.raw = ["Disallows unused imports, variables, functions and\n private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals\n options, but does not interrupt code compilation."], Lint.Utils.dedent(_a)),
+ descriptionDetails: (_b = ["\n In addition to avoiding compilation errors, this rule may still be useful if you\n wish to have `tslint` automatically remove unused imports, variables, functions,\n and private class members, when using TSLint's `--fix` option."], _b.raw = ["\n In addition to avoiding compilation errors, this rule may still be useful if you\n wish to have \\`tslint\\` automatically remove unused imports, variables, functions,\n and private class members, when using TSLint's \\`--fix\\` option."], Lint.Utils.dedent(_b)),
hasFix: true,
- optionsDescription: (_b = ["\n Three optional arguments may be optionally provided:\n\n * `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\n Variable names that match the pattern will be ignored."], _b.raw = ["\n Three optional arguments may be optionally provided:\n\n * \\`\"check-parameters\"\\` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * \\`{\"ignore-pattern\": \"pattern\"}\\` where pattern is a case-sensitive regexp.\n Variable names that match the pattern will be ignored."], Lint.Utils.dedent(_b)),
+ optionsDescription: (_c = ["\n Three optional arguments may be optionally provided:\n\n * `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\n Variable names and imports that match the pattern will be ignored."], _c.raw = ["\n Three optional arguments may be optionally provided:\n\n * \\`\"check-parameters\"\\` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n * \\`{\"ignore-pattern\": \"pattern\"}\\` where pattern is a case-sensitive regexp.\n Variable names and imports that match the pattern will be ignored."], Lint.Utils.dedent(_c)),
options: {
type: "array",
items: {
@@ -78,7 +74,7 @@ function parseOptions(options) {
if (typeof o === "object") {
// tslint:disable-next-line no-unsafe-any
var ignore = o[OPTION_IGNORE_PATTERN];
- if (ignore != null) {
+ if (ignore != undefined) {
ignorePattern = new RegExp(ignore);
break;
}
@@ -104,6 +100,12 @@ function walk(ctx, program) {
continue;
}
var failure = ts.flattenDiagnosticMessageText(diag.messageText, "\n");
+ if (ignorePattern !== undefined) {
+ var varName = /'(.*)'/.exec(failure)[1];
+ if (ignorePattern.test(varName)) {
+ continue;
+ }
+ }
if (kind === 0 /* VARIABLE_OR_PARAMETER */) {
var importName = findImport(diag.start, sourceFile);
if (importName !== undefined) {
@@ -117,12 +119,6 @@ function walk(ctx, program) {
continue;
}
}
- if (ignorePattern !== undefined) {
- var varName = /'(.*)'/.exec(failure)[1];
- if (ignorePattern.test(varName)) {
- continue;
- }
- }
ctx.addFailureAt(diag.start, diag.length, failure);
}
if (importSpecifierFailures.size !== 0) {
@@ -375,4 +371,4 @@ function makeUnusedCheckedProgram(program, checkParameters) {
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
}
}
-var _a, _b;
+var _a, _b, _c;