Migrating from TSLint to ESLint in a TypeScript project
Showcase the steps and code modifications needed to migrate a TypeScript project from using TSLint to using ESLint.
npm uninstall tslint typescript-tslint-plugin
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
Uninstall TSLint and TSLint TypeScript plugin, then install ESLint with its TypeScript parser and plugin.
npm install --save-dev eslint-config-prettier eslint-plugin-prettier
Optional: Install ESLint integrations for Prettier if prettier formatting is used.
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
// Specify ESLint rules here
}
}
Create a new `.eslintrc.json` configuration file for ESLint with recommended settings for TypeScript.
npx tslint-to-eslint-config
Optional: Run the tslint-to-eslint-config utility to help migrate TSLint rules to ESLint.
// package.json
{
"scripts": {
// Update linting script to use eslint instead of tslint
"lint": "eslint . --ext .ts,.tsx"
}
}
Update the `lint` script in `package.json` to use ESLint instead of TSLint.
// Before: Using TSLint
/* tslint:disable */
// Your TypeScript code here
/* tslint:enable */
// After: Migrated to ESLint
/* eslint-disable */
// Your TypeScript code here
/* eslint-enable */
If you have any code-level TSLint disable/enable comments, replace them with ESLint equivalents.