.rubocop.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. - 'lib/json_ld/*' # Generated files
  28. - 'lib/templates/**/*'
  29. # Reason: Prefer Hashes without extreme indentation
  30. # https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirsthashelementindentation
  31. Layout/FirstHashElementIndentation:
  32. EnforcedStyle: consistent
  33. # Reason: Currently disabled in .rubocop_todo.yml
  34. # https://docs.rubocop.org/rubocop/cops_layout.html#layoutlinelength
  35. Layout/LineLength:
  36. Max: 320 # Default of 120 causes a duplicate entry in generated todo file
  37. # Reason:
  38. # https://docs.rubocop.org/rubocop/cops_lint.html#lintuselessaccessmodifier
  39. Lint/UselessAccessModifier:
  40. ContextCreatingMethods:
  41. - class_methods
  42. ## Disable most Metrics/*Length cops
  43. # Reason: those are often triggered and force significant refactors when this happend
  44. # but the team feel they are not really improving the code quality.
  45. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsblocklength
  46. Metrics/BlockLength:
  47. Enabled: false
  48. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsclasslength
  49. Metrics/ClassLength:
  50. Enabled: false
  51. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmethodlength
  52. Metrics/MethodLength:
  53. Enabled: false
  54. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmodulelength
  55. Metrics/ModuleLength:
  56. Enabled: false
  57. ## End Disable Metrics/*Length cops
  58. # Reason: Currently disabled in .rubocop_todo.yml
  59. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsabcsize
  60. Metrics/AbcSize:
  61. Exclude:
  62. - 'lib/mastodon/cli/*.rb'
  63. - db/*migrate/**/*
  64. # Reason:
  65. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsblocknesting
  66. Metrics/BlockNesting:
  67. Exclude:
  68. - 'lib/mastodon/cli/*.rb'
  69. # Reason: Currently disabled in .rubocop_todo.yml
  70. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
  71. Metrics/CyclomaticComplexity:
  72. Exclude:
  73. - lib/mastodon/cli/*.rb
  74. - db/*migrate/**/*
  75. # Reason:
  76. # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists
  77. Metrics/ParameterLists:
  78. CountKeywordArgs: false
  79. # Reason: Prevailing style is argument file paths
  80. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsfilepath
  81. Rails/FilePath:
  82. EnforcedStyle: arguments
  83. # Reason: Prevailing style uses numeric status codes, matches RSpec/Rails/HttpStatus
  84. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railshttpstatus
  85. Rails/HttpStatus:
  86. EnforcedStyle: numeric
  87. # Reason: Allowed in `tootctl` CLI code and in boot ENV checker
  88. # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsexit
  89. Rails/Exit:
  90. Exclude:
  91. - 'config/boot.rb'
  92. - 'lib/mastodon/cli/*.rb'
  93. # Reason: Some single letter camel case files shouldn't be split
  94. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecfilepath
  95. RSpec/FilePath:
  96. CustomTransform:
  97. ActivityPub: activitypub # Ignore the snake_case due to the amount of files to rename
  98. DeepL: deepl
  99. FetchOEmbedService: fetch_oembed_service
  100. JsonLdHelper: jsonld_helper
  101. OEmbedController: oembed_controller
  102. OStatus: ostatus
  103. NodeInfoController: nodeinfo_controller # NodeInfo isn't snake_cased for any of the instances
  104. Exclude:
  105. - 'spec/config/initializers/rack_attack_spec.rb' # namespaces usually have separate folder
  106. - 'spec/lib/sanitize_config_spec.rb' # namespaces usually have separate folder
  107. # Reason:
  108. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnamedsubject
  109. RSpec/NamedSubject:
  110. EnforcedStyle: named_only
  111. # Reason: Prevailing style choice
  112. # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnottonot
  113. RSpec/NotToNot:
  114. EnforcedStyle: to_not
  115. # Reason: Prevailing style uses numeric status codes, matches Rails/HttpStatus
  116. # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html#rspecrailshttpstatus
  117. RSpec/Rails/HttpStatus:
  118. EnforcedStyle: numeric
  119. # Reason:
  120. # https://docs.rubocop.org/rubocop/cops_style.html#styleclassandmodulechildren
  121. Style/ClassAndModuleChildren:
  122. Enabled: false
  123. # Reason: Classes mostly self-document with their names
  124. # https://docs.rubocop.org/rubocop/cops_style.html#styledocumentation
  125. Style/Documentation:
  126. Enabled: false
  127. # Reason: Enforce modern Ruby style
  128. # https://docs.rubocop.org/rubocop/cops_style.html#stylehashsyntax
  129. Style/HashSyntax:
  130. EnforcedStyle: ruby19_no_mixed_keys
  131. # Reason:
  132. # https://docs.rubocop.org/rubocop/cops_style.html#stylenumericliterals
  133. Style/NumericLiterals:
  134. AllowedPatterns:
  135. - \d{4}_\d{2}_\d{2}_\d{6} # For DB migration date version number readability
  136. # Reason:
  137. # https://docs.rubocop.org/rubocop/cops_style.html#stylepercentliteraldelimiters
  138. Style/PercentLiteralDelimiters:
  139. PreferredDelimiters:
  140. '%i': '()'
  141. '%w': '()'
  142. # Reason: Prefer less indentation in conditional assignments
  143. # https://docs.rubocop.org/rubocop/cops_style.html#styleredundantbegin
  144. Style/RedundantBegin:
  145. Enabled: false
  146. # Reason: Overridden to reduce implicit StandardError rescues
  147. # https://docs.rubocop.org/rubocop/cops_style.html#stylerescuestandarderror
  148. Style/RescueStandardError:
  149. EnforcedStyle: implicit
  150. # Reason: Simplify some spec layouts
  151. # https://docs.rubocop.org/rubocop/cops_style.html#stylesemicolon
  152. Style/Semicolon:
  153. AllowAsExpressionSeparator: true
  154. # Reason: Originally disabled for CodeClimate, and no config consensus has been found
  155. # https://docs.rubocop.org/rubocop/cops_style.html#stylesymbolarray
  156. Style/SymbolArray:
  157. Enabled: false
  158. # Reason:
  159. # https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainarrayliteral
  160. Style/TrailingCommaInArrayLiteral:
  161. EnforcedStyleForMultiline: 'comma'
  162. # Reason:
  163. # https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainhashliteral
  164. Style/TrailingCommaInHashLiteral:
  165. EnforcedStyleForMultiline: 'comma'
  166. Style/MiddleDot:
  167. Enabled: true