diff --git a/src/converters/lintConfigs/rules/ruleConverters.ts b/src/converters/lintConfigs/rules/ruleConverters.ts index 4baf906e4..cf0b85f27 100644 --- a/src/converters/lintConfigs/rules/ruleConverters.ts +++ b/src/converters/lintConfigs/rules/ruleConverters.ts @@ -176,6 +176,7 @@ import { convertUsePipeDecorator } from "./ruleConverters/codelyzer/use-pipe-dec import { convertUsePipeTransformInterface } from "./ruleConverters/codelyzer/use-pipe-transform-interface"; // ESLint-React converters +import { convertJsxBanProps } from "./ruleConverters/eslint-plugin-react/jsx-ban-props"; import { convertJsxBooleanValue } from "./ruleConverters/eslint-plugin-react/jsx-boolean-value"; import { convertJsxCurlySpacing } from "./ruleConverters/eslint-plugin-react/jsx-curly-spacing"; import { convertJsxEqualsSpacing } from "./ruleConverters/eslint-plugin-react/jsx-equals-spacing"; @@ -237,6 +238,7 @@ export const ruleConverters = new Map([ ["interface-name", convertInterfaceName], ["interface-over-type-literal", convertInterfaceOverTypeLiteral], ["jsdoc-format", convertJSDocFormat], + ["jsx-ban-props", convertJsxBanProps], ["jsx-boolean-value", convertJsxBooleanValue], ["jsx-curly-spacing", convertJsxCurlySpacing], ["jsx-equals-spacing", convertJsxEqualsSpacing], diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-react/jsx-ban-props.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-react/jsx-ban-props.ts new file mode 100644 index 000000000..d66dae7e6 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-react/jsx-ban-props.ts @@ -0,0 +1,23 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertJsxBanProps: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments.map((ruleArgument) => ({ + forbid: + ruleArgument.length === 1 + ? ruleArgument[0] + : { + message: ruleArgument[1], + propName: ruleArgument[0], + }, + })), + }), + ruleName: "react/forbid-component-props", + }, + ], + plugins: ["eslint-plugin-react"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-react/tests/jsx-ban-props.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-react/tests/jsx-ban-props.test.ts new file mode 100644 index 000000000..ed9559684 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-react/tests/jsx-ban-props.test.ts @@ -0,0 +1,64 @@ +import { convertJsxBanProps } from "../jsx-ban-props"; + +describe(convertJsxBanProps, () => { + test("conversion without arguments", () => { + const result = convertJsxBanProps({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "react/forbid-component-props", + }, + ], + plugins: ["eslint-plugin-react"], + }); + }); + + test("conversion with a single prop", () => { + const result = convertJsxBanProps({ + ruleArguments: [["someProp"]], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [ + { + forbid: "someProp", + }, + ], + ruleName: "react/forbid-component-props", + }, + ], + plugins: ["eslint-plugin-react"], + }); + }); + + test("conversion with a message", () => { + const result = convertJsxBanProps({ + ruleArguments: [["someProp"], ["anotherProp", "Optional explanation"]], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [ + { + forbid: "someProp", + }, + { + forbid: { + message: "Optional explanation", + propName: "anotherProp", + }, + }, + ], + ruleName: "react/forbid-component-props", + }, + ], + plugins: ["eslint-plugin-react"], + }); + }); +});