Skip to content

fix(rule/variable-name): Use ruleArguments property #1565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -49,7 +49,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE", "PascalCase"],
Expand Down Expand Up @@ -145,7 +145,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -177,7 +177,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE", "snake_case"],
Expand Down Expand Up @@ -209,7 +209,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -241,7 +241,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -273,7 +273,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand All @@ -296,6 +296,49 @@ describe("convertVariableName", () => {
});
});

test("conversion with ban-keywords argument without check-format argument", () => {
const result = convertVariableName({
ruleArguments: ["ban-keywords"],
});

expect(result).toEqual({
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
leadingUnderscore: "forbid",
trailingUnderscore: "forbid",
},
],
},
{
ruleName: "no-underscore-dangle",
notices: [ForbiddenLeadingTrailingIdentifierMsg],
},
{
ruleName: "id-denylist",
ruleArguments: [
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined",
],
},
{
ruleName: "id-match",
},
],
});
});

test("conversion with require-const-for-all-caps argument and check-format argument", () => {
const result = convertVariableName({
ruleArguments: ["check-format", "require-const-for-all-caps"],
Expand All @@ -306,7 +349,7 @@ describe("convertVariableName", () => {
{
notices: [ConstRequiredForAllCapsMsg],
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -338,7 +381,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -371,7 +414,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -408,7 +451,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
Expand Down Expand Up @@ -449,7 +492,7 @@ describe("convertVariableName", () => {
rules: [
{
ruleName: "@typescript-eslint/naming-convention",
rules: [
ruleArguments: [
{
selector: "variable",
format: ["camelCase", "UPPER_CASE", "PascalCase", "snake_case"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const convertVariableName: RuleConverter = (tslintRule) => {
const camelCaseRules: Record<string, unknown>[] = [];
const camelCaseOptionNotices: string[] = [];
const formats = ["camelCase", "UPPER_CASE"];

if (hasCheckFormat && allowPascalCase) {
formats.push("PascalCase");
}
Expand Down Expand Up @@ -68,7 +67,7 @@ export const convertVariableName: RuleConverter = (tslintRule) => {

return {
...(camelCaseOptionNotices.length !== 0 && { notices: camelCaseOptionNotices }),
...(camelCaseRules.length !== 0 && { rules: camelCaseRules }),
...(camelCaseRules.length !== 0 && { ruleArguments: camelCaseRules }),
ruleName: "@typescript-eslint/naming-convention",
};
};
Expand Down