Make TSLint follow my rules in JS files
Asked Answered
D

1

5

I'm using TSLint within Visual Studio Code (via the TSLint extension), and it's great for .ts files. It also runs on .js files, which is good, but it does not use the same rules, which is bad (for me). How can I make it use the same rules?

My tslint.json looks like this:

{
  "extends": "tslint:latest",
  "rules": {
    "indent": [true, "tabs"],
    // a bunch of others
  }
}

And for example, I'm getting this warning in a .js file:

[tslint] space indentation expected (indent)

(It wants me to use space indentation, when my rules are set up for "tabs".)

Dovelike answered 30/12, 2016 at 14:14 Comment(0)
A
8

You can specify what rules you want to run on JS files via a jsRules property in your tslint.json file. For example:

{
  "extends": "tslint:latest",
  "rules": {
    "indent": [true, "tabs"],
    // a bunch of others
  },
  "jsRules": {
    "indent": [true, "tabs"],
    // a bunch more rules
  }
}

If you're extending tslint:latest, these are the default rules as of the time of this writing and you'll have disable or overwrite the rules you don't want.

Actionable answered 2/1, 2017 at 2:30 Comment(1)
Ah OK. Thank you. Somehow I missed that it uses completely separate rules for javascript!Dovelike

© 2022 - 2024 — McMap. All rights reserved.