Help us understand the problem. What is going on with this article?

prettier でコードフォーマットしてみた

More than 1 year has passed since last update.

インストール

https://github.com/prettier/prettier

npm install prettier --save-dev

.prettierrc

package.json と同階層に .prettierrc を置きます。
JSON または YAML で書けます。

.prettierrc
printWidth: 120 # 1行の文字数制限
tabWidth: 2
singleQuote: true
trailingComma: none
semi: false
parser: typescript # flow もあります。

その他のオプションは下記を参照ください。
https://github.com/prettier/prettier#options

npm scripts を追加する

例では format の略字で fmt としてますが、なんでも構いません。
--write をつけるとファイルを上書きしてくれます。

package.json
"scripts": {
  "fmt": "prettier --write 'src/**/*.js'"
}

実行

npm run fmt

感想

eslint と競合しました。
各種リンターを使用する場合、ルールを考慮する必要があります。

kkeisuke
TypeScript / Vue.js / Go / 母・妹・妻と自社システム開発中(ベータ版テスト中)
https://kkeisuke.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした