Skip to content

Commit d8848d3

Browse files
author
roman.vasilev
committed
fix(use-validation-pipe): fixed for nest 5.X
1 parent 545d41f commit d8848d3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/use-validation-pipe/use-validation-pipe.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ ruleTester.run('use-validation-pipe', useValidationPipe, {
2323
{ code: `@UsePipes(new ValidationPipe()) class { @Post() async create(@Body() createCatDto: CreateCatDto) { } }` },
2424
{ code: `class { @Post() async create(@Body() createCatDto: any) { } }` },
2525
{ code: `class { @Post() async create(@Body() createCatDto) { } }` },
26+
{ code: `@UsePipes(ValidationPipe) class { @Post() async create(@Body() createCatDto: CreateCatDto) { } }` },
2627
],
2728
});

src/use-validation-pipe/use-validation-pipe.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const useValidationPipe = {
99
return {
1010
ClassDeclaration: (node: ClassDeclaration) => {
1111
const classUsePipes = getDecoratorByName(node, 'UsePipes');
12-
validationPipeInClass = hasNewExprValidationPipe(classUsePipes);
12+
validationPipeInClass = hasExprValidationPipe(classUsePipes);
1313
},
1414
'ClassDeclaration:exit': () => {
1515
validationPipeInClass = false;
@@ -23,11 +23,11 @@ export const useValidationPipe = {
2323
return;
2424
}
2525
const body = getDecoratorByName(param, 'Body');
26-
if (hasNewExprValidationPipe(body)) {
26+
if (hasExprValidationPipe(body)) {
2727
return;
2828
}
2929
const usePipes = getDecoratorByName(node, 'UsePipes');
30-
if (hasNewExprValidationPipe(usePipes)) {
30+
if (hasExprValidationPipe(usePipes)) {
3131
return;
3232
}
3333
const { typeAnnotation } = param as any;
@@ -39,10 +39,13 @@ export const useValidationPipe = {
3939
}
4040
};
4141

42-
function hasNewExprValidationPipe(node) {
42+
function hasExprValidationPipe(node) {
4343
if (!node) {
4444
return false;
4545
}
4646
return (node.expression as CallExpression).arguments
47-
.some(argument => argument.type === 'NewExpression' && argument.callee.type === 'Identifier' && argument.callee.name === 'ValidationPipe');
47+
.some(argument => {
48+
return (argument.type === 'NewExpression' && argument.callee.type === 'Identifier' && argument.callee.name === 'ValidationPipe')
49+
|| (argument.type === 'Identifier' && argument.name === 'ValidationPipe');
50+
});
4851
}

0 commit comments

Comments
 (0)