darraghoriordan / eslint-plugin-nestjs-typed

Some eslint rules for working with NestJs projects
http://www.darraghoriordan.com
171 stars 34 forks source link

Rule to enforce rest naming convention #59

Open alko89 opened 1 year ago

alko89 commented 1 year ago

Would it be possible to expand the module to use it to enforce rest naming conventions for endpoints?

https://restfulapi.net/resource-naming/

Essentially to check the Controller, Get, Post, Put, Delete.. decorators if a proper naming was used for the endpoint:

This PASSES

@Controller('tests')
class TestClass {
    @Get()
    public getAll() {
    }
}

This FAILS, because the resource is not plural

@Controller('test')
class TestClass {
    @Get()
    public getAll() {
    }
}

This PASSES

@Controller('tests')
class TestClass {
    @Get('some-param/:someParam')
    public getByParam(@Param('someParam') param) {
    }
}

This FAILS, because camel case was used to name the resource

@Controller('tests')
class TestClass {
    @Get('getByParam/:someParam')
    public getByParam(@Param('someParam') param) {
    }
}
spotlesscoder commented 1 year ago

it should be configurable to use camelCase or dash or underscore

darraghoriordan commented 1 year ago

This is a fairly complex rule that I wouldn't really enforce in my projects. Unlikely to implement this myself.

Happy to accept PR for it though.

spotlesscoder commented 1 year ago

Can you give us a hint what the necessary steps would be to implement this?

darraghoriordan commented 1 year ago

There is a naming convention rule in the main eslint ruleset you could use for inspiration.

There are a couple of examples in this project of how to detect a nestjs controller and the nestjs api method decorators.

you would have to combine these in some way