Skip to content

Commit

Permalink
use all casing values on rule options (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorimr authored Jul 22, 2022
1 parent bc192ca commit 7978dc4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -388,7 +452,7 @@ describe("convertVariableName", () => {
rules: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
format: ["camelCase", "UPPER_CASE", "PascalCase", "snake_case"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down

0 comments on commit 7978dc4

Please sign in to comment.