Since TSLint is deprecated, I migrated my TypeScript projects to ESLint.
Prerequisites
I expect your project to contain the files:
- package.json
- tsconfig.json
- tslint.json
Uninstall
First, uninstall tslint from package.json
:
$ npm remove tslint
Verify typescript is still present:
$ npm list typescript
Install
Then install eslint and the TypeScript eslint-plugin and parser:
$ npm install eslint @typescript-eslint/{eslint-plugin,parser} # --save-dev
Config
Initialize .eslintrc
:
$ npx eslint --init
Your base .eslintrc
should look something like this:
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"]
}
Move your tslint.json
rules to .eslintrc
.
Add env
to your .eslintrc
(if applicable):
{
"env": {
"browser": true,
"es6": true,
"jest": true,
"node": true
}
}
Script
Update your lint
script in package.json
:
{
"scripts": {
- "lint": "tslint -c tslint.json 'src/**/*.ts'"
+ "lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
}
}
Test that it still works:
$ npm run lint
Misc
Migrate any TSLint configs/plugins to ESLint (if applicable).
The following example is for Prettier:
$ npm rm tslint-config-prettier
$ npm i eslint-plugin-prettier # -D
Don’t forget to update .eslintrc
:
{
// ...
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": "error"
}
}
Here’s a pull request that I opened for phonetic-alphabet-converter.
Lastly, you can use tslint-to-eslint-config to migrate from TSLint to ESLint:
$ npx tslint-to-eslint-config