This post goes over how to migrate a project from TypeScript to ESLint since TSLint is deprecated.
Prerequisites
The project should 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 --save-dev eslint @typescript-eslint/{eslint-plugin,parser}
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 -D eslint-plugin-prettier
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