如何在打字稿 eslint 中强制执行文件名和文件夹名称约定?

Zha*_* Yi 5 typescript eslint

eslint用于typescript约定。我检查了这个https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md只适用于代码的规则。

我正在寻找一个规则,它可以将camelCase文件名强制为snake_case. 如何在打字稿中设置此规则?

Gré*_*EUT 14

Eslint 默认情况下不实现文件名检查,请参阅2015 年的 github 问题

有些插件确实像eslint-plugin-unicorneslint-plugin-filenames


由于 Tslint 现已弃用,因此他们创建了项目typescript-eslint,该项目负责处理文件命名大小写,您可以查看一下:)

  • @Orelsanpls typescript-eslint 的链接在这里不是很有帮助。该规则仅适用于文件内的标识符(函数、类、变量……),而不适用于文件本身。github 问题的链接非常清楚地表明检查文件名超出了范围。 (11认同)

小智 11

eslint 插件eslint-plugin-check-file允许您对文件名和文件夹强制执行一致的命名模式。

camelCase样式应用于文件名:

{
   "rules":{
      "check-file/filename-naming-convention":[
         "error",
         {
            "*.{js,ts}":"CAMEL_CASE"
         }
      ]
   }
}
Run Code Online (Sandbox Code Playgroud)

snake_case样式应用到文件夹名称:

{
   "rules":{
      "check-file/folder-naming-convention":[
         "error",
         {
            "src/**/":"SNAKE_CASE"
         }
      ]
   }
}
Run Code Online (Sandbox Code Playgroud)

查看此链接以获取有关 的更多信息eslint-plugin-check-file