简体   繁体   中英

TSLint: how to ignore JS files?

How can I tell tslint to ignore JS files?

In tsconfig.json I have "allowJs": true because I do want it to compile JS files:

{
  "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" . This is because it tries to lint JS files, but has not been given any rules for doing so.

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):

"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.

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)

"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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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