Skip to content

Commit

Permalink
Rubocop: Cap method length at 50 lines + disable module length
Browse files Browse the repository at this point in the history
Remi pointed out in #666 that we basically just have to keep adding more
more onto the `Max` exception for both these rules every time we add a
new API resource.

Here I suggest that we modify the check on method length in two ways:

1. Permanently disable the cop on `Util.object_classes`. This is just
   going to keep growing until we change are approach to it.
2. Choose a more reasonable maximum of 50 lines for elsewhere (IMO, the
   default of 10 is just too short). Most of our methods already come in
   below this, but there's a couple outliers like `#execute_request` in
   `StripeClient`. If we knock over some of those, we could lower this
   number again, but I suspect that we'd probably want somewhere closer
   to 30 (instead of 10) event then.

I also disable the check on module length completely. I'm not convinced
this is a very good heuristic for code quality.
  • Loading branch information
brandur committed Jul 28, 2018
1 parent 4e3f38e commit ebbce66
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Layout/IndentArray:
Layout/IndentHash:
EnforcedStyle: consistent

Metrics/MethodLength:
# There's ~2 long methods in `StripeClient`. If we want to truncate those a
# little, we could move this to be closer to ~30 (but the default of 10 is
# probably too short).
Max: 50

Metrics/ModuleLength:
Enabled: false

Style/FrozenStringLiteralComment:
EnforcedStyle: always

Expand Down
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ Metrics/CyclomaticComplexity:
Metrics/LineLength:
Max: 310

# Offense count: 32
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 55

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 315

# Offense count: 6
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.objects_to_ids(h)
end
end

def self.object_classes
def self.object_classes # rubocop:disable Metrics/MethodLength
@object_classes ||= {
# data structures
ListObject::OBJECT_NAME => ListObject,
Expand Down

0 comments on commit ebbce66

Please sign in to comment.