Reputation: 1037
I'm trying to migrate an existing JS repo to TypeScript. The problem is that projects' API responses are objects with identifiers in snake_case
and this conflicts with default eslint camelCase
rule.
Before the migration we were handling snake_case
object identifiers with this rule in .eslintrc.js
:
'camelcase': ['error', {properties: 'never'}],
And could have objects like this in our code:
const { variable_name } = await axios(url)
But after moving to TypeScript, these identifiers are also going show up in interfaces.
So basically I want to be able to have:
interface Model<T extends string> {
type: T;
id: number;
variable_name: string;
language_code: string;
}
But Typescript now throws:
Identifier 'variable_name' is not in camel case.
What rule should I have in my .eslintrc.js
file to justify this? Please note that my identifiers are not limited to those two listed above and there are dozens of others which I removed for simplicity.
Upvotes: 4
Views: 5556
Reputation: 20341
Keep in mind that JavaScript (for which ESLint is developed) doesn't know of types (eg. interfaces).
So I think this is what is happening while linting the file:
camelCase
rule of ESLint applies to objects and their properties.I think what you need to do is:
camelCase
rule (at least for your TypeScript files).This should work:
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"]
},
{
"selector": "typeProperty",
"format": null
}
]
Upvotes: 1