简体   繁体   English

TSLint:如何忽略 JS 文件?

[英]TSLint: how to ignore JS files?

How can I tell tslint to ignore JS files?如何告诉 tslint 忽略 JS 文件?

In tsconfig.json I have "allowJs": true because I do want it to compile JS files:tsconfig.json我有"allowJs": true因为我确实希望它编译 JS 文件:

{
  "compilerOptions": {
    // ...
    "allowJs": true,
    // ...
  },
  // ...
}

However I do not want it to lint them.但是我不希望它掉毛它们。

With this setup, it complains that "No valid rules have been specified for JavaScript files" .使用此设置,它抱怨“没有为 JavaScript 文件指定有效规则” This is because it tries to lint JS files, but has not been given any rules for doing so.这是因为它试图对 JS 文件进行 lint,但没有给出任何这样做的规则。

It has been suggested in another Stack Overflow thread to add the following, so that it has some rules to go by (a bit of a hack really):在另一个堆栈溢出线程中建议添加以下内容,以便它对 go 有一些规则(真的有点黑客):

"jsRules": {
    "no-empty": true
}

But what if I don't want it to check for this rule either?但是,如果我也不希望它检查此规则怎么办? I just don't want it to lint JS files at all.我只是不希望它对 JS 文件进行 lint。

I've found out how to do this.我已经找到了如何做到这一点。

To ignore JS files, add the following to your tslint.json (you can, of course, ignore any file type in a similar fashion)要忽略 JS 文件,请将以下内容添加到您的tslint.json (当然,您可以以类似的方式忽略任何文件类型)

"linterOptions": {
    "exclude": [
        "**/*.js"
    ]
}

Note that linterOptions.exclude was introduced in tslint 5.8, so you must have this version or later to use this feature.请注意,在linterOptions.exclude 5.8 中引入了 linterOptions.exclude,因此您必须拥有此版本或更高版本才能使用此功能。

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

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