Skip to content

Commit

Permalink
style(rubocop): update rubocop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Feb 10, 2024
1 parent e142d0d commit 6d4dea7
Showing 1 changed file with 152 additions and 15 deletions.
167 changes: 152 additions & 15 deletions .rubocop.yml
@@ -1,37 +1,174 @@
inherit_from:
- https://dev.k.io/rubocop/rubocop.rails.yml
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Exclude:
- "bin/*"
- "db/schema.rb"
# Fixes missing gem exception when running Rubocop on GitHub Actions.
- "vendor/bundle/**/*"

# Always use double quotes
Style/StringLiterals:
EnforcedStyle: double_quotes

Style/WordArray:
# We prefer arrays of symbols to look like an array of symbols.
# For example: [:one, :two, :three] as opposed to %i[one two three]
Style/SymbolArray:
EnforcedStyle: brackets

Layout/LineLength:
# We want to reduce this back down to 120 but there are a fair number of offences
# of this which need addressing individually and carefully.
Max: 200
# There should always be empty lines inside a class. For example
#
# class MyExample
#
# def some_method
# end
#
# end
Layout/EmptyLinesAroundClassBody:
EnforcedStyle: empty_lines

Metrics/AbcSize:
# We want to keep attr_* definitions separated on their own lines, rather than
# all of them collapsed into a single attr_* call. The collapsed/grouped variant
# is harder to read, and harder to see what's been changed in diffs.
Style/AccessorGrouping:
Enabled: false

Metrics/BlockLength:
# Blocks are slightly different to classes, in these cases there should
# not be new lines around the contents of the block.
#
# proc do
# # Do something
# end
Layout/EmptyLinesAroundBlockBody:
EnforcedStyle: no_empty_lines

# Modules are the same as classes unless they're being used for namespacing
# purposes in which case there should not be new lines.
Layout/EmptyLinesAroundModuleBody:
EnforcedStyle: empty_lines_except_namespace

# Space is required following -> when writing a lambda:
#
# somethign = -> (var) { block }
Layout/SpaceInLambdaLiteral:
EnforcedStyle: require_space

Layout/FirstHashElementIndentation:
Enabled: false

Metrics/ClassLength:
# We don't mind setting assignments in conditions so this has been disabled to
# allow `if something = something_else` without worrying about brackets.
Lint/AssignmentInCondition:
Enabled: false

Metrics/CyclomaticComplexity:
# Top level documentation is quite rare...
Style/Documentation:
Enabled: false

Metrics/MethodLength:
# We want to allow inner slashes in a regexp to be used when using /xxx/ form.
Style/RegexpLiteral:
AllowInnerSlashes: true

# Blocks of if statements are perfectly fine and usually more readable than
# putting everything onto a single line just because we can.
Style/IfUnlessModifier:
Enabled: false

Metrics/ModuleLength:
# We prefer assignments to happen within the condition rather than setting a
# variable to the result of a condition.
Style/ConditionalAssignment:
EnforcedStyle: assign_inside_condition
IncludeTernaryExpressions: false

# Empty methods should not be compacted onto a single line
Style/EmptyMethod:
EnforcedStyle: expanded

# We do not wish to auto correct unused method arguments because that can be a
# pain. These should just be flagged for manual intervention.
Lint/UnusedMethodArgument:
AutoCorrect: false

# As above, just flag them.
Lint/UnusedBlockArgument:
AutoCorrect: false

# While we don't want to make heavy use of get_ or set_ methods we do often need
# to use these when we want to refer to actually getting or setting something
# (usually from another API).
Naming/AccessorMethodName:
Enabled: false

# If we want a boolean called :true, we should be allowed that. These are likely
# not mistakes.
Lint/BooleanSymbol:
Enabled: false

Metrics/PerceivedComplexity:
# Using block.map(&:upcase) is not always the neatest way to show something. For
# example if you have a block that just calls one thing, you don't want it
# collapsed.
#
# action do |user|
# user.delete
# end
#
# This should be action(&:delete) because it is not clear what is actually
# happening without the context of knowing what the inner variable should be
# called.
Style/SymbolProc:
Enabled: false

Lint/MissingSuper:
# Excluding specs from block lengths
Metrics/BlockLength:
Exclude:
- "spec/**/*.rb"
- "db/schema.rb"
- "db/migrate/**/*.rb"
- "lib/tasks/auto_annotate_models.rake"
- "config/routes.rb"
- "lib/tasks/*.rake"
- "app/apis/core_api/base.rb"

Metrics/ModuleLength:
Exclude:
- "spec/factories/**/*.rb"
- "spec/**/*_spec.rb"
- "spec/support/**/*.rb"
- "spec/specs/support/**/*.rb"
- "db/schema.rb"
- "db/migrate/**/*.rb"
- "lib/tasks/auto_annotate_models.rake"
- "config/routes.rb"

# Slightly increase tyhe default method length to be a bit more forgiving
Metrics/MethodLength:
Max: 30

# Allow a maxmium of 5 arguments and don't include keyword arguments
Metrics/ParameterLists:
Max: 5
CountKeywordArgs: false

# This cop checks for chaining of a block after another block that spans multiple lines.
Style/MultilineBlockChain:
Exclude:
- "spec/**/*.rb"

# Increase class lengths to a more reasonable place
Metrics/ClassLength:
Max: 250

Metrics/AbcSize:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: true
SafeAutoCorrect: true

Naming/PredicateName:
Enabled: false

Layout/LineLength:
# We want to reduce this back down to 120 but there are a fair number of offences
# of this which need addressing individually and carefully.
Max: 200

0 comments on commit 6d4dea7

Please sign in to comment.