typescript 如何使用 tslint lint 整个文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36447910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to lint entire folder using tslint
提问by ValeriiVasin
Is that possible to lint entire folder using tslint?
是否可以使用 tslint 对整个文件夹进行 lint?
Using eslint it is possible to do eslint ./src
to validate whole folder.
使用 eslint 可以eslint ./src
验证整个文件夹。
When i try to do the same for tslint - i am getting an error Error: EISDIR: illegal operation on a directory
. In their examples on the site - they show how to validate single file, which is not the case usually.
当我尝试对 tslint 执行相同操作时 - 我收到错误消息Error: EISDIR: illegal operation on a directory
。在网站上的示例中 - 他们展示了如何验证单个文件,这通常不是这种情况。
Is that possible to validate my project without extra things like gulp-tslint
, just from the command line?
是否可以gulp-tslint
仅从命令行验证我的项目而不需要额外的东西?
回答by JKillian
You can use a glob to lint multiple files.
您可以使用 glob 来 lint 多个文件。
Normally, if you just pass a glob as is, your shell will expand it and pass the resulting files to TSLint. So for example, in bash 4+ with the globstar option enabled, you could do the following to lint all .ts
and .tsx
files:
通常,如果你只是按原样传递一个 glob,你的 shell 将扩展它并将结果文件传递给 TSLint。因此,例如,在bash 4+与globstar选项启用,你可以做以下lint的所有.ts
和.tsx
文件:
tslint src/**/*.ts{,x}
You're probably better off though using a command that will work consistently across platforms and shells though. For this, you can pass the glob in quotes. When in quotes, the glob will get passed as is to TSLint which will handle it with node-glob. You could then run the following command to get the same results as above:
尽管使用可以跨平台和外壳一致工作的命令,但您可能会更好。为此,您可以在引号中传递 glob。当在引号中时,glob 将按原样传递给 TSLint,后者将使用node-glob处理它。然后,您可以运行以下命令以获得与上述相同的结果:
tslint 'src/**/*.ts?(x)'
回答by Matt Browne
There is now a --project
option for this. Example:
现在有一个--project
选项。例子:
tslint --project .
From the docs:
从文档:
-p, --project:
The path or directory containing a tsconfig.json file that will be used to determine which files will be linted. This flag also enables rules that require the type checker.
-p, --project:
包含 tsconfig.json 文件的路径或目录,该文件将用于确定哪些文件将被 linted。此标志还启用需要类型检查器的规则。
回答by Daniel Eduardo Delgado Diaz
If your project has a tsconfig.json you can aproach --project advange.
如果您的项目有 tsconfig.json,您可以使用 --project advange。
In my case I have a nativescript project wich includes a tsconfig.json
at project root, so I have this:
就我而言,我有一个 nativescript 项目,其中包含一个tsconfig.json
at 项目根目录,所以我有这个:
Note that in the json 'node_modules' and 'platforms' directories are excluded. This means that all files in the project are going to be mapped except 'node_modules' and 'platforms' directories.
请注意,在 json 中,'node_modules' 和 'platforms' 目录被排除在外。这意味着项目中的所有文件都将被映射,除了“node_modules”和“platforms”目录。
I have added this scripts at my package.json, 'tslint' to log the errors and 'tslint-fix' to fix the errors.
我在我的 package.json 中添加了这个脚本,'tslint' 来记录错误,'tslint-fix' 来修复错误。
"scripts": {
"tslint": "tslint -p tsconfig.json",
"tslint-fix": "tslint --fix -p tsconfig.json"
}