plugins:
  - rubocop-rails

AllCops:
  TargetRubyVersion: 3.0
  NewCops: enable
  Exclude:
    - "bin/**/*"
    - "db/schema.rb"
    - "config/locales/cldr/plurals.rb"

# Disable for rails 4
Rails/HttpPositionalArguments:
  Enabled: false

# Commonly used screens these days easily fit more than 80 characters.
Layout/LineLength:
  Max: 120

# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
  Max: 20

# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength:
  Max: 1500
Metrics/ModuleLength:
  Max: 1500

# Raise complexity metrics
Metrics/AbcSize:
  Max: 20

Metrics/CyclomaticComplexity:
  Max: 20

Metrics/PerceivedComplexity:
  Max: 20

# Some blocks are longer.
Metrics/BlockLength:
  AllowedMethods:
    - "namespace"
    - "create_table"
  Exclude:
    - "config/**/*.rb"
    - "spec/**/*.rb"

# No space makes the method definition shorter and differentiates
# from a regular assignment.
Layout/SpaceAroundEqualsInParameterDefault:
  EnforcedStyle: no_space

# Single quotes being faster is hardly measurable and only affects parse time.
# Enforcing double quotes reduces the times where you need to change them
# when introducing an interpolation. Use single quotes only if their semantics
# are needed.
Style/StringLiterals:
  EnforcedStyle: double_quotes
  Exclude:
    # These files are generated by rails, so it's best to keep them close to the original for smaller diffs
    - "config/application.rb"
    - "config/boot.rb"
    - "config/environment.rb"
    - "config/environments/*.rb"

# We do not need to support Ruby 1.9, so this is good to use.
Style/SymbolArray:
  Enabled: true

# Most readable form.
Layout/HashAlignment:
  EnforcedHashRocketStyle: table
  EnforcedColonStyle: table

# This rule makes haml files less readable, as there is no 'end' there.
Layout/CaseIndentation:
  Exclude:
    - "app/views/**/*"

# Mixing the styles looks just silly.
Style/HashSyntax:
  EnforcedStyle: ruby19_no_mixed_keys

# has_key? and has_value? are far more readable than key? and value?
Style/PreferredHashMethods:
  Enabled: false

# String#% is by far the least verbose and only object oriented variant.
Style/FormatString:
  EnforcedStyle: percent

Style/CollectionMethods:
  Enabled: true
  PreferredMethods:
    # inject seems more common in the community.
    reduce: "inject"

# Either allow this style or don't. Marking it as safe with parenthesis
# is silly. Let's try to live without them for now.
Style/ParenthesesAroundCondition:
  AllowSafeAssignment: false
Lint/AssignmentInCondition:
  AllowSafeAssignment: false

# A specialized exception class will take one or more arguments and construct the message from it.
# So both variants make sense.
Style/RaiseArgs:
  Enabled: false

# Indenting the chained dots beneath each other is not supported by this cop,
# see https://github.com/bbatsov/rubocop/issues/1633
Layout/MultilineOperationIndentation:
  Enabled: false

# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
# The argument that fail should be used to abort the program is wrong too,
# there's Kernel#abort for that.
Style/SignalException:
  EnforcedStyle: only_raise

# Suppressing exceptions can be perfectly fine, and be it to avoid to
# explicitly type nil into the rescue since that's what you want to return,
# or suppressing LoadError for optional dependencies
Lint/SuppressedException:
  Enabled: false

Layout/SpaceInsideBlockBraces:
  # The space here provides no real gain in readability while consuming
  # horizontal space that could be used for a better parameter name.
  # Also {| differentiates better from a hash than { | does.
  SpaceBeforeBlockParameters: false

# No trailing space differentiates better from the block:
# foo} means hash, foo } means block.
Layout/SpaceInsideHashLiteralBraces:
  EnforcedStyle: no_space

# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
Style/BlockDelimiters:
  Enabled: false

# Enforcing -> would be nice, but not at the cost of enforcing lambda { } for
# multiline lambdas.
Style/Lambda:
  Enabled: false

# do / end blocks should be used for side effects,
# methods that run a block for side effects and have
# a useful return value are rare, assign the return
# value to a local variable for those cases.
Style/MethodCalledOnDoEndBlock:
  Enabled: true

# Enforcing the names of variables? To single letter ones? Just no.
Style/SingleLineBlockParams:
  Enabled: false

# Shadowing outer local variables with block parameters is often useful
# to not reinvent a new name for the same thing, it highlights the relation
# between the outer variable and the parameter. The cases where it's actually
# confusing are rare, and usually bad for other reasons already, for example
# because the method is too long.
Lint/ShadowingOuterLocalVariable:
  Enabled: false

# Check with yard instead.
Style/Documentation:
  Enabled: false

# This is just silly. Calling the argument `other` in all cases makes no sense.
Naming/BinaryOperatorParameterName:
  Enabled: false

# Defining constants in tests is fine, and it's good to have them close to the test where they are used.
Lint/ConstantDefinitionInBlock:
  Exclude:
    - "spec/**/*"

# There are valid cases, for example debugging Cucumber steps,
# also they'll fail CI anyway
Lint/Debugger:
  Enabled: false

# We used comparison everywhere.
Style/NumericPredicate:
  EnforcedStyle: comparison

# Reset some HoundCI changes back to Rubocop defaults
Layout/DotPosition:
  EnforcedStyle: leading

# Not enabled by default but good
Style/HashEachMethods:
  Enabled: true

# It makes more sense to allow to structure and group them how it makes sense in the code
Style/AccessorGrouping:
  Enabled: false
