Skip to content

Commit

Permalink
Update RuboCop config to source from pdobb-style gem
Browse files Browse the repository at this point in the history
The new pdobb-style gem is an attempt to commonize my style guide across
all of my gems and/or future projects.

After updating to the new common base I had to fix a few issues in the
existing code as well, coming from inclusion of the rubocop-performance
gem that's now being included as well.
  • Loading branch information
Paul DobbinSchmaltz committed Nov 21, 2023
1 parent 8bcaf83 commit 89f314c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 211 deletions.
197 changes: 2 additions & 195 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,195 +1,2 @@
require:
- rubocop-rake
- rubocop-minitest

AllCops:
NewCops: enable
TargetRubyVersion: 2.7
UseCache: true
DisplayCopNames: true
DisplayStyleGuide: true
ExtraDetails: true
Exclude:
# Rubocop Defaults
- "node_modules/**/*"
- "tmp/**/*"
- "vendor/**/*"
- ".git/**/*"
# Custom additions
- "script/**/*"

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec # See: https://bundler.io/guides/creating_gem.html#testing-our-gem

Layout/DotPosition:
EnforcedStyle: trailing

Layout/EmptyLineAfterGuardClause:
Enabled: true

Layout/EndOfLine:
EnforcedStyle: lf

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent_relative_to_receiver

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/FirstParameterIndentation:
Enabled: false # Revisit if more settings become available.

Layout/LineContinuationSpacing:
EnforcedStyle: no_space

Layout/LineEndStringConcatenationIndentation:
EnforcedStyle: aligned

Layout/LineLength:
Max: 80
Exclude:
- "say.gemspec"
AllowedPatterns:
# YARD doc `@example` output.
- !ruby/regexp /\A *# \# => /
- !ruby/regexp /\A *# =/

Layout/MultilineAssignmentLayout:
Enabled: true
SupportedTypes:
- block
- case
- class
- if
# - kwbegin
- module

Layout/MultilineMethodCallBraceLayout:
EnforcedStyle: same_line

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented_relative_to_receiver

Layout/MultilineMethodDefinitionBraceLayout:
EnforcedStyle: same_line

Layout/MultilineOperationIndentation:
Enabled: false # Waiting for e.g. `indented_relative_to_receiver`.

# Lint/AmbiguousOperator:
# Enabled: false # Conflicts with other rules.

# Lint/AmbiguousRegexpLiteral:
# Enabled: false # Conflicts with other rules.

Lint/Void:
CheckForMethodsWithNoSideEffects: true

Metrics/BlockLength:
AllowedMethods:
- describe
- context

Metrics/ClassLength:
CountAsOne:
- array
- heredoc
- method_call
Exclude:
- "test/**/*"

Metrics/ModuleLength:
CountAsOne:
- array
- heredoc
- method_call

Naming/MethodParameterName:
AllowedNames:
- a
- b

Naming/RescuedExceptionsVariableName:
PreferredName: ex

Style/Alias:
EnforcedStyle: prefer_alias_method

Style/BlockDelimiters:
EnforcedStyle: semantic
AllowBracesOnProceduralOneLiners: true
FunctionalMethods:
# Minitest Spec DSL. (Rubocop defaults.)
- let
- let!
- subject
- watch
# Overrides (Defaulted to Procedural by Rubocop.)
- tap
# MuchStub
- call
- on_call
- spy
# - tap (Already listed above.)
- tap_on_call
- with
ProceduralMethods: # Defining this just to remove `tap` from the list.
- benchmark
- bm
- bmbm
- create
- each_with_object
- measure
- new
- realtime
# - tap (Remove from Rubocop defaults.)
- with_object

Style/ClassAndModuleChildren:
AutoCorrect: true
EnforcedStyle: compact

Style/Documentation:
Exclude:
- "test/**/*"
- "script/**/*"

Style/EmptyElse:
Enabled: false # Including a comment in an empty else block shows intent.

Style/EmptyMethod:
EnforcedStyle: expanded

Style/FormatString:
Enabled: false # % notation with an Array just reads better sometimes.

Style/Lambda:
EnforcedStyle: literal

Style/LambdaCall:
Enabled: false # Allow ServiceObject.(*). Only use on classes, not instances.

Style/RegexpLiteral:
EnforcedStyle: mixed

Style/RescueStandardError:
EnforcedStyle: implicit

Style/SingleLineMethods:
Exclude:
- "test/**/*_test.rb"

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
inherit_gem:
pdobb-style: .rubocop.yml
20 changes: 11 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GEM
reline (>= 0.3.1)
docile (1.4.0)
io-console (0.6.0)
irb (1.8.3)
irb (1.9.0)
rdoc
reline (>= 0.3.8)
json (2.6.3)
Expand All @@ -34,22 +34,27 @@ GEM
parser (3.2.2.4)
ast (~> 2.4.1)
racc
pdobb-style (0.1.3)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rake
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.1.1.1)
stringio
racc (1.7.1)
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
rdoc (6.5.0)
rdoc (6.6.0)
psych (>= 4.0.0)
reek (6.1.4)
kwalify (~> 0.7.0)
parser (~> 3.2.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.8.2)
reline (0.3.9)
reline (0.4.0)
io-console (~> 0.5)
rexml (3.2.6)
rubocop (1.57.2)
Expand Down Expand Up @@ -79,7 +84,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
stringio (3.0.8)
stringio (3.0.9)
timecop (0.9.8)
unicode-display_width (2.5.0)
yard (0.9.34)
Expand All @@ -95,13 +100,10 @@ DEPENDENCIES
minitest
minitest-reporters
much-stub
pdobb-style
pry
rake
reek
rubocop
rubocop-minitest
rubocop-performance
rubocop-rake
say!
simplecov
timecop
Expand Down
2 changes: 1 addition & 1 deletion lib/say/progress/interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def say(text = nil, type = nil, index: self.index, &block)
Say.progress_line(text, type, index: index)
end
elsif block
block.call
yield
else
# Nothing to do.
end
Expand Down
4 changes: 2 additions & 2 deletions lib/say/say.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def self.with_block(header: nil, footer: DONE_MESSAGE, justify: :left, &block)
result
end

def self.benchmark_block_run(message, &block)
def self.benchmark_block_run(message)
result = nil
time = Benchmark.measure { result = block.call }
time = Benchmark.measure { result = yield }
time_string = "%.4fs" % time.real
[result, "#{message} (#{time_string})"]
end
Expand Down
5 changes: 1 addition & 4 deletions say.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest"
spec.add_development_dependency "minitest-reporters"
spec.add_development_dependency "much-stub"
spec.add_development_dependency "pdobb-style"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake"
spec.add_development_dependency "reek"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "rubocop-minitest"
spec.add_development_dependency "rubocop-performance"
spec.add_development_dependency "rubocop-rake"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "timecop"
spec.add_development_dependency "yard"
Expand Down

0 comments on commit 89f314c

Please sign in to comment.