From 0dedf5ee4d9072cd40d4e006f6c445d61438335f Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Sun, 26 Apr 2020 17:34:35 -0500 Subject: [PATCH 1/2] Add no-unused-variable converter --- src/rules/converters/no-unused-variable.ts | 20 +++++++++++++++++ .../tests/no-unused-variable.test.ts | 22 +++++++++++++++++++ src/rules/rulesConverters.ts | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 src/rules/converters/no-unused-variable.ts create mode 100644 src/rules/converters/tests/no-unused-variable.test.ts diff --git a/src/rules/converters/no-unused-variable.ts b/src/rules/converters/no-unused-variable.ts new file mode 100644 index 00000000..beaec221 --- /dev/null +++ b/src/rules/converters/no-unused-variable.ts @@ -0,0 +1,20 @@ +import { RuleConverter } from "../converter"; + +export const NO_UNUSED_VARIABLE_NOTICE = + "Please read the following article as the rule behaviour may change on the short term: " + + "https://github.com/typescript-eslint/typescript-eslint/issues/1856"; + +export const convertNoUnusedVariable: RuleConverter = () => { + return { + rules: [ + { + ruleName: "@typescript-eslint/no-unused-vars", + notices: [NO_UNUSED_VARIABLE_NOTICE], + }, + { + ruleName: "no-unused-vars", + ruleArguments: ["off"], + }, + ], + }; +}; diff --git a/src/rules/converters/tests/no-unused-variable.test.ts b/src/rules/converters/tests/no-unused-variable.test.ts new file mode 100644 index 00000000..4792b672 --- /dev/null +++ b/src/rules/converters/tests/no-unused-variable.test.ts @@ -0,0 +1,22 @@ +import { convertNoUnusedVariable, NO_UNUSED_VARIABLE_NOTICE } from "../no-unused-variable"; + +describe(convertNoUnusedVariable, () => { + test("conversion without arguments", () => { + const result = convertNoUnusedVariable({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/no-unused-vars", + notices: [NO_UNUSED_VARIABLE_NOTICE], + }, + { + ruleName: "no-unused-vars", + ruleArguments: ["off"], + }, + ], + }); + }); +}); diff --git a/src/rules/rulesConverters.ts b/src/rules/rulesConverters.ts index 95671e19..8d0d8be4 100644 --- a/src/rules/rulesConverters.ts +++ b/src/rules/rulesConverters.ts @@ -99,6 +99,7 @@ import { convertNoUnnecessarySemicolons } from "./converters/no-unnecessary-semi import { convertNoUnnecessaryTypeAssertion } from "./converters/no-unnecessary-type-assertion"; import { convertNoUnsafeFinally } from "./converters/no-unsafe-finally"; import { convertNoUnusedExpression } from "./converters/no-unused-expression"; +import { convertNoUnusedVariable } from "./converters/no-unused-variable"; import { convertNoUseBeforeDeclare } from "./converters/no-use-before-declare"; import { convertNoVarKeyword } from "./converters/no-var-keyword"; import { convertNoVarRequires } from "./converters/no-var-requires"; @@ -240,6 +241,7 @@ export const rulesConverters = new Map([ ["no-unnecessary-type-assertion", convertNoUnnecessaryTypeAssertion], ["no-unsafe-finally", convertNoUnsafeFinally], ["no-unused-expression", convertNoUnusedExpression], + ["no-unused-variable", convertNoUnusedVariable], ["no-use-before-declare", convertNoUseBeforeDeclare], ["no-var-keyword", convertNoVarKeyword], ["no-var-requires", convertNoVarRequires], From 6a84204fe0c6573e20fafc4a2f193d969be89005 Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Tue, 28 Apr 2020 21:03:08 -0500 Subject: [PATCH 2/2] remove extra rule output on no-unused-variable --- src/rules/converters/no-unused-variable.ts | 4 ---- src/rules/converters/tests/no-unused-variable.test.ts | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/rules/converters/no-unused-variable.ts b/src/rules/converters/no-unused-variable.ts index beaec221..5486a4a8 100644 --- a/src/rules/converters/no-unused-variable.ts +++ b/src/rules/converters/no-unused-variable.ts @@ -11,10 +11,6 @@ export const convertNoUnusedVariable: RuleConverter = () => { ruleName: "@typescript-eslint/no-unused-vars", notices: [NO_UNUSED_VARIABLE_NOTICE], }, - { - ruleName: "no-unused-vars", - ruleArguments: ["off"], - }, ], }; }; diff --git a/src/rules/converters/tests/no-unused-variable.test.ts b/src/rules/converters/tests/no-unused-variable.test.ts index 4792b672..ddfd0322 100644 --- a/src/rules/converters/tests/no-unused-variable.test.ts +++ b/src/rules/converters/tests/no-unused-variable.test.ts @@ -12,10 +12,6 @@ describe(convertNoUnusedVariable, () => { ruleName: "@typescript-eslint/no-unused-vars", notices: [NO_UNUSED_VARIABLE_NOTICE], }, - { - ruleName: "no-unused-vars", - ruleArguments: ["off"], - }, ], }); });