I use the @typescript-eslint plugin to add rules to my TypeScript code using eslint.
One of the rules that I have enabled is camelcase:
"@typescript-eslint/camelcase": ["error", { "properties": "always" }]
It allows me to normalize my variable and interfaces names.
Problem is that the standard JSON format uses the snake_case convention to name their identifier. So all my API requests response are using snake_case.
In this case, I have to declare interfaces using snake_case like that:
interface UserResponse {
id: number
dark_mode: boolean
status_code: string
}
So my question is: Is there a way to disable this rule for identifier defined in an interface ending width Response? So there are no lint errors in my UserResponse interface.
@typescript-eslint provide an interesting parameter allow that disable the rule for specific names matching a regex:
/* @typescript-eslint/camelcase: ["error", {allow: ["Response$"]}] */
interface Foo_Bar_Response {
...
}
Here the linter will not trigger the snake_case format from Foo_Bar_Response because it's ending with the word Response.
But here it only works for the name of the interface itself and not for the names of these child identifiers.
Any idea how we can make this work?