Skip to content
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

Rule to enforce rest naming convention #59

Open
alko89 opened this issue Apr 26, 2023 · 4 comments
Open

Rule to enforce rest naming convention #59

alko89 opened this issue Apr 26, 2023 · 4 comments

Comments

@alko89
Copy link

alko89 commented Apr 26, 2023

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
Copy link
Contributor

it should be configurable to use camelCase or dash or underscore

@darraghoriordan
Copy link
Owner

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
Copy link
Contributor

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

@darraghoriordan
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants