Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make TSLint follow my rules in JS files

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

like image 337
Eric Simonton Avatar asked Dec 30 '16 14:12

Eric Simonton


People also ask

Does Tslint work with JavaScript?

(TSLint for types, JSHint/ESLint for the rest) Do not allow to use TypeScript keywords in JavaScript.

What is Tslint rules?

no-empty-interface - Forbids empty interfaces. no-for-in - Ban the usage of for…in statements. no-import-side-effect - Avoid import statements with side-effect. TS Only Has Fixer. no-inferrable-types - Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.

Which command is correct regarding to Tslint?

tslint accepts the following command-line options: -c, --config: The location of the configuration file that tslint will use to determine which rules are activated and what options to provide to the rules. If no option is specified, the config file named tslint. json is used, so long as it exists in the path.


1 Answers

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.

like image 55
JKillian Avatar answered Nov 15 '22 08:11

JKillian