.rubocop.yml 5.27 KB
Newer Older
Benjamin Neff's avatar
Benjamin Neff committed
1 2
require: rubocop-rails

Jonne Haß's avatar
Jonne Haß committed
3
AllCops:
4
  TargetRubyVersion: 2.3
5
  Exclude:
Benjamin Neff's avatar
Benjamin Neff committed
6 7
    - "bin/**/*"
    - "db/schema.rb"
Jonne Haß's avatar
Jonne Haß committed
8
    - "config/locales/cldr/plurals.rb"
Jonne Haß's avatar
Jonne Haß committed
9

10 11 12 13
# Disable for rails 4
Rails/HttpPositionalArguments:
  Enabled: false

Jonne Haß's avatar
Jonne Haß committed
14
# Commonly used screens these days easily fit more than 80 characters.
15
Layout/LineLength:
Jonne Haß's avatar
Jonne Haß committed
16 17 18 19
  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
20
Metrics/MethodLength:
Jonne Haß's avatar
Jonne Haß committed
21 22 23 24 25
  Max: 20

# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength:
  Max: 1500
Benjamin Neff's avatar
Benjamin Neff committed
26 27
Metrics/ModuleLength:
  Max: 1500
28 29

# Raise complexity metrics
30 31
Metrics/AbcSize:
  Max: 20
Jonne Haß's avatar
Jonne Haß committed
32

33 34 35 36 37 38
Metrics/CyclomaticComplexity:
  Max: 20

Metrics/PerceivedComplexity:
  Max: 20

Benjamin Neff's avatar
Benjamin Neff committed
39 40 41 42 43 44 45 46 47
# Some blocks are longer.
Metrics/BlockLength:
  ExcludedMethods:
    - "namespace"
    - "create_table"
  Exclude:
    - "config/**/*.rb"
    - "spec/**/*.rb"

Jonne Haß's avatar
Jonne Haß committed
48 49
# No space makes the method definition shorter and differentiates
# from a regular assignment.
Benjamin Neff's avatar
Benjamin Neff committed
50
Layout/SpaceAroundEqualsInParameterDefault:
Jonne Haß's avatar
Jonne Haß committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64
  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

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

# Most readable form.
65
Layout/HashAlignment:
Jonne Haß's avatar
Jonne Haß committed
66 67 68 69
  EnforcedHashRocketStyle: table
  EnforcedColonStyle: table

# Mixing the styles looks just silly.
Jonne Haß's avatar
Jonne Haß committed
70 71
Style/HashSyntax:
 EnforcedStyle: ruby19_no_mixed_keys
Jonne Haß's avatar
Jonne Haß committed
72 73

# has_key? and has_value? are far more readable than key? and value?
Benjamin Neff's avatar
Benjamin Neff committed
74
Style/PreferredHashMethods:
Jonne Haß's avatar
Jonne Haß committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  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.
95
# So both variants make sense.
Jonne Haß's avatar
Jonne Haß committed
96 97 98
Style/RaiseArgs:
  Enabled: false

99 100
# Indenting the chained dots beneath each other is not supported by this cop,
# see https://github.com/bbatsov/rubocop/issues/1633
Benjamin Neff's avatar
Benjamin Neff committed
101
Layout/MultilineOperationIndentation:
102 103
  Enabled: false

Jonne Haß's avatar
Jonne Haß committed
104 105 106 107 108 109 110 111 112
# 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
113
Lint/SuppressedException:
Jonne Haß's avatar
Jonne Haß committed
114 115
  Enabled: false

Benjamin Neff's avatar
Benjamin Neff committed
116
Layout/SpaceInsideBlockBraces:
Jonne Haß's avatar
Jonne Haß committed
117 118 119 120 121 122 123
  # 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.
Benjamin Neff's avatar
Benjamin Neff committed
124
Layout/SpaceInsideHashLiteralBraces:
Jonne Haß's avatar
Jonne Haß committed
125 126 127 128
  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
Jonne Haß's avatar
Jonne Haß committed
129
Style/BlockDelimiters:
Jonne Haß's avatar
Jonne Haß committed
130 131
  Enabled: false

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

Jonne Haß's avatar
Jonne Haß committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
# 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:
158
  Enabled: false
Jonne Haß's avatar
Jonne Haß committed
159 160

# This is just silly. Calling the argument `other` in all cases makes no sense.
Benjamin Neff's avatar
Benjamin Neff committed
161
Naming/BinaryOperatorParameterName:
162
  Enabled: false
Jonne Haß's avatar
Jonne Haß committed
163 164 165 166 167 168

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

Benjamin Neff's avatar
Benjamin Neff committed
169 170 171
# We used comparison everywhere.
Style/NumericPredicate:
  EnforcedStyle: comparison
172 173

# Reset some HoundCI changes back to Rubocop defaults
Benjamin Neff's avatar
Benjamin Neff committed
174
Layout/DotPosition:
175
  EnforcedStyle: leading
176 177 178 179 180 181 182 183 184 185

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

# TODO: Enable with Ruby 2.5
Style/HashTransformKeys:
  Enabled: false
Style/HashTransformValues:
  Enabled: false