不要 .prettierrc*

直接参考如下 settings.json 配置

  1. {
  2. "search.exclude": {
  3. "**/node_modules": true
  4. },
  5. //-------- Files configuration --------
  6. // Configure glob patterns for excluding files and folders.
  7. "files.exclude": {
  8. "**/*.swn": true,
  9. "**/*.swo": true,
  10. "**/*.swp": true,
  11. "**/node_modules": true,
  12. "**/.git": true,
  13. "**/.DS_Store": true,
  14. "**/.sass-cache/": true,
  15. "**/*.map": true,
  16. "**/packages": true
  17. },
  18. // "eslint.validate": [
  19. // "javascript",
  20. // "javascriptreact",
  21. // "typescript",
  22. // "typescriptreact",
  23. // "css",
  24. // "scss",
  25. // "sass"
  26. // ],
  27. // "[css, scss]": {
  28. // "editor.defaultFormatter": "esbenp.prettier-vscode"
  29. // },
  30. // "[javascript]": {
  31. // "editor.defaultFormatter": "esbenp.prettier-vscode"
  32. // },
  33. // "[javascriptreact]": {
  34. // "editor.defaultFormatter": "esbenp.prettier-vscode"
  35. // },
  36. // "[typescriptreact]": {
  37. // "editor.defaultFormatter": "esbenp.prettier-vscode"
  38. // },
  39. "editor.formatOnSave": true,
  40. "editor.formatOnType": true,
  41. "editor.codeActionsOnSave": { "source.fixAll.eslint": true },
  42. // "editor.formatOnType": true,
  43. // "editor.codeActionsOnSave": { "source.fixAll.eslint": true }
  44. "editor.defaultFormatter": "esbenp.prettier-vscode",
  45. // "eslint.enable": true,
  46. // "[html]": {
  47. // "editor.defaultFormatter": "esbenp.prettier-vscode"
  48. // },
  49. // "[javascript]": {
  50. // "editor.defaultFormatter": "esbenp.prettier-vscode"
  51. // }
  52. /* prettier的配置 */
  53. "prettier.printWidth": 160, // 超过最大值换行
  54. "prettier.tabWidth": 2, // 缩进字节数
  55. "prettier.useTabs": false, // 缩进不使用tab,使用空格
  56. "prettier.semi": true, // 句尾添加分号
  57. "prettier.singleQuote": true, // 使用单引号代替双引号
  58. "prettier.jsxSingleQuote": true, // jsx中使用单引号代替双引号
  59. // "prettier.proseWrap": "preserve", // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行
  60. // "prettier.arrowParens": "avoid", // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号
  61. "prettier.bracketSpacing": true, // 在对象,数组括号与文字之间加空格 "{ foo: bar }"
  62. // "prettier.disableLanguages": ["vue"], // 不格式化vue文件,vue文件的格式化单独设置
  63. // "prettier.endOfLine": "auto", // 结尾是 \n \r \n\r auto
  64. // "prettier.eslintIntegration": false, // 不让prettier使用eslint的代码格式进行校验
  65. // "prettier.htmlWhitespaceSensitivity": "ignore",
  66. "prettier.ignorePath": ".prettierignore", // 不使用prettier格式化的文件填写在项目的.prettierignore文件中
  67. "prettier.jsxBracketSameLine": false, // jsx中把'>' 是否单独放一行
  68. "prettier.parser": "babel", // 格式化的解析器,默认是babylon
  69. // "prettier.requireConfig": false, // Require a 'prettierconfig' to format prettier
  70. // "prettier.stylelintIntegration": false, // 不让prettier使用stylelint的代码格式进行校验
  71. "prettier.trailingComma": "all" // 在对象或数组最后一个元素后面是否加逗号(在ES5中加尾逗号)
  72. // "prettier.tslintIntegration": false // 不让prettier使用tslint的代码格式进行校验
  73. }

局部禁用

  1. // prettier-ignore
  2. x = '' +
  3. '<div id="welfare-modal-purchase">' +
  4. '<div class="hb-modal-mask"></div>' +
  5. '<div class="hb-modal-wrap">' +
  6. '<div class="hb-modal" style="' + config.width + 'px">' +
  7. '<div class="hb-modal-content">' +
  8. '<div class="hb-modal-close hb-modal-btn-close"></div>' +
  9. '<div class="hb-modal-header">' +
  10. '<div class="hb-modal-title">' + config.title + '</div>' +
  11. '</div>' +
  12. '<div class="hb-modal-body"></div>' +
  13. '<div class="hb-modal-footer">' +
  14. '<div class="hb-btn cancel hb-modal-btn hb-modal-btn-close">取消</div>' +
  15. '<div class="hb-btn primary hb-modal-btn hb-modal-btn-confirm">确认</div>' +
  16. '</div>' +
  17. '</div>' + // end hb-modal-content
  18. '</div>' + // end hb-modal
  19. '</div>'+ // end hb-modal-wrap
  20. '</div>';

Visual Studio Code Settings

You can use VS Code settings to configure prettier. Settings will be read from (listed by priority):

  • Prettier configuration file
  • .editorconfig
  • Visual Studio Code Settings (Ignored if any other configuration is present)

NOTE: If any local configuration file is present (i.e. .prettierrc) the VS Code settings will NOT be used.