.rubocop.yml 7.2 KB

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