简体   繁体   English

如何使用 tslint lint 整个文件夹

[英]How to lint entire folder using tslint

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 .当我尝试对 tslint 执行相同操作时 - 我收到错误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.在网站上的示例中 - 他们展示了如何验证单个文件,这通常不是这种情况。

Is that possible to validate my project without extra things like gulp-tslint , just from the command line?是否可以仅从命令行验证我的项目而无需额外的东西,例如gulp-tslint

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.通常,如果你只是按原样传递一个 glob,你的 shell 将扩展它并将结果文件传递给 TSLint。 So for example, in bash 4+ with the globstar option enabled, you could do the following to lint all .ts and .tsx files:例如,在启用了 globstar 选项的 bash 4+ 中,您可以执行以下操作来 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.为此,您可以在引号中传递 glob。 When in quotes, the glob will get passed as is to TSLint which will handle it with node-glob .当在引号中时,glob 将按原样传递给 TSLint,后者将使用node-glob处理它。 You could then run the following command to get the same results as above:然后,您可以运行以下命令以获得与上述相同的结果:

tslint 'src/**/*.ts?(x)'

There is now a --project option for this.现在有一个--project选项。 Example:示例:

tslint --project .

From the docs :文档

-p, --project: -p, --project:

The path or directory containing a tsconfig.json file that will be used to determine which files will be linted.包含 tsconfig.json 文件的路径或目录,该文件将用于确定哪些文件将被 linted。 This flag also enables rules that require the type checker.此标志还启用需要类型检查器的规则。

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 ,所以我有这个:

在此处输入图片说明

Note that in the json 'node_modules' and 'platforms' directories are excluded.请注意,在 json 中,'node_modules' 和 'platforms' 目录被排除在外。 This means that all files in the project are going to be mapped except 'node_modules' and 'platforms' directories.这意味着项目中的所有文件都将被映射,除了“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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM