From 4a10b3fe4b70a9b9fd341b4fbcd1bfc3786a22cc Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Wed, 2 Oct 2019 19:10:51 -0400 Subject: [PATCH 1/7] add converter for space-within-parens rule --- src/rules/converters.ts | 50 ++++++++++++++++--- src/rules/converters/space-within-parens.ts | 14 ++++++ .../tests/space-within-parens.test.ts | 32 ++++++++++++ 3 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 src/rules/converters/space-within-parens.ts create mode 100644 src/rules/converters/tests/space-within-parens.test.ts diff --git a/src/rules/converters.ts b/src/rules/converters.ts index f609001ae..f429a1769 100644 --- a/src/rules/converters.ts +++ b/src/rules/converters.ts @@ -103,6 +103,7 @@ import { convertRadix } from "./converters/radix"; import { convertRestrictPlusOperands } from "./converters/restrict-plus-operands"; import { convertSemicolon } from "./converters/semicolon"; import { convertSpaceBeforeFunctionParen } from "./converters/space-before-function-paren"; +import { convertSpaceWithinParens } from "./converters/space-within-parens"; import { convertSwitchDefault } from "./converters/switch-default"; import { convertTypedefWhitespace } from "./converters/typedef-whitespace"; import { convertTypeLiteralDelimiter } from "./converters/type-literal-delimiter"; @@ -235,19 +236,56 @@ export const converters = new Map([ ["unnecessary-constructor", convertUnnecessaryConstructor], ["use-default-type-parameter", convertUseDefaultTypeParameter], ["use-isnan", convertUseIsnan], + ["arrow-return-shorthand", convertArrowReturnShorthand], + ["curly", convertCurly], + ["cyclomatic-complexity", convertCyclomaticComplexity], + ["increment-decrement", convertIncrementDecrement], + ["linebreak-style", convertLinebreakStyle], + ["max-classes-per-file", convertMaxClassesPerFile], + ["max-file-line-count", convertMaxFileLineCount], + ["max-line-length", convertMaxLineLength], + ["no-consecutive-blank-lines", convertNoConsecutiveBlankLines], + ["no-console", convertNoConsole], + ["no-empty", convertNoEmpty], + ["no-invalid-template-strings", convertNoInvalidTemplateStrings], + ["no-invalid-this", convertNoInvalidThis], + ["no-magic-numbers", convertNoMagicNumbers], + ["object-literal-key-quotes", convertObjectLiteralKeyQuotes], + ["object-literal-shorthand", convertObjectLiteralShorthand], + ["one-variable-per-declaration", convertOneVariablePerDeclaration], + ["only-arrow-functions", convertOnlyArrowFunctions], + ["prefer-const", convertPreferConst], + ["prefer-function-over-method", convertPreferFunctionOverMethod], + ["prefer-readonly", convertPreferReadonly], + ["prefer-template", convertPreferTemplate], + ["space-before-function-paren", convertSpaceBeforeFunctionParen], + ["space-within-parens", convertSpaceWithinParens], + ["switch-default", convertSwitchDefault], + ["no-banned-terms", convertNoBannedTerms], + ["no-constant-condition", convertNoConstantCondition], + ["no-control-regex", convertNoControlRegex], + ["no-multiline-string", convertNoMultilineString], + ["no-invalid-regexp", convertNoInvalidRegexp], + ["no-octal-literal", convertNoOctalLiteral], + ["no-regex-spaces", convertNoRegexSpaces], + ["no-unnecessary-semicolons", convertNoUnnecessarySemicolons], + ["quotemark", convertQuotemark], + ["triple-equals", convertTripleEquals], - // These converters are all for rules that need more complex option conversions. - // Some of them will likely need to have notices about changed lint behaviors... - // If you're willing to take on that work, that'd be great! Please send PRs! 💖 - // As these are enabled, they should be added in sorted order to the list above. + // these converters are all for rules that need more complex option conversions. + // some of them will likely need to have notices about changed lint behaviors... + // if you're willing to take on that work, that'd be great! Please send PRs! 💖 + // as these are enabled, they should be added in sorted order to the list above. - // TSLint core rules: + // tSLint core rules: // ["ban", convertBan], // no-restricted-properties // ["import-blacklist", convertImportBlacklist], // no-restricted-imports // ["no-duplicate-variable", convertNoDuplicateVariable], // no-redeclare // ["no-shadowed-variable", convertNoShadowedVariable], // no-shadow // ["no-unused-expression", convertNoUnusedExpression], // no-unused-expressions - // ["space-within-parens", convertSpaceWithinParens], // space-in-parens + // ["no-void-expression", convertNoVoidExpression], // (no exact equivalent) + // ["quotemark", convertQuotemark], // quotes + // ["triple-equals", convertTripleEquals], // eqeqeq // ["variable-name", convertVariableName], // a bunch of rules... // tslint-microsoft-contrib rules: diff --git a/src/rules/converters/space-within-parens.ts b/src/rules/converters/space-within-parens.ts new file mode 100644 index 000000000..cf616e3ef --- /dev/null +++ b/src/rules/converters/space-within-parens.ts @@ -0,0 +1,14 @@ +import { RuleConverter } from "../converter"; + +export const convertSpaceWithinParens: RuleConverter = tslintRule => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments, + }), + ruleName: "@typescript-eslint/space-within-parens", + }, + ], + }; +}; diff --git a/src/rules/converters/tests/space-within-parens.test.ts b/src/rules/converters/tests/space-within-parens.test.ts new file mode 100644 index 000000000..e3a291874 --- /dev/null +++ b/src/rules/converters/tests/space-within-parens.test.ts @@ -0,0 +1,32 @@ +import { convertSpaceWithinParens } from "../space-within-parens"; + +describe(convertSpaceWithinParens, () => { + test("conversion without arguments", () => { + const result = convertSpaceWithinParens({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/space-within-parens", + }, + ], + }); + }); + + test("conversion with min spaces arguement", () => { + const result = convertSpaceWithinParens({ + ruleArguments: [5], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [5], + ruleName: "@typescript-eslint/space-within-parens", + }, + ], + }); + }); +}); From ee41b3638e2d39c4d952a237f0a4a10eedfbc776 Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Fri, 4 Oct 2019 08:31:52 -0400 Subject: [PATCH 2/7] convert rule to eslint equivalent --- src/rules/converters/space-within-parens.ts | 10 +++++++--- src/rules/converters/tests/space-within-parens.test.ts | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/rules/converters/space-within-parens.ts b/src/rules/converters/space-within-parens.ts index cf616e3ef..e619506dd 100644 --- a/src/rules/converters/space-within-parens.ts +++ b/src/rules/converters/space-within-parens.ts @@ -1,12 +1,16 @@ import { RuleConverter } from "../converter"; export const convertSpaceWithinParens: RuleConverter = tslintRule => { + let arg: string = ""; + if (tslintRule.ruleArguments.length === 1) { + arg = "always"; + } else { + arg = "never"; + } return { rules: [ { - ...(tslintRule.ruleArguments.length !== 0 && { - ruleArguments: tslintRule.ruleArguments, - }), + ruleArguments: [arg], ruleName: "@typescript-eslint/space-within-parens", }, ], diff --git a/src/rules/converters/tests/space-within-parens.test.ts b/src/rules/converters/tests/space-within-parens.test.ts index e3a291874..a3a8d9536 100644 --- a/src/rules/converters/tests/space-within-parens.test.ts +++ b/src/rules/converters/tests/space-within-parens.test.ts @@ -9,6 +9,7 @@ describe(convertSpaceWithinParens, () => { expect(result).toEqual({ rules: [ { + ruleArguments: ["never"], ruleName: "@typescript-eslint/space-within-parens", }, ], @@ -23,7 +24,7 @@ describe(convertSpaceWithinParens, () => { expect(result).toEqual({ rules: [ { - ruleArguments: [5], + ruleArguments: ["always"], ruleName: "@typescript-eslint/space-within-parens", }, ], From 1ec257155d49b04be74c7ced570505e286fde15a Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Fri, 4 Oct 2019 08:38:11 -0400 Subject: [PATCH 3/7] fix eslint error --- src/rules/converters/space-within-parens.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/converters/space-within-parens.ts b/src/rules/converters/space-within-parens.ts index e619506dd..7755f7572 100644 --- a/src/rules/converters/space-within-parens.ts +++ b/src/rules/converters/space-within-parens.ts @@ -1,7 +1,7 @@ import { RuleConverter } from "../converter"; export const convertSpaceWithinParens: RuleConverter = tslintRule => { - let arg: string = ""; + let arg = ""; if (tslintRule.ruleArguments.length === 1) { arg = "always"; } else { From c32d3473bef6bca37dc46bbddd11b21add320f99 Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Sat, 5 Oct 2019 18:05:23 -0400 Subject: [PATCH 4/7] add notices for space-within-parens --- src/rules/converters.ts | 2 +- src/rules/converters/space-within-parens.ts | 8 ++------ src/rules/converters/tests/space-within-parens.test.ts | 2 ++ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/rules/converters.ts b/src/rules/converters.ts index f429a1769..b384947ca 100644 --- a/src/rules/converters.ts +++ b/src/rules/converters.ts @@ -277,7 +277,7 @@ export const converters = new Map([ // if you're willing to take on that work, that'd be great! Please send PRs! 💖 // as these are enabled, they should be added in sorted order to the list above. - // tSLint core rules: + // TSLint core rules: // ["ban", convertBan], // no-restricted-properties // ["import-blacklist", convertImportBlacklist], // no-restricted-imports // ["no-duplicate-variable", convertNoDuplicateVariable], // no-redeclare diff --git a/src/rules/converters/space-within-parens.ts b/src/rules/converters/space-within-parens.ts index 7755f7572..43ed3bb37 100644 --- a/src/rules/converters/space-within-parens.ts +++ b/src/rules/converters/space-within-parens.ts @@ -1,17 +1,13 @@ import { RuleConverter } from "../converter"; export const convertSpaceWithinParens: RuleConverter = tslintRule => { - let arg = ""; - if (tslintRule.ruleArguments.length === 1) { - arg = "always"; - } else { - arg = "never"; - } + const arg = tslintRule.ruleArguments.length === 1 ? "always" : "never"; return { rules: [ { ruleArguments: [arg], ruleName: "@typescript-eslint/space-within-parens", + notices: ["The number of spaces will be ignored"], }, ], }; diff --git a/src/rules/converters/tests/space-within-parens.test.ts b/src/rules/converters/tests/space-within-parens.test.ts index a3a8d9536..b7b90c39a 100644 --- a/src/rules/converters/tests/space-within-parens.test.ts +++ b/src/rules/converters/tests/space-within-parens.test.ts @@ -11,6 +11,7 @@ describe(convertSpaceWithinParens, () => { { ruleArguments: ["never"], ruleName: "@typescript-eslint/space-within-parens", + notices: ["The number of spaces will be ignored"], }, ], }); @@ -26,6 +27,7 @@ describe(convertSpaceWithinParens, () => { { ruleArguments: ["always"], ruleName: "@typescript-eslint/space-within-parens", + notices: ["The number of spaces will be ignored"], }, ], }); From da9ff73daa4c66a2beb654f00f399875b75e00b6 Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Sun, 6 Oct 2019 17:49:09 -0400 Subject: [PATCH 5/7] add notice only if parameter supplied --- src/rules/converters.ts | 8 ++++---- src/rules/converters/space-within-parens.ts | 11 +++++++++-- .../converters/tests/space-within-parens.test.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/rules/converters.ts b/src/rules/converters.ts index b384947ca..d703a49c7 100644 --- a/src/rules/converters.ts +++ b/src/rules/converters.ts @@ -272,10 +272,10 @@ export const converters = new Map([ ["quotemark", convertQuotemark], ["triple-equals", convertTripleEquals], - // these converters are all for rules that need more complex option conversions. - // some of them will likely need to have notices about changed lint behaviors... - // if you're willing to take on that work, that'd be great! Please send PRs! 💖 - // as these are enabled, they should be added in sorted order to the list above. + // These converters are all for rules that need more complex option conversions. + // Some of them will likely need to have notices about changed lint behaviors... + // If you're willing to take on that work, that'd be great! Please send PRs! 💖 + // As these are enabled, they should be added in sorted order to the list above. // TSLint core rules: // ["ban", convertBan], // no-restricted-properties diff --git a/src/rules/converters/space-within-parens.ts b/src/rules/converters/space-within-parens.ts index 43ed3bb37..5f48b0f02 100644 --- a/src/rules/converters/space-within-parens.ts +++ b/src/rules/converters/space-within-parens.ts @@ -1,13 +1,20 @@ import { RuleConverter } from "../converter"; export const convertSpaceWithinParens: RuleConverter = tslintRule => { - const arg = tslintRule.ruleArguments.length === 1 ? "always" : "never"; + let arg = "never"; + const notices = []; + + if (tslintRule.ruleArguments.length === 1) { + arg = "always"; + notices.push("The number of spaces will be ignored"); + } + return { rules: [ { ruleArguments: [arg], ruleName: "@typescript-eslint/space-within-parens", - notices: ["The number of spaces will be ignored"], + notices, }, ], }; diff --git a/src/rules/converters/tests/space-within-parens.test.ts b/src/rules/converters/tests/space-within-parens.test.ts index b7b90c39a..e464d096f 100644 --- a/src/rules/converters/tests/space-within-parens.test.ts +++ b/src/rules/converters/tests/space-within-parens.test.ts @@ -11,7 +11,7 @@ describe(convertSpaceWithinParens, () => { { ruleArguments: ["never"], ruleName: "@typescript-eslint/space-within-parens", - notices: ["The number of spaces will be ignored"], + notices: [], }, ], }); From d2ebb885675cb905cc4d63c8f6cf85fcb50f79d8 Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Sun, 6 Oct 2019 17:55:16 -0400 Subject: [PATCH 6/7] fix duplicates from conflict --- src/rules/converters.ts | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/rules/converters.ts b/src/rules/converters.ts index d703a49c7..055027781 100644 --- a/src/rules/converters.ts +++ b/src/rules/converters.ts @@ -236,41 +236,6 @@ export const converters = new Map([ ["unnecessary-constructor", convertUnnecessaryConstructor], ["use-default-type-parameter", convertUseDefaultTypeParameter], ["use-isnan", convertUseIsnan], - ["arrow-return-shorthand", convertArrowReturnShorthand], - ["curly", convertCurly], - ["cyclomatic-complexity", convertCyclomaticComplexity], - ["increment-decrement", convertIncrementDecrement], - ["linebreak-style", convertLinebreakStyle], - ["max-classes-per-file", convertMaxClassesPerFile], - ["max-file-line-count", convertMaxFileLineCount], - ["max-line-length", convertMaxLineLength], - ["no-consecutive-blank-lines", convertNoConsecutiveBlankLines], - ["no-console", convertNoConsole], - ["no-empty", convertNoEmpty], - ["no-invalid-template-strings", convertNoInvalidTemplateStrings], - ["no-invalid-this", convertNoInvalidThis], - ["no-magic-numbers", convertNoMagicNumbers], - ["object-literal-key-quotes", convertObjectLiteralKeyQuotes], - ["object-literal-shorthand", convertObjectLiteralShorthand], - ["one-variable-per-declaration", convertOneVariablePerDeclaration], - ["only-arrow-functions", convertOnlyArrowFunctions], - ["prefer-const", convertPreferConst], - ["prefer-function-over-method", convertPreferFunctionOverMethod], - ["prefer-readonly", convertPreferReadonly], - ["prefer-template", convertPreferTemplate], - ["space-before-function-paren", convertSpaceBeforeFunctionParen], - ["space-within-parens", convertSpaceWithinParens], - ["switch-default", convertSwitchDefault], - ["no-banned-terms", convertNoBannedTerms], - ["no-constant-condition", convertNoConstantCondition], - ["no-control-regex", convertNoControlRegex], - ["no-multiline-string", convertNoMultilineString], - ["no-invalid-regexp", convertNoInvalidRegexp], - ["no-octal-literal", convertNoOctalLiteral], - ["no-regex-spaces", convertNoRegexSpaces], - ["no-unnecessary-semicolons", convertNoUnnecessarySemicolons], - ["quotemark", convertQuotemark], - ["triple-equals", convertTripleEquals], // These converters are all for rules that need more complex option conversions. // Some of them will likely need to have notices about changed lint behaviors... From b5f46de13ea89f804b5b962b88f0752259986449 Mon Sep 17 00:00:00 2001 From: Brandon Everett Date: Sun, 6 Oct 2019 18:39:29 -0400 Subject: [PATCH 7/7] make sure converter is actually used --- src/rules/converters.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rules/converters.ts b/src/rules/converters.ts index 055027781..40e81fe50 100644 --- a/src/rules/converters.ts +++ b/src/rules/converters.ts @@ -226,6 +226,7 @@ export const converters = new Map([ ["restrict-plus-operands", convertRestrictPlusOperands], ["semicolon", convertSemicolon], ["space-before-function-paren", convertSpaceBeforeFunctionParen], + ["space-within-parens", convertSpaceWithinParens], ["switch-default", convertSwitchDefault], ["triple-equals", convertTripleEquals], ["type-literal-delimiter", convertTypeLiteralDelimiter],