Choosing a Linter
Not unlike stellar collisions, TSLint
will inevitably be merging with ESLint
.
Read the announcements here and here which cover why this is a good idea.
TL;DR
- Use
ESLint
for your Typescript projects - Start migrating from
TSLint
toESLint
based configs
Configure ESLint for Typescript
Install the core packages.
yarn i -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
Then use the eslint --init
tool to generate a config that suits your needs.
Migrating TSLint based projects
We basially have two options:
a) Use the newer ESLint equlivant package; or
b) Codemod the rules. This has been solved by tslint-to-eslint-config project.
Evaluate the following. The following command will look at your existing tslint.json
and generate the corresponding ESLint rules.
npx tslint-to-eslint-config --config .eslintrc.json
When there are no clear matches there is a nifty summary. Pretty cool. Use at your own peril as the rules collection becomes quite πish.
β¨ 115 rules replaced with their ESLint equivalents. β¨
π’ 8 ESLint rules behave differently from their TSLint counterparts: π’
* no-invalid-this:
- Functions in methods will no longer be ignored.
* no-unused-expressions:
- The TSLint optional config "allow-new" is the default ESLint behavior and will no longer be ignored.
* one-var:
- Variables declared in for loops will no longer be checked.
* @typescript-eslint/quotes:
- Option "jsx-single" is not supported by ESLint.
* eqeqeq:
- Option "smart" allows for comparing two literal values, evaluating the value of typeof and null comparisons.
* camelcase:
- Leading undescores in variable names will now be ignored.
- ESLint's camel-case rule does not allow pascal or snake case variable names. Those cases are reserved for class names and static methods.
* no-underscore-dangle:
- Leading and trailing underscores (_) on identifiers will now be ignored.
* @typescript-eslint/space-within-parens:
- The number of spaces will be ignored
π 1 error thrown. π
Check ./tslint-to-eslint-config.log for details.
οΈπ 64 rules do not yet have ESLint equivalents (see generated log file); defaulting to eslint-plugin-tslint for these rules. π
Choosing a styleguide
Explore some core
rules.
Explore some company based
rules.
Explore some opinioniated
rules.
But most importantly, BE CONSISTENT across your team.