|
|
# Rubocop
|
|
|
|
|
|
**RuboCop** is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide). For in-depth information about Rubocop, access the [gem's repository](https://github.com/bbatsov/rubocop) or the [official documentation](http://rubocop.readthedocs.io/en/latest/).
|
|
|
|
|
|
## Config File
|
|
|
|
|
|
Here at GoCase, we are looking to establish the configuration file to be used in all Ruby on Rails projects. Contributions are welcome.
|
|
|
|
|
|
```yaml
|
|
|
Rails:
|
|
|
Enabled: true
|
|
|
|
|
|
AllCops:
|
|
|
Exclude:
|
|
|
- 'db/**/*'
|
|
|
- 'config/**/*'
|
|
|
- 'bin/**/*'
|
|
|
- 'app/models/ability.rb'
|
|
|
DefaultFormatter: html
|
|
|
|
|
|
# Commonly used screens these days easily fit more than 80 characters.
|
|
|
Metrics/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
|
|
|
|
|
|
# Most readable form.
|
|
|
Style/AlignHash:
|
|
|
EnforcedHashRocketStyle: table
|
|
|
EnforcedColonStyle: table
|
|
|
|
|
|
# Mixing the styles looks just silly.
|
|
|
Style/HashSyntax:
|
|
|
EnforcedStyle: ruby19_no_mixed_keys
|
|
|
|
|
|
# String#% is by far the least verbose and only object oriented variant.
|
|
|
Style/FormatString:
|
|
|
EnforcedStyle: percent
|
|
|
|
|
|
Style/CollectionMethods:
|
|
|
Enabled: true
|
|
|
|
|
|
# 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
|
|
|
Style/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/HandleExceptions:
|
|
|
Enabled: false
|
|
|
|
|
|
# No trailing space differentiates better from the block:
|
|
|
# foo} means hash, foo } means block.
|
|
|
Style/SpaceInsideHashLiteralBraces:
|
|
|
EnforcedStyle: no_space
|
|
|
|
|
|
# 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
|
|
|
|
|
|
# Check with yard instead.
|
|
|
Style/Documentation:
|
|
|
Enabled: false
|
|
|
``` |
|
|
\ No newline at end of file |