ESLint + TypeScript
前提
- 2019年TSLintはdeprecatedになったので、2020年以降はESLintを代わりに使う
インストール
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
設定
ESLintの設定
📄.eslintrc.js:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
};
Lintスクリプトの設定
📄package.json:
{
"scripts": {
...
"lint": "eslint . --ext .ts",
"lint-and-fix": "eslint . --ext .ts --fix"
}
}
Lintの実行
npm run lint
npm run lint-fix
参考