.golangci.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. version: "2"
  2. linters:
  3. default: none
  4. enable:
  5. - depguard
  6. - errcheck
  7. - gosec
  8. - govet
  9. - ineffassign
  10. - staticcheck
  11. - unused
  12. settings:
  13. depguard:
  14. rules:
  15. # Enforce: service must not depend on repository.
  16. service-no-repository:
  17. list-mode: original
  18. files:
  19. - "**/internal/service/**"
  20. - "!**/internal/service/ops_aggregation_service.go"
  21. - "!**/internal/service/ops_alert_evaluator_service.go"
  22. - "!**/internal/service/ops_cleanup_service.go"
  23. - "!**/internal/service/ops_metrics_collector.go"
  24. - "!**/internal/service/ops_scheduled_report_service.go"
  25. - "!**/internal/service/wire.go"
  26. deny:
  27. - pkg: github.com/Wei-Shaw/sub2api/internal/repository
  28. desc: "service must not import repository"
  29. - pkg: gorm.io/gorm
  30. desc: "service must not import gorm"
  31. - pkg: github.com/redis/go-redis/v9
  32. desc: "service must not import redis"
  33. handler-no-repository:
  34. list-mode: original
  35. files:
  36. - "**/internal/handler/**"
  37. deny:
  38. - pkg: github.com/Wei-Shaw/sub2api/internal/repository
  39. desc: "handler must not import repository"
  40. - pkg: gorm.io/gorm
  41. desc: "handler must not import gorm"
  42. - pkg: github.com/redis/go-redis/v9
  43. desc: "handler must not import redis"
  44. gosec:
  45. excludes:
  46. - G101
  47. - G103
  48. - G104
  49. - G109
  50. - G115
  51. - G201
  52. - G202
  53. - G301
  54. - G302
  55. - G304
  56. - G306
  57. - G404
  58. severity: high
  59. confidence: high
  60. errcheck:
  61. # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
  62. # Such cases aren't reported by default.
  63. # Default: false
  64. check-type-assertions: true
  65. # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
  66. # Such cases aren't reported by default.
  67. # Default: false
  68. check-blank: false
  69. # To disable the errcheck built-in exclude list.
  70. # See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
  71. # Default: false
  72. disable-default-exclusions: true
  73. # List of functions to exclude from checking, where each entry is a single function to exclude.
  74. # See https://github.com/kisielk/errcheck#excluding-functions for details.
  75. exclude-functions:
  76. - io/ioutil.ReadFile
  77. - io.Copy(*bytes.Buffer)
  78. - io.Copy(os.Stdout)
  79. - fmt.Println
  80. - fmt.Print
  81. - fmt.Printf
  82. - fmt.Fprint
  83. - fmt.Fprintf
  84. - fmt.Fprintln
  85. # Display function signature instead of selector.
  86. # Default: false
  87. verbose: true
  88. ineffassign:
  89. # Check escaping variables of type error, may cause false positives.
  90. # Default: false
  91. check-escaping-errors: true
  92. staticcheck:
  93. # https://staticcheck.dev/docs/configuration/options/#dot_import_whitelist
  94. dot-import-whitelist:
  95. - fmt
  96. # https://staticcheck.dev/docs/configuration/options/#initialisms
  97. initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS" ]
  98. # https://staticcheck.dev/docs/configuration/options/#http_status_code_whitelist
  99. http-status-code-whitelist: [ "200", "400", "404", "500" ]
  100. # "all" enables every SA/ST/S/QF check; only list the ones to disable.
  101. checks:
  102. - all
  103. - -ST1000 # Package comment format
  104. - -ST1003 # Poorly chosen identifier (ApiKey vs APIKey)
  105. - -ST1020 # Comment on exported method format
  106. - -ST1021 # Comment on exported type format
  107. - -ST1022 # Comment on exported variable format
  108. unused:
  109. # Default: true
  110. field-writes-are-uses: true
  111. # Default: false
  112. post-statements-are-reads: true
  113. # Default: true
  114. exported-fields-are-used: true
  115. # Default: true
  116. parameters-are-used: true
  117. # Default: true
  118. local-variables-are-used: false
  119. # Default: true — must be true, ent generates 130K+ lines of code
  120. generated-is-used: true
  121. exclusions:
  122. rules:
  123. # G703/G704 污点分析在测试文件中只会命中 httptest mock 与测试者自设的
  124. # 环境变量路径,不构成攻击面;且该分析跨环境结果不稳定(本地/CI 报告的
  125. # 位置集合不同),逐点 nolint 无法收敛,故按路径豁免。生产代码不豁免,
  126. # 必须逐点 //nolint:gosec 并写明信任边界。
  127. - path: '_test\.go$'
  128. linters: [ gosec ]
  129. text: 'G70[34]'
  130. formatters:
  131. enable:
  132. - gofmt
  133. settings:
  134. gofmt:
  135. # Simplify code: gofmt with `-s` option.
  136. # Default: true
  137. simplify: false
  138. # Apply the rewrite rules to the source before reformatting.
  139. # https://pkg.go.dev/cmd/gofmt
  140. # Default: []
  141. rewrite-rules:
  142. - pattern: 'interface{}'
  143. replacement: 'any'
  144. - pattern: 'a[b:len(a)]'
  145. replacement: 'a[b:]'