Use pipe ValidationPipe for data validation (use-validation-pipe)

January 4, 2018 ยท View on GitHub

Pipes can overtake the validation responsibility, since it's possible to throw an exception when the data isn't correct.

Rule Details

The following patterns are considered warnings (fail):

class CatController {
    @Post()
    async create(@Body() createCatDto: CreateCatDto) { }
}

The following patterns are not warnings (pass):

@UsePipes(new ValidationPipe())
class CatController {
    @Post()
    async create(@Body() createCatDto: CreateCatDto) { }
}
class CatController {
    @Post()
    async create(@Body(new ValidationPipe()) createCatDto: CreateCatDto) { }
}
class { 
    @Post() 
    async create(@Body() createCatDto: any) {  } 
}

Further Reading

Pipes