zh-rocco / fe-notes

:memo: 前端笔记

Home Page:https://zh-rocco.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

【Tools】Prettier 配置

zh-rocco opened this issue · comments

commented

推荐

如果项目中配置 eslint 的话,在 VSCode settings.json 里添加配置 "prettier.eslintIntegration": true

参考配置

.prettierrc

{
  "printWidth": 80,  // 换行字符串阈值
  "singleQuote": true,  // 使用单引号
  "semi": true,  // 句末加分号
  "trailingComma": "all",  // 对象 / 数组 多行时最后一行加逗号
  "bracketSpacing": true,  // 对象 / 数组 边界加空格
  "arrowParens": "always" // 箭头函数参数加括号
}

在命令行使用 prettier 格式化项目代码

yarn global add prettier

prettier --config ./.prettierrc --write "src/**/*.{js,vue,less}"

参考文档