.rubocop.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. - db/*migrate/**/*
  65. # Reason: Currently disabled in .rubocop_todo.yml
  66. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
  67. Metrics/CyclomaticComplexity:
  68. Exclude:
  69. - lib/mastodon/cli/*.rb
  70. - db/*migrate/**/*
  71. # Reason:
  72. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists
  73. Metrics/ParameterLists:
  74. CountKeywordArgs: false
  75. # Reason: Prevailing style is argument file paths
  76. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsfilepath
  77. Rails/FilePath:
  78. EnforcedStyle: arguments
  79. # Reason: Prevailing style uses numeric status codes, matches RSpec/Rails/HttpStatus
  80. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railshttpstatus
  81. Rails/HttpStatus:
  82. EnforcedStyle: numeric
  83. # Reason: Allowed in `tootctl` CLI code and in boot ENV checker
  84. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsexit
  85. Rails/Exit:
  86. Exclude:
  87. - 'config/boot.rb'
  88. - 'lib/mastodon/cli/*.rb'
  89. Rails/SkipsModelValidations:
  90. Exclude:
  91. - 'db/*migrate/**/*'
  92. # Reason: Some single letter camel case files shouldn't be split
  93. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecfilepath
  94. RSpec/FilePath:
  95. CustomTransform:
  96. ActivityPub: activitypub
  97. DeepL: deepl
  98. FetchOEmbedService: fetch_oembed_service
  99. OEmbedController: oembed_controller
  100. OStatus: ostatus
  101. # Reason:
  102. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnamedsubject
  103. RSpec/NamedSubject:
  104. EnforcedStyle: named_only
  105. # Reason: Prevailing style choice
  106. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnottonot
  107. RSpec/NotToNot:
  108. EnforcedStyle: to_not
  109. # Reason: Prevailing style uses numeric status codes, matches Rails/HttpStatus
  110. # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html#rspecrailshttpstatus
  111. RSpec/Rails/HttpStatus:
  112. EnforcedStyle: numeric
  113. # Reason: Match overrides from Rspec/FilePath rule above
  114. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecspecfilepathformat
  115. RSpec/SpecFilePathFormat:
  116. CustomTransform:
  117. ActivityPub: activitypub
  118. DeepL: deepl
  119. FetchOEmbedService: fetch_oembed_service
  120. OEmbedController: oembed_controller
  121. OStatus: ostatus
  122. # Reason:
  123. # https://docs.rubocop.org/rubocop/cops_style.html#styleclassandmodulechildren
  124. Style/ClassAndModuleChildren:
  125. Enabled: false
  126. # Reason: Classes mostly self-document with their names
  127. # https://docs.rubocop.org/rubocop/cops_style.html#styledocumentation
  128. Style/Documentation:
  129. Enabled: false
  130. # Reason: Enforce modern Ruby style
  131. # https://docs.rubocop.org/rubocop/cops_style.html#stylehashsyntax
  132. Style/HashSyntax:
  133. EnforcedStyle: ruby19_no_mixed_keys
  134. # Reason:
  135. # https://docs.rubocop.org/rubocop/cops_style.html#stylenumericliterals
  136. Style/NumericLiterals:
  137. AllowedPatterns:
  138. - \d{4}_\d{2}_\d{2}_\d{6} # For DB migration date version number readability
  139. # Reason:
  140. # https://docs.rubocop.org/rubocop/cops_style.html#stylepercentliteraldelimiters
  141. Style/PercentLiteralDelimiters:
  142. PreferredDelimiters:
  143. '%i': '()'
  144. '%w': '()'
  145. # Reason: Prefer less indentation in conditional assignments
  146. # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantbegin
  147. Style/RedundantBegin:
  148. Enabled: false
  149. # Reason: Overridden to reduce implicit StandardError rescues
  150. # https://docs.rubocop.org/rubocop/cops_style.html#stylerescuestandarderror
  151. Style/RescueStandardError:
  152. EnforcedStyle: implicit
  153. # Reason: Simplify some spec layouts
  154. # https://docs.rubocop.org/rubocop/cops_style.html#stylesemicolon
  155. Style/Semicolon:
  156. AllowAsExpressionSeparator: true
  157. # Reason: Originally disabled for CodeClimate, and no config consensus has been found
  158. # https://docs.rubocop.org/rubocop/cops_style.html#stylesymbolarray
  159. Style/SymbolArray:
  160. Enabled: false
  161. # Reason:
  162. # https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainarrayliteral
  163. Style/TrailingCommaInArrayLiteral:
  164. EnforcedStyleForMultiline: 'comma'
  165. # Reason:
  166. # https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainhashliteral
  167. Style/TrailingCommaInHashLiteral:
  168. EnforcedStyleForMultiline: 'comma'
  169. Style/MiddleDot:
  170. Enabled: true