From 75853599e072200816b55a3928c8558b76863f33 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 22 May 2021 22:27:03 -0400 Subject: [PATCH] Added rule converter for react-a11y-anchors --- .../lintConfigs/rules/ruleConverters.ts | 2 + .../ruleConverters/react-a11y-anchors.ts | 15 +++++++ .../tests/react-a11y-anchors.test.ts | 40 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/converters/lintConfigs/rules/ruleConverters/react-a11y-anchors.ts create mode 100644 src/converters/lintConfigs/rules/ruleConverters/tests/react-a11y-anchors.test.ts diff --git a/src/converters/lintConfigs/rules/ruleConverters.ts b/src/converters/lintConfigs/rules/ruleConverters.ts index 0b4286cc5..77703055c 100644 --- a/src/converters/lintConfigs/rules/ruleConverters.ts +++ b/src/converters/lintConfigs/rules/ruleConverters.ts @@ -129,6 +129,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 { convertReactA11yAnchors } from "./ruleConverters/react-a11y-anchors"; import { convertRestrictPlusOperands } from "./ruleConverters/restrict-plus-operands"; import { convertSemicolon } from "./ruleConverters/semicolon"; import { convertSpaceBeforeFunctionParen } from "./ruleConverters/space-before-function-paren"; @@ -403,6 +404,7 @@ export const ruleConverters = new Map([ ["quotemark", convertQuotemark], ["radix", convertRadix], ["relative-url-prefix", convertRelativeUrlPrefix], + ["react-a11y-anchors", convertReactA11yAnchors], ["restrict-plus-operands", convertRestrictPlusOperands], ["semicolon", convertSemicolon], ["space-before-function-paren", convertSpaceBeforeFunctionParen], diff --git a/src/converters/lintConfigs/rules/ruleConverters/react-a11y-anchors.ts b/src/converters/lintConfigs/rules/ruleConverters/react-a11y-anchors.ts new file mode 100644 index 000000000..6b7a8951d --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/react-a11y-anchors.ts @@ -0,0 +1,15 @@ +import { RuleConverter } from "../ruleConverter"; + +export const convertReactA11yAnchors: RuleConverter = (tslintRule) => { + return { + ...(tslintRule.ruleArguments.length > 0 && ({ + notices: Object.keys(tslintRule.ruleArguments[0] as Record).map(key => `jsx-a11y/anchor-is-valid does not support the '${key}' option.`) + })), + plugins: ["jsx-a11y"], + rules: [ + { + ruleName: "jsx-a11y/anchor-is-valid", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/tests/react-a11y-anchors.test.ts b/src/converters/lintConfigs/rules/ruleConverters/tests/react-a11y-anchors.test.ts new file mode 100644 index 000000000..102732666 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/tests/react-a11y-anchors.test.ts @@ -0,0 +1,40 @@ +import { convertReactA11yAnchors } from "../react-a11y-anchors"; + +describe(convertReactA11yAnchors, () => { + test("conversion without arguments", () => { + const result = convertReactA11yAnchors({ + ruleArguments: [], + }); + + expect(result).toEqual({ + plugins: ["jsx-a11y"], + rules: [ + { + ruleName: "jsx-a11y/anchor-is-valid", + }, + ], + }); + }); + + test("conversion with arguments", () => { + const result = convertReactA11yAnchors({ + ruleArguments: [{ + 'ignore-case': true, + 'ignore-whitespace': 'trim' + }], + }); + + expect(result).toEqual({ + notices: [ + `jsx-a11y/anchor-is-valid does not support the 'ignore-case' option.`, + `jsx-a11y/anchor-is-valid does not support the 'ignore-whitespace' option.` + ], + plugins: ["jsx-a11y"], + rules: [ + { + ruleName: "jsx-a11y/anchor-is-valid", + }, + ], + }); + }); +});