From 959ba6980cedcaa0de230f6306d0fac6b26d3d5f Mon Sep 17 00:00:00 2001 From: Krzysztof Brilla Date: Sat, 7 Nov 2020 18:34:52 +0100 Subject: [PATCH] Adding the rule, mapping it and writing the tests --- .../lintConfigs/rules/ruleConverters.ts | 2 + .../eslint-plugin-rxjs/no-sharereplay.ts | 15 +++++++ .../tests/no-sharereplay.test.ts | 42 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/no-sharereplay.ts create mode 100644 src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/tests/no-sharereplay.test.ts diff --git a/src/converters/lintConfigs/rules/ruleConverters.ts b/src/converters/lintConfigs/rules/ruleConverters.ts index 40c1f9c32..4359f9aed 100644 --- a/src/converters/lintConfigs/rules/ruleConverters.ts +++ b/src/converters/lintConfigs/rules/ruleConverters.ts @@ -183,6 +183,7 @@ import { convertJsxWrapMultiline } from "./ruleConverters/eslint-plugin-react/js //eslint-plugin-rxjs converters import { convertNoAsyncSubscribe } from "./ruleConverters/eslint-plugin-rxjs/no-async-subscribe"; +import { convertNoShareReplay } from "./ruleConverters/eslint-plugin-rxjs/no-sharereplay"; /** * Keys TSLint rule names to their ESLint rule converters. @@ -368,6 +369,7 @@ export const ruleConverters = new Map([ ["use-pipe-transform-interface", convertUsePipeTransformInterface], ["variable-name", convertVariableName], ["rxjs-no-async-subscribe", convertNoAsyncSubscribe], + ["rxjs-no-sharereplay", convertNoShareReplay], // 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... diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/no-sharereplay.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/no-sharereplay.ts new file mode 100644 index 000000000..dc7649029 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/no-sharereplay.ts @@ -0,0 +1,15 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoShareReplay: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments, + }), + ruleName: "rxjs/no-sharereplay", + }, + ], + plugins: ["eslint-plugin-rxjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/tests/no-sharereplay.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/tests/no-sharereplay.test.ts new file mode 100644 index 000000000..8da4b0556 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-rxjs/tests/no-sharereplay.test.ts @@ -0,0 +1,42 @@ +import { convertNoShareReplay } from "../no-sharereplay"; + +describe(convertNoShareReplay, () => { + test("conversion without arguments", () => { + const result = convertNoShareReplay({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "rxjs/no-sharereplay", + }, + ], + plugins: ["eslint-plugin-rxjs"], + }); + }); + + test("conversion without arguments", () => { + const result = convertNoShareReplay({ + ruleArguments: [ + { + allowConfig: true, + }, + ], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "rxjs/no-sharereplay", + ruleArguments: [ + { + allowConfig: true, + }, + ], + }, + ], + plugins: ["eslint-plugin-rxjs"], + }); + }); +});