0
0

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 の設定をする

0
Last updated at Posted at 2022-08-05

備忘録

Prettier とは

Prettier とはコードフォーマッタです。
ソースコードを整形してくれるやつです。

以下に対応しているらしい

JavaScript
JSX
Flow
TypeScript
JSON
HTML
Vue
Angular
Ember / Handlebars
CSS
Less
SCSS
styled-components 💅
styled-jsx
GraphQL
Markdown
YAML

インストールする

prettierrc—_parser-mizumoni.png

設定してみる

セミロコンつけてくださいてきなやつ
お好みでどうぞ

.prettierrc
{
  "semi": true,
  "arrowParens": "always",
  "bracketSpacing": true,
  "singleQuote": true,
  "endOfLine": "auto"
}

どうやって使うの?

コマンドを走らせる

"format": "prettier --write './src/**/*.ts'"
を追加する

package.json
{
  "name": "app_name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "npm run json2ts && tsc --build tsconfig.json",
    "main": "node dist/app.js",
    "dev": "nodemon --watch src --exec ts-node --compiler-options '{\"noUnusedLocals\": false}' src/app.ts",
    "format": "prettier --write './src/**/*.ts'"
  },

  省略

ディレクトリ保存時に適応させる

package_json_—_parser-mizumoni.png

スクリーンショット_2022-08-05_12_54_40.png

Menubar.png

※他の設定も入ってます

settings.json
{
    "editor.tabCompletion": "on",
    "editor.tabSize": 2,
    "files.trimTrailingWhitespace": true,
    "files.insertFinalNewline": true,
    "[json]": {
      "editor.defaultFormatter": "vscode.json-language-features"
    },
    "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
    },
    "editor.formatOnSave": true,
    "[javascript]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[typescript]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "cSpell.enabledLanguageIds": [
      "html",
      "css",
      "ruby",
      "javascript",
      "typescript",
      "markdown"
    ],
}


.prettierrc に基づく

{
    "workbench.startupEditor": "none",
    "editor.tabSize": 2,
    "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "editor.formatOnSave": true,
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[typescript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "prettier.requireConfig": true,
    "prettier.configPath": "./.prettierrc",
}
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?