ESLint を Express (Node.js) プロジェクトへインストール・初期設定

ESLint を Express (Node.js) プロジェクトへインストール、初期設定した手順をご紹介します。

JavaScript

ESLint の導入背景

「コードの品質向上」、「コードスタイルを整える」などの目的で ESLint を導入しています。

ESLint を Express (Node.js) プロジェクトへインストール ~ 初期設定まで完了した一連の流れは、以下の GitHub Pull Request を元に説明していきます。

ESLint インストール

npm install eslint --save-dev

npm install eslint –save-dev · Pull Request #9 · codenote-net/expressjs-sandbox

ESLint 初期設定

$(npm bin)/eslint --init

? How would you like to use ESLint? To check syntax, find problems, and enforce code style
? What type of modules does your project use? CommonJS (require/exports)
? Which framework does your project use? None of these
? Does your project use TypeScript? No
? Where does your code run? Node
? How would you like to define a style for your project? Use a popular style guide
? Which style guide do you want to follow? Standard: https://github.com/standard/standard
? What format do you want your config file to be in? JavaScript

$(npm bin)/eslint –init · Pull Request #9 · codenote-net/expressjs-sandbox

eslint –fix を npm-scripts へ追加

Add “lint”: “eslint .” to npm scripts · Pull Request #9 · codenote-net/expressjs-sandbox

npm run lint:fix

以上、Express (Node.js) プロジェクトへ ESLint を導入した、現場からお送りしました。

参考情報