LoginSignup
2
2

More than 3 years have passed since last update.

ゼロからのPrettier

Last updated at Posted at 2019-11-27

Prettierとは

コードフォーマッターのこと
コマンドを叩くとコードを綺麗にしてくれるもの。

installation

package.jsonを生成し、prettierをインストールする。

terminal
$ npm init -y 
$ npm install prettier

scriptsに fmtコマンドを記述する。

package.json
{
  "name": "Prettier",
  "scripts": {
    "fmt": "prettier --write src/**.js"
  },
  "dependencies": {
    "prettier": "^1.19.1"
  }
}

綺麗にしたいJSファイルを用意する。

src/app.js
function hello(text){
  console.log(text + "!")} hello("Hello")

実際に綺麗にする

terminal
$ npm run fmt
src/app.js
function hello(text) {
  console.log(text + "!");
}
hello("Hello");

こんな感じに綺麗にしてくれます。

おわり

今回使用したコードはこちら

ESLintの記事はこちら

ESLintとPrettierの併用こちら

2
2
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
2
2