From 270b48bdd484ab1dd02dcf8b06fc6821a2684ab3 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 19 May 2021 02:22:41 -0400 Subject: [PATCH] Added converter for react-tsx-curly-spacing --- .../lintConfigs/rules/ruleConverters.ts | 2 + .../ruleConverters/react-tsx-curly-spacing.ts | 18 ++++++ .../tests/react-tsx-curly-spacing.test.ts | 58 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/converters/lintConfigs/rules/ruleConverters/react-tsx-curly-spacing.ts create mode 100644 src/converters/lintConfigs/rules/ruleConverters/tests/react-tsx-curly-spacing.test.ts diff --git a/src/converters/lintConfigs/rules/ruleConverters.ts b/src/converters/lintConfigs/rules/ruleConverters.ts index 093edb285..7755e701c 100644 --- a/src/converters/lintConfigs/rules/ruleConverters.ts +++ b/src/converters/lintConfigs/rules/ruleConverters.ts @@ -124,6 +124,7 @@ import { convertPreferTemplate } from "./ruleConverters/prefer-template"; import { convertPromiseFunctionAsync } from "./ruleConverters/promise-function-async"; import { convertQuotemark } from "./ruleConverters/quotemark"; import { convertRadix } from "./ruleConverters/radix"; +import { convertReactTsxCurlySpacing } from "./ruleConverters/react-tsx-curly-spacing"; import { convertRestrictPlusOperands } from "./ruleConverters/restrict-plus-operands"; import { convertSemicolon } from "./ruleConverters/semicolon"; import { convertSpaceBeforeFunctionParen } from "./ruleConverters/space-before-function-paren"; @@ -391,6 +392,7 @@ export const ruleConverters = new Map([ ["promise-function-async", convertPromiseFunctionAsync], ["quotemark", convertQuotemark], ["radix", convertRadix], + ["react-tsx-curly-spacing", convertReactTsxCurlySpacing], ["relative-url-prefix", convertRelativeUrlPrefix], ["restrict-plus-operands", convertRestrictPlusOperands], ["semicolon", convertSemicolon], diff --git a/src/converters/lintConfigs/rules/ruleConverters/react-tsx-curly-spacing.ts b/src/converters/lintConfigs/rules/ruleConverters/react-tsx-curly-spacing.ts new file mode 100644 index 000000000..ea07c0311 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/react-tsx-curly-spacing.ts @@ -0,0 +1,18 @@ +import { RuleConverter } from "../ruleConverter"; + +export const convertReactTsxCurlySpacing: RuleConverter = (tslintRule) => { + return { + plugins: ["eslint-plugin-react"], + rules: [ + { + ruleArguments: [ + { + ...(tslintRule.ruleArguments.length > 1 && tslintRule.ruleArguments[1]), + 'when': tslintRule.ruleArguments[0], + } + ], + ruleName: "react/jsx-curly-spacing", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/tests/react-tsx-curly-spacing.test.ts b/src/converters/lintConfigs/rules/ruleConverters/tests/react-tsx-curly-spacing.test.ts new file mode 100644 index 000000000..4931650a8 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/tests/react-tsx-curly-spacing.test.ts @@ -0,0 +1,58 @@ +import { convertReactTsxCurlySpacing } from "../react-tsx-curly-spacing"; + +describe(convertReactTsxCurlySpacing, () => { + test("conversion with 'always'", () => { + const result = convertReactTsxCurlySpacing({ + ruleArguments: ['always'], + }); + + expect(result).toEqual({ + plugins: ["eslint-plugin-react"], + rules: [ + { + ruleArguments: [ + { when: 'always' } + ], + ruleName: "react/jsx-curly-spacing", + }, + ], + }); + }); + + test("conversion with 'never'", () => { + const result = convertReactTsxCurlySpacing({ + ruleArguments: ['never'], + }); + + expect(result).toEqual({ + plugins: ["eslint-plugin-react"], + rules: [ + { + ruleArguments: [ + { when: 'never' } + ], + ruleName: "react/jsx-curly-spacing", + }, + ], + }); + }); + + test("conversion with 'never' and 'allowMultiline'", () => { + const result = convertReactTsxCurlySpacing({ + ruleArguments: ['never', { allowMultiline: true }], + }); + + expect(result).toEqual({ + plugins: ["eslint-plugin-react"], + rules: [ + { + ruleArguments: [{ + allowMultiline: true, + when: 'never', + }], + ruleName: "react/jsx-curly-spacing", + }, + ], + }); + }); +});