'How can I enforce filename and folder name convention in typescript eslint?
I am using eslint for typescript convention. And I checked this rule https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md which only works for code.
I am looking for a rule which can enforce filename to be camelCase and folder name to be snake_case. How can I set this rule in typescript?
Solution 1:[1]
Eslint doesn't implement by default the file name check, see this github issue from 2015.
Some plugins do like eslint-plugin-unicorn or eslint-plugin-filenames.
Because Tslint is now deprecated, they created the project typescript-eslint, which is handling file naming casing, you could check it out :)
Solution 2:[2]
Adding a few more resources after the fact - I found for filenames, that eslint-plugin-filename-rules worked well.
For enforcing eslint on folders, eslint-plugin-folders worked for me for directories with files in it. The documentation says only .js and .jsx files but .ts and .tsx files worked for me as well.
Solution 3:[3]
The eslint plugin eslint-plugin-check-file allows you to enforce a consistent naming pattern for the filename and folder.
Apply the camelCase style to filename:
{
"rules":{
"check-file/filename-naming-convention":[
"error",
{
"*.{js,ts}":"CAMEL_CASE"
}
]
}
}
Apply the snake_case style to folder name:
{
"rules":{
"check-file/folder-naming-convention":[
"error",
{
"src/**/":"SNAKE_CASE"
}
]
}
}
Check out this link for more information about eslint-plugin-check-file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | reduckted |
| Solution 2 | papers1010 |
| Solution 3 | Duke Luo |
