.prettierrc.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module.exports = {
  2. // 基础配置
  3. printWidth: 100, // 每行最大字符数
  4. tabWidth: 2, // 缩进空格数
  5. useTabs: false, // 使用空格缩进
  6. semi: true, // 语句末尾使用分号
  7. singleQuote: true, // 使用单引号
  8. quoteProps: 'as-needed', // 对象属性按需加引号
  9. jsxSingleQuote: false, // JSX中使用双引号
  10. // 尾随逗号配置
  11. trailingComma: 'only-multiline', // 多行时才添加尾随逗号
  12. // 括号配置
  13. bracketSpacing: true, // 对象字面量的括号之间添加空格
  14. bracketSameLine: false, // 将多行HTML元素的>放在最后一行的末尾
  15. // 箭头函数配置
  16. arrowParens: 'always', // 箭头函数参数总是使用括号
  17. // 格式化范围
  18. rangeStart: 0,
  19. rangeEnd: Infinity,
  20. // Vue文件配置
  21. vueIndentScriptAndStyle: false, // 不缩进Vue文件中的script和style标签
  22. // HTML配置
  23. htmlWhitespaceSensitivity: 'css', // HTML空格敏感度
  24. // 换行符配置
  25. endOfLine: 'auto', // 自动检测换行符
  26. // 嵌入式语言格式化
  27. embeddedLanguageFormatting: 'auto', // 自动格式化嵌入的代码
  28. // 特定文件覆盖配置
  29. overrides: [
  30. {
  31. files: '*.vue',
  32. options: {
  33. parser: 'vue'
  34. }
  35. },
  36. {
  37. files: ['*.json', '.eslintrc', '.prettierrc'],
  38. options: {
  39. parser: 'json',
  40. tabWidth: 2
  41. }
  42. },
  43. {
  44. files: '*.md',
  45. options: {
  46. parser: 'markdown',
  47. proseWrap: 'preserve'
  48. }
  49. },
  50. {
  51. files: '*.yaml',
  52. options: {
  53. parser: 'yaml',
  54. tabWidth: 2
  55. }
  56. }
  57. ],
  58. // 忽略的文件和目录(从 .prettierignore 合并而来)
  59. // 注意:Prettier 使用 .prettierignore 文件或 package.json 中的配置
  60. // 这里仅作为文档记录,实际忽略需要通过其他方式配置
  61. /*
  62. ignorePatterns: [
  63. 'node_modules',
  64. 'dist',
  65. 'public',
  66. 'docs',
  67. '*.min.js',
  68. '*.min.css',
  69. 'package-lock.json',
  70. '.vscode',
  71. '.idea'
  72. ]
  73. */
  74. };
  75. // 导出忽略模式供工具使用
  76. module.exports.prettierIgnore = [
  77. 'node_modules',
  78. 'dist',
  79. 'public',
  80. 'docs',
  81. '*.min.js',
  82. '*.min.css',
  83. 'package-lock.json',
  84. '.vscode',
  85. '.idea'
  86. ];