Can I control which rules 'tslint --fix' auto fixes?
Asked Answered
M

2

7

Is it possible to control which rules are auto-fixed when running tslint --fix? Ideally, I only want to autofix the whitespace and quotation rules, and I'll evaluate the rest manually. I can't seem to find anything in the documentation telling me which rules auto fix, or how to control which rules to apply though, and I'm a bit apprehensive about blindly fixing everything.

I'm currently using the tslint file that's autogenerated by Angular CLI.

Miyasawa answered 7/8, 2018 at 15:48 Comment(2)
I think you are right to be afraid, some fixes can indeed break your existing code (for instance, the rules concerning the 'don't use null use undefined instead' and likewise with == vs ===.Siegel
To evaluate, I rely on my source-control to see the changes, for the rules, use a tslint.jsonSiegel
N
9

You could always run tslint --fix using a separate tslint.json file that contains only the rules you want to fix. I believe the rules that auto-fix are the ones marked "Has Fixer" in the list.

Norford answered 7/8, 2018 at 15:52 Comment(1)
I added to my NPM - "lint:one-rule-fix": "tslint -c tslint-empty.json src/**/*.ts --fix", and I specify one rule at a time there; (note - for eslint there was github.com/IanVS/eslint-nibble , I wonder if something like this exists for tslint)Sentience
S
0

As already said, you can use you own tslint.json, with your custom rules.

For the "evaluation" part of your problem, I suggest simply using your source-control. For instance, it's easy with Git to validate / discard changes by files, or even by lines / chunk.

Siegel answered 7/8, 2018 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.