v5.0.0
NPM distribution note: tslint@next
is deprecated now that the standard tslint
package allows a peer dependency of typescript@next
. Please switch to tslint@latest
.
🔥 Breaking changes
- Minimum version of TypeScript is now 2.1.0 (#2425)
- The severity level of each rule is now configurable and defaults to severity "error". This affects the output of formatters:
- [formatter]
msbuild
was outputting all failures as "warning". - [formatter]
pmd
was outputting all failures as priority 1. Now, it uses priority 3 for "error" (default) and priority 4 for "warning"
- [formatter]
- [formatter]
json
changed thefix
property to now contain either one replacement or an array of replacements (#2403) tslint:recommended
configuration updated withtslint:latest
rules & options (#2424)- Removed
no-unused-new
rule, with logic moved intono-unused-expression
(#2269) no-trailing-whitespace
now checks template strings by default. Use the new optionsignore-template-strings
to restore the old behavior. (#2359)- Some rules that previously worked without the type checker now require it. This includes:
no-unused-variable
no-use-before-declare
API breaks for editor integration
LintResult.failureCount
is now separated intoLintResult.errorCount
andLintResult.warningCount
class Fix
is nowtype Fix = Replacement | Replacement[]
API breaks for custom rules
-
Removed method
skip
fromRuleWalker
(#2313) -
Removed all use of the TypeScript Language Service, use only Program APIs instead (#2235)
- This breaks custom rule compilation. If your rule was not using the
ts.LanguageService
APIs, the migration is quite simple:
- public applyWithProgram(srcFile: ts.SourceFile, langSvc: ts.LanguageService): Lint.RuleFailure[] { - return this.applyWithWalker(new Walker(srcFile, this.getOptions(), langSvc.getProgram())); + public applyWithProgram(srcFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { + return this.applyWithWalker(new Walker(srcFile, this.getOptions(), program));
- N.B. If you are refactoring your custom rules, consider these performance tips for writing custom rules.
- This breaks custom rule compilation. If your rule was not using the
-
Removed
createFix
. Replacements should be passed directly into addFailure. (#2403) -
Removed deprecated
scanAllTokens
andskippableTokenAwareRuleWalker
(#2370)
🎉 Notable features & enhancements
-
[feature] The severity level of each rule is now individually configurable. Default severity can also be configured for a config file. (#629, #345)
- Valid values for
severity
:default
|error | warn | warning | none | off
- Valid values for
defaultSeverity
:error | warn | warning | none | off
- Old style:
{ "extends": "tslint:latest", "rules": { "callable-types": true, "max-line-length": [true, 140] } }
- New style (in this example,
callable-types
outputs errors andmax-line-length
outputs warnings):
{ "extends": "tslint:latest", "defaultSeverity": "error", "rules": { "callable-types": true, "max-line-length": { "options": 140, "severity": "warning" } } }
- Valid values for
-
[new-rule]
prefer-template
(#2243) -
[new-rule]
return-undefined
(#2251) -
[new-rule]
no-reference-import
(#2273) -
[new-rule]
no-unnecessary-callback-wrapper
(#2249) -
[new-fixer]
linebreak-style
(#2394) -
[new-fixer]
eofline
(#2393)
Full list of changes
- [api] Added class
OptionallyTypedRule
, which allows rule authors to write a rule that applies when typing is either enabled or disabled (#2300) - [bugfix]
prefer-function-over-method
now ignores abstract methods (#2307) - [bugfix]
arrow-parens
with optionban-single-arg-parens
now correctly handles functions with return type annotation (#2265) - [bugfix]
prefer-function-over-method
exclude overload signatures (#2315) - [bugfix]
use-isnan
now applies only to comparison operators (#2317) - [bugfix]
file-header-rule
now handles single-line comments correctly (#2320) - [bugfix]
newline-before-return
: fix handling of blank lines between comments (#2321) - [bugfix]
trailing-comma
No longer enforce trailing commas in type parameters and tuple types (#2236) - [bugfix]
align
don't fix if it would remove code (#2379) - [bugfix]
unified-signatures
now recognizes rest parameters (#2342) - [bugfix]
no-inferrable-types
don't warn for inferrable type on readonly property (#2312) - [bugfix]
trailing-comma
no longer crashes on new without parentheses (e.g.new Foo
) (#2389) - [bugfix]
semicolon
Ignore comments when checking for unnecessary semicolon (#2240) - [bugfix]
semicolon
Don't report unnecessary semicolon when followed by regex literal (#2240) - [bugfix] CLI: exit with 0 on type check errors when
--force
is specified (#2322) - [bugfix] CLI:
--test
now correctly strips single quotes from patterns on windows (#2322) - [bugfix]
prefer-const
only fix initialized variables (#2219) - [bugfix]
prefer-const
correctly handle variables shadowed by parameters and catched exceptions (#2219) - [bugfix]
prefer-const
don't warn if one variable in a for loop initializer can not be const (#2219) - [bugfix]
prefer-const
handle more cases in destructuring (#2219) - [bugfix]
no-unused-expression
allow comma separated assignments (#2269) - [chore] removed update-notifier dependency (#2262)
- [development] allow rule tests to specify version requirement for typescript (#2323)
- [enhancement]
ignore-properties
option ofno-inferrable-types
now also ignores parameter properties (#2312) - [enhancement]
unified-signatures
now displays line number of the overload to unify if there are more than 2 overloads (#2270) - [enhancement]
trailing-comma
New checks for CallSignature and NamedExports (#2236) - [enhancement]
semicolon
New check for export statements, function overloads and shorthand module declaration (#2240) - [enhancement]
semicolon
Report unnecessary semicolons in classes and in statement position (for option "always" too) (#2240) - [enhancement]
semicolon
check for semicolon after method overload (#2240) - [enhancement]
array-type
now considerobject
,undefined
andnever
as simple types, allowingobject
,undefined[]
andnever[]
(#1843)(#2353) - [enhancement]
align
check statement alignment for all blocks (#2379) - [enhancement]
align
check parameter alignment for all signatures (#2379) - [enhancement]
--test
can handle multiple paths at once (#2322) - [enhancement]
only-arrow-functions
allow functions that usethis
in the body (#2229) - [enhancement] CLI: print error when
--type-check
is used without--project
(#2322) - [enhancement] CLI: don't print stack trace on type check error (#2322)
- [enhancement] CLI: added
-p
as shorthand for--project
to be consistent withtsc
(#2322) - [enhancement]
prefer-const
show warnings forvar
(#2219) - [enhancement]
quotemark
fixer unescapes original quotemark (e.g.'\''
->"'"
) (#2359) - [enhancement]
no-unused-expression
allow indirect eval(0, eval)("");
(#2269) - [enhancement]
no-unused-expression
checking for unused new can now use optionallow-fast-null-checks
(#2269) - [enhancement]
no-unused-expression
find unused comma separated expressions in all locations of the code (#2269) - [enhancement]
no-unused-expression
find unused expressions inside void expression (#2269) - [new-config-option] Adds
defaultSeverity
with optionserror
,warning
, andoff
. (#2416) - [new-formatter] TAP formatter (#2325)
- [new-rule-option]
no-unused-expression
adds optionallow-tagged-template
to allow tagged templates for side effects (#2269) - [new-rule-option]
no-unused-expression
adds optionallow-new
to allownew
without using the new object (#2269) - [new-rule-option]
member-access
addsno-public
option (#2247) - [new-rule-option]
curly
added optionignore-same-line
(#2334) - [new-rule-option]
{destructuring: "all"}
to only warn if all variables in a destructuring can be const (#2219) - [new-rule-option] added
ignore-template-strings
tono-trailing-whitespace
(#2359) - [rule-update]
array-type
now considerundefined
andnever
as simple types, allowingundefined[]
andnever[]
(#1843)
Thanks to our contributors!
- Brian Olore
- Andy Hanson
- @andy-ms
- Chris Barr
- Klaus Meinhardt
- @bumbleblym
- Josh Goldberg
- James Clark
- @vilic
- Aleksandr Filatov
- Matt Banz
- Karol Janyst
- Mike Deverell
- Alexander James Phillips
- Irfan Hudda