Skip to content

Commit 8a6df93

Browse files
fix: param rule should support single quote
1 parent 672e9eb commit 8a6df93

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/rules/paramDecoratorNameMatchesRouteParam/paramDecoratorNameMatchesRouteParam.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,52 @@ ruleTester.run("param-decorator-name-matches-route-param", rule, {
5050
}
5151
`,
5252
},
53+
{
54+
//mixed quotes shouldn't matter
55+
code: `
56+
@ApiTags("Custom Bot")
57+
@ApiBearerAuth()
58+
@UseGuards(DefaultAuthGuard)
59+
@Controller("custom-bot")
60+
export class CustomBotController {
61+
constructor(
62+
) {}
63+
64+
@Get(':uuid')
65+
@ApiOkResponse({ type: CustomBot })
66+
findOne(
67+
@Param("uuid") uuid: string,
68+
@Request() request: RequestWithUser
69+
): Promise<CustomBot> {
70+
return this.customBotService.findOne(uuid, request.user.uuid);
71+
}
72+
73+
}
74+
`,
75+
},
76+
{
77+
// single quotes shouldn't matter
78+
code: `
79+
@ApiTags("Custom Bot")
80+
@ApiBearerAuth()
81+
@UseGuards(DefaultAuthGuard)
82+
@Controller("custom-bot")
83+
export class CustomBotController {
84+
constructor(
85+
) {}
86+
87+
@Get(':uuid')
88+
@ApiOkResponse({ type: CustomBot })
89+
findOne(
90+
@Param('uuid') uuid: string,
91+
@Request() request: RequestWithUser
92+
): Promise<CustomBot> {
93+
return this.customBotService.findOne(uuid, request.user.uuid);
94+
}
95+
96+
}
97+
`,
98+
},
5399
{
54100
code: `
55101
@ApiTags("Custom Bot")

src/rules/paramDecoratorNameMatchesRouteParam/paramDecoratorNameMatchesRouteParam.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export const isParameterNameIncludedInAPathPart = (
5050
): boolean => {
5151
return pathPartsToCheck.some((pathPart) => {
5252
return (
53+
// note to reader: this might be better as a regex. feel free to open a pr!
5354
pathPart === `":${paramName}"` ||
55+
pathPart === `':${paramName}'` ||
5456
pathPart.includes(`/:${paramName}/`) ||
5557
pathPart.includes(`/:${paramName}"`) ||
5658
pathPart.includes(`":${paramName}/`)

0 commit comments

Comments
 (0)