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

Commit

Permalink
Deprecate no-unused-variable rule (#1618)
Browse files Browse the repository at this point in the history
Resolves #1481. Adds a `deprecationMessage` field to rule metadata.
  • Loading branch information
adidahiya authored Oct 10, 2016
1 parent db0e417 commit 5cd9757
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/ruleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function loadRules(ruleConfiguration: {[name: string]: any},
const ruleSpecificList = (ruleName in enableDisableRuleMap ? enableDisableRuleMap[ruleName] : []);
const disabledIntervals = buildDisabledIntervalsFromSwitches(ruleSpecificList, allList);
rules.push(new Rule(ruleName, ruleValue, disabledIntervals));

if (Rule.metadata && Rule.metadata.deprecationMessage) {
console.warn(`${Rule.metadata.ruleName} is deprecated. ${Rule.metadata.deprecationMessage}`);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
38 changes: 19 additions & 19 deletions src/tslintMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5cd9757

Please sign in to comment.