.rubocop.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Can be removed once all rules are addressed or moved to this file as documented overrides
  2. inherit_from: .rubocop_todo.yml
  3. # Used for merging with exclude lists with .rubocop_todo.yml
  4. inherit_mode:
  5. merge:
  6. - Exclude
  7. require:
  8. - rubocop-rails
  9. - rubocop-rspec
  10. - rubocop-rspec_rails
  11. - rubocop-performance
  12. - rubocop-capybara
  13. - ./lib/linter/rubocop_middle_dot
  14. AllCops:
  15. TargetRubyVersion: 3.1 # Set to minimum supported version of CI
  16. DisplayCopNames: true
  17. DisplayStyleGuide: true
  18. ExtraDetails: true
  19. UseCache: true
  20. CacheRootDirectory: tmp
  21. NewCops: enable # Opt-in to newly added rules
  22. Exclude:
  23. - db/schema.rb
  24. - 'bin/*'
  25. - 'node_modules/**/*'
  26. - 'Vagrantfile'
  27. - 'vendor/**/*'
  28. - 'config/initializers/json_ld*' # Generated files
  29. - 'lib/mastodon/migration_helpers.rb' # Vendored from GitLab
  30. - 'lib/templates/**/*'
  31. # Reason: Prefer Hashes without extreme indentation
  32. # https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirsthashelementindentation
  33. Layout/FirstHashElementIndentation:
  34. EnforcedStyle: consistent
  35. # Reason: Currently disabled in .rubocop_todo.yml
  36. # https://docs.rubocop.org/rubocop/cops_layout.html#layoutlinelength
  37. Layout/LineLength:
  38. Max: 300 # Default of 120 causes a duplicate entry in generated todo file
  39. ## Disable most Metrics/*Length cops
  40. # Reason: those are often triggered and force significant refactors when this happend
  41. # but the team feel they are not really improving the code quality.
  42. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsblocklength
  43. Metrics/BlockLength:
  44. Enabled: false
  45. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsclasslength
  46. Metrics/ClassLength:
  47. Enabled: false
  48. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmethodlength
  49. Metrics/MethodLength:
  50. Enabled: false
  51. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmodulelength
  52. Metrics/ModuleLength:
  53. Enabled: false
  54. ## End Disable Metrics/*Length cops
  55. # Reason: Currently disabled in .rubocop_todo.yml
  56. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsabcsize
  57. Metrics/AbcSize:
  58. Exclude:
  59. - 'lib/mastodon/cli/*.rb'
  60. # Reason: Currently disabled in .rubocop_todo.yml
  61. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
  62. Metrics/CyclomaticComplexity:
  63. Exclude:
  64. - lib/mastodon/cli/*.rb
  65. # Reason:
  66. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists
  67. Metrics/ParameterLists:
  68. CountKeywordArgs: false
  69. # Reason: Prefer seeing a variable name
  70. # https://docs.rubocop.org/rubocop/cops_naming.html#namingblockforwarding
  71. Naming/BlockForwarding:
  72. EnforcedStyle: explicit
  73. # Reason: Prevailing style is argument file paths
  74. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsfilepath
  75. Rails/FilePath:
  76. EnforcedStyle: arguments
  77. # Reason: Prevailing style uses numeric status codes, matches RSpec/Rails/HttpStatus
  78. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railshttpstatus
  79. Rails/HttpStatus:
  80. EnforcedStyle: numeric
  81. # Reason: Conflicts with `Lint/UselessMethodDefinition` for inherited controller actions
  82. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railslexicallyscopedactionfilter
  83. Rails/LexicallyScopedActionFilter:
  84. Exclude:
  85. - 'app/controllers/auth/*'
  86. # Reason: These tasks are doing local work which do not need full env loaded
  87. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsrakeenvironment
  88. Rails/RakeEnvironment:
  89. Exclude:
  90. - 'lib/tasks/auto_annotate_models.rake'
  91. - 'lib/tasks/emojis.rake'
  92. - 'lib/tasks/mastodon.rake'
  93. - 'lib/tasks/repo.rake'
  94. - 'lib/tasks/statistics.rake'
  95. # Reason: There are appropriate times to use these features
  96. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsskipsmodelvalidations
  97. Rails/SkipsModelValidations:
  98. Enabled: false
  99. # Reason: We want to preserve the ability to migrate from arbitrary old versions,
  100. # and cannot guarantee that every installation has run every migration as they upgrade.
  101. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsunusedignoredcolumns
  102. Rails/UnusedIgnoredColumns:
  103. Enabled: false
  104. # Reason: Prevailing style choice
  105. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsnegateinclude
  106. Rails/NegateInclude:
  107. Enabled: false
  108. # Reason: Enforce default limit, but allow some elements to span lines
  109. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecexamplelength
  110. RSpec/ExampleLength:
  111. CountAsOne: ['array', 'heredoc', 'method_call']
  112. # Reason: Deprecated cop, will be removed in 3.0, replaced by SpecFilePathFormat
  113. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecfilepath
  114. RSpec/FilePath:
  115. Enabled: false
  116. # Reason:
  117. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnamedsubject
  118. RSpec/NamedSubject:
  119. EnforcedStyle: named_only
  120. # Reason: Prevailing style choice
  121. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnottonot
  122. RSpec/NotToNot:
  123. EnforcedStyle: to_not
  124. # Reason: Match overrides from Rspec/FilePath rule above
  125. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecspecfilepathformat
  126. RSpec/SpecFilePathFormat:
  127. CustomTransform:
  128. ActivityPub: activitypub
  129. DeepL: deepl
  130. FetchOEmbedService: fetch_oembed_service
  131. OEmbedController: oembed_controller
  132. OStatus: ostatus
  133. # Reason: Prevailing style uses numeric status codes, matches Rails/HttpStatus
  134. # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html#rspecrailshttpstatus
  135. RSpecRails/HttpStatus:
  136. EnforcedStyle: numeric
  137. # Reason:
  138. # https://docs.rubocop.org/rubocop/cops_style.html#styleclassandmodulechildren
  139. Style/ClassAndModuleChildren:
  140. Enabled: false
  141. # Reason: Classes mostly self-document with their names
  142. # https://docs.rubocop.org/rubocop/cops_style.html#styledocumentation
  143. Style/Documentation:
  144. Enabled: false
  145. # Reason: Route redirects are not token-formatted and must be skipped
  146. # https://docs.rubocop.org/rubocop/cops_style.html#styleformatstringtoken
  147. Style/FormatStringToken:
  148. inherit_mode:
  149. merge:
  150. - AllowedMethods # The rubocop-rails config adds `redirect`
  151. AllowedMethods:
  152. - redirect_with_vary
  153. # Reason: Prevailing style choice
  154. # https://docs.rubocop.org/rubocop/cops_style.html#stylehashaslastarrayitem
  155. Style/HashAsLastArrayItem:
  156. Enabled: false
  157. # Reason: Enforce modern Ruby style
  158. # https://docs.rubocop.org/rubocop/cops_style.html#stylehashsyntax
  159. Style/HashSyntax:
  160. EnforcedStyle: ruby19_no_mixed_keys
  161. EnforcedShorthandSyntax: either
  162. # Reason:
  163. # https://docs.rubocop.org/rubocop/cops_style.html#stylenumericliterals
  164. Style/NumericLiterals:
  165. AllowedPatterns:
  166. - \d{4}_\d{2}_\d{2}_\d{6} # For DB migration date version number readability
  167. # Reason:
  168. # https://docs.rubocop.org/rubocop/cops_style.html#stylepercentliteraldelimiters
  169. Style/PercentLiteralDelimiters:
  170. PreferredDelimiters:
  171. '%i': '()'
  172. '%w': '()'
  173. # Reason: Prefer less indentation in conditional assignments
  174. # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantbegin
  175. Style/RedundantBegin:
  176. Enabled: false
  177. # Reason: Overridden to reduce implicit StandardError rescues
  178. # https://docs.rubocop.org/rubocop/cops_style.html#stylerescuestandarderror
  179. Style/RescueStandardError:
  180. EnforcedStyle: implicit
  181. # Reason: Originally disabled for CodeClimate, and no config consensus has been found
  182. # https://docs.rubocop.org/rubocop/cops_style.html#stylesymbolarray
  183. Style/SymbolArray:
  184. Enabled: false
  185. # Reason:
  186. # https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainarrayliteral
  187. Style/TrailingCommaInArrayLiteral:
  188. EnforcedStyleForMultiline: 'comma'
  189. # Reason:
  190. # https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainhashliteral
  191. Style/TrailingCommaInHashLiteral:
  192. EnforcedStyleForMultiline: 'comma'
  193. Style/MiddleDot:
  194. Enabled: true