From 152981430810d225379290eeb560fdb1d93f45c4 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 17:33:05 -0400 Subject: [PATCH] Deprecate no-unused-variable rule Resolves #1481. Adds a `deprecationMessage` field to rule metadata. --- src/configs/recommended.ts | 3 ++- src/language/rule/rule.ts | 5 ++++ src/ruleLoader.ts | 4 ++++ src/rules/noUnusedVariableRule.ts | 3 ++- src/tslintMulti.ts | 38 +++++++++++++++---------------- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 99b52e95cb7..0dada01a64f 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -68,7 +68,8 @@ export const rules = { "no-unreachable": true, "no-unused-expression": true, "no-unused-new": true, - "no-unused-variable": [true, "react"], + // deprecated as of v4.0 + "no-unused-variable": false, // disable this rule as it is very heavy performance-wise and not that useful "no-use-before-declare": false, "no-var-keyword": true, diff --git a/src/language/rule/rule.ts b/src/language/rule/rule.ts index a4311e425b7..01e257a29bf 100644 --- a/src/language/rule/rule.ts +++ b/src/language/rule/rule.ts @@ -30,6 +30,11 @@ export interface IRuleMetadata { */ type: RuleType; + /** + * A rule deprecation message, if applicable. + */ + deprecationMessage?: string; + /** * A short, one line description of what the rule does. */ diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index de2634c4849..ed1996bd263 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -49,6 +49,10 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, const disabledIntervals = buildDisabledIntervalsFromSwitches(ruleSpecificList, allList); rules.push(new Rule(ruleName, ruleValue, disabledIntervals)); } + + if (Rule.metadata.deprecationMessage != null) { + console.warn(`${Rule.metadata.ruleName} is deprecated. ${Rule.metadata.deprecationMessage}`); + } } } diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 886ed620b0a..a20b24b625d 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ public static metadata: Lint.IRuleMetadata = { ruleName: "no-unused-variable", + deprecationMessage: "Use the compiler options --noUnusedParameters and --noUnusedLocals instead.", description: "Disallows unused imports, variables, functions and private class members.", optionsDescription: Lint.Utils.dedent` Three optional arguments may be optionally provided: @@ -331,7 +332,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker { node.modifiers, ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, - ts.SyntaxKind.ProtectedKeyword + ts.SyntaxKind.ProtectedKeyword, ); if (!isSingleVariable && isPropertyParameter) { diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 471fd636e37..7ef35aa9435 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -132,25 +132,25 @@ class MultiLinter { } public getResult(): LintResult { - let formatter: IFormatter; - const formattersDirectory = getRelativePath(this.options.formattersDirectory); - - const formatterName = this.options.formatter || "prose"; - const Formatter = findFormatter(formatterName, formattersDirectory); - if (Formatter) { - formatter = new Formatter(); - } else { - throw new Error(`formatter '${formatterName}' not found`); - } - - const output = formatter.format(this.failures); - - return { - failureCount: this.failures.length, - failures: this.failures, - format: formatterName, - output, - }; + let formatter: IFormatter; + const formattersDirectory = getRelativePath(this.options.formattersDirectory); + + const formatterName = this.options.formatter || "prose"; + const Formatter = findFormatter(formatterName, formattersDirectory); + if (Formatter) { + formatter = new Formatter(); + } else { + throw new Error(`formatter '${formatterName}' not found`); + } + + const output = formatter.format(this.failures); + + return { + failureCount: this.failures.length, + failures: this.failures, + format: formatterName, + output, + }; } private containsRule(rules: RuleFailure[], rule: RuleFailure) {