TSLint 4.0 Released
TSLint 4.0 has been released! With this release comes a few exciting changes. Some of the highlights:
- Fixers. Do you dread turning on a new rule because of all of the new errors? For some of the most common issues, we’ll fix them for you. To use this feature, run
tslint
with the--fix
option. Rules that support the--fix
feature: -
Linting
.js
files. A much-requested feature from our community. Simplify your toolset by running the same rules you know and love on your .js and .jsx files. Just add ajsRules
section to yourtslint.json
file, and TSLint will lint your JavaScript files. - TypeScript 2.0+ required. This lets us deprecate/remove rules that are checked by the compiler. Problematic code that once violated these rules now cause compilation errors in
tsc
:- no-duplicate-key
- no-unreachable
- no-unused-variable
-
Node.js API Change. Moved and renamed some things to make more sense. Get it all when you use
import * as TSLint from "tslint"
. - Recommended Rules Updated
- Other rules you might find handy:
Create your own fixer
To create your own fixer, instantiate a Fix
object and pass it in as an argument to addFailure
.
This snippet updates the sample custom rule by adding a fixer which replaces the offending import statement with an empty string:
// create a fixer for this failure
const replacement = new Lint.Replacement(node.getStart(), node.getWidth(), "");
const fix = new Lint.Fix("no-imports", [replacement]);
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING, fix));