From bcc8ea09c55ef8f7de25900d35e1d4635f03e1c1 Mon Sep 17 00:00:00 2001 From: Raquel Amorim Date: Tue, 5 Jul 2022 21:30:27 -0400 Subject: [PATCH] use all casing values on rule options --- .../tests/variable-name.test.ts | 66 ++++++++++++++++++- .../rules/ruleConverters/variable-name.ts | 4 +- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/converters/lintConfigs/rules/ruleConverters/tests/variable-name.test.ts b/src/converters/lintConfigs/rules/ruleConverters/tests/variable-name.test.ts index c4aa3dde2..85b7e5b03 100644 --- a/src/converters/lintConfigs/rules/ruleConverters/tests/variable-name.test.ts +++ b/src/converters/lintConfigs/rules/ruleConverters/tests/variable-name.test.ts @@ -104,6 +104,38 @@ describe("convertVariableName", () => { }); }); + test("conversion with allow-pascal-case argument with check-format", () => { + const result = convertVariableName({ + ruleArguments: ["allow-pascal-case", "check-format"], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/naming-convention", + rules: [ + { + selector: "variable", + format: ["camelCase", "UPPER_CASE", "PascalCase"], + leadingUnderscore: "forbid", + trailingUnderscore: "forbid", + }, + ], + }, + { + notices: [ForbiddenLeadingTrailingIdentifierMsg], + ruleName: "no-underscore-dangle", + }, + { + ruleName: "id-denylist", + }, + { + ruleName: "id-match", + }, + ], + }); + }); + test("conversion with allow-snake-case argument without check-format argument", () => { const result = convertVariableName({ ruleArguments: ["allow-snake-case"], @@ -136,6 +168,38 @@ describe("convertVariableName", () => { }); }); + test("conversion with allow-snake-case argument with check-format", () => { + const result = convertVariableName({ + ruleArguments: ["allow-snake-case", "check-format"], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/naming-convention", + rules: [ + { + selector: "variable", + format: ["camelCase", "UPPER_CASE", "snake_case"], + leadingUnderscore: "forbid", + trailingUnderscore: "forbid", + }, + ], + }, + { + notices: [ForbiddenLeadingTrailingIdentifierMsg], + ruleName: "no-underscore-dangle", + }, + { + ruleName: "id-denylist", + }, + { + ruleName: "id-match", + }, + ], + }); + }); + test("conversion with allow-leading-underscore without check-format argument", () => { const result = convertVariableName({ ruleArguments: ["allow-leading-underscore"], @@ -388,7 +452,7 @@ describe("convertVariableName", () => { rules: [ { selector: "variable", - format: ["camelCase", "UPPER_CASE"], + format: ["camelCase", "UPPER_CASE", "PascalCase", "snake_case"], leadingUnderscore: "allow", trailingUnderscore: "allow", }, diff --git a/src/converters/lintConfigs/rules/ruleConverters/variable-name.ts b/src/converters/lintConfigs/rules/ruleConverters/variable-name.ts index b0fddb792..ef9f1eae1 100644 --- a/src/converters/lintConfigs/rules/ruleConverters/variable-name.ts +++ b/src/converters/lintConfigs/rules/ruleConverters/variable-name.ts @@ -49,14 +49,14 @@ export const convertVariableName: RuleConverter = (tslintRule) => { if (!hasCheckFormat) { camelCaseRules.push({ selector: "variable", - format: ["camelCase", "UPPER_CASE"], + format: formats, leadingUnderscore: "forbid", trailingUnderscore: "forbid", }); } else { camelCaseRules.push({ selector: "variable", - format: ["camelCase", "UPPER_CASE"], + format: formats, leadingUnderscore: allowedLeadingUnderscore ? "allow" : "forbid", trailingUnderscore: allowedTrailingUnderscore ? "allow" : "forbid", });