From 89f314c2baf3406334aa91dcde28537917e7d8d6 Mon Sep 17 00:00:00 2001 From: Paul DobbinSchmaltz Date: Mon, 20 Nov 2023 23:00:47 -0600 Subject: [PATCH] Update RuboCop config to source from pdobb-style gem 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. --- .rubocop.yml | 197 +---------------------------------- Gemfile.lock | 20 ++-- lib/say/progress/interval.rb | 2 +- lib/say/say.rb | 4 +- say.gemspec | 5 +- 5 files changed, 17 insertions(+), 211 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e500518..a0f24d1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 3de0ea9..bcb8915 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/lib/say/progress/interval.rb b/lib/say/progress/interval.rb index e989378..7f788a3 100644 --- a/lib/say/progress/interval.rb +++ b/lib/say/progress/interval.rb @@ -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 diff --git a/lib/say/say.rb b/lib/say/say.rb index 741ff5d..d6330ec 100644 --- a/lib/say/say.rb +++ b/lib/say/say.rb @@ -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 diff --git a/say.gemspec b/say.gemspec index 8c6a2e4..0ff7f1e 100644 --- a/say.gemspec +++ b/say.gemspec @@ -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"