0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Prettier(フォーマッタ) => ESLint(静的解析)の設定

Last updated at Posted at 2020-11-23

これはなに

タイトルの内容についての2020年11月23日時点でのメモ。

やること

プロジェクトのディレクトリにてCLIで

$ npm init -y //package.json
$ npm install -D prettier eslint eslint-config-prettier

次に、./node_modules/.binのPATHを通す

PATHを通したら、

$ code -r .eslintrc.json .prettierrc

.eslintrc.jsonは以下のようにする(ミニマルな形)

.eslintrc.json
{
  "env": {
    "es6": true
  },
  "extends": ["prettier"]
}

注意として、extendsの配列に"eslint:recommended"を入れると失敗しました

.prettierrcは以下のようにする(わたしのばあい)

ESLintはフォーマッタとして使用しないので、このファイルに細かいルールを書いていく

ちなみにtabwidthはデフォルトで2なので書かなくてもいい

.prettierrc
{
    "tabWidth": 2,
    "singleQuote": true
}

最後に、settings.jsonに以下を追加

settings.json
{
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

ここまでやって、

VSCodeの右下にあるESLintPrettierにチェックがついて、ファイルを保存したときに両方行われていればOK.

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?