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.

Also, rename the `scripts` folder to `script` to follow along with what
is expected by the new style guide (gem).
  • Loading branch information
Paul DobbinSchmaltz committed Nov 21, 2023
1 parent 9a4d7d9 commit 4d322fa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ directories:
enabled: false
UtilityFunction:
enabled: false
"scripts":
"script":
IrresponsibleModule:
enabled: false
UtilityFunction:
Expand Down
246 changes: 2 additions & 244 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,244 +1,2 @@
require:
- rubocop-rake
- rubocop-minitest

AllCops:
NewCops: enable
TargetRubyVersion: 2.7
UseCache: true
DisplayCopNames: true
DisplayStyleGuide: true
ExtraDetails: true

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

Layout/ClassStructure:
Enabled: true
Categories:
module_inclusion:
- extend
- include
- prepend
attributes:
- attr_accessor
- attr_reader
- attr_writer
ExpectedOrder:
- constants
- module_inclusion
- attributes
- public_class_methods
- initializer
- public_methods
- predicates
- protected_methods
- private_methods

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:
- "object_identifier.gemspec"
- "scripts/benchmarking/**/*"
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/OrAssignmentToConstant:
Exclude:
- "scripts/**/*"

Lint/Void:
CheckForMethodsWithNoSideEffects: true

Metrics/BlockLength:
AllowedMethods:
- new
- describe # Tests
- context # Tests
- ips # Benchmarking

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

Metrics/MethodLength:
CountAsOne:
- array
- hash
- 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
Exclude:
- "test/**/*"

Style/CollectionMethods:
Enabled: true
PreferredMethods:
collect: map
collect!: map!
find_all: select
detect: detect
inject: inject

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

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

Style/EmptyMethod:
EnforcedStyle: expanded

Style/ExpandPathArguments:
Exclude:
- "object_identifier.gemspec"

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/NumericPredicate:
AutoCorrect: true

Style/OpenStructUse:
Exclude:
- "test/**/*"

Style/RegexpLiteral:
EnforcedStyle: mixed

Style/RescueStandardError:
EnforcedStyle: implicit

Style/ReturnNil:
Enabled: true

Style/StringMethods:
Enabled: true

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: 12 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ GEM
kwalify (0.7.2)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
mini_portile2 (2.8.5)
minitest (5.20.0)
minitest-reporters (1.6.1)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
much-stub (0.1.10)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
parallel (1.23.0)
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)
Expand Down Expand Up @@ -74,6 +77,9 @@ GEM
parser (>= 3.2.1.0)
rubocop-minitest (0.33.0)
rubocop (>= 1.39, < 2.0)
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
Expand Down Expand Up @@ -105,7 +111,7 @@ GEM
yard (0.9.34)

PLATFORMS
ruby
arm64-darwin-23

DEPENDENCIES
benchmark-ips
Expand All @@ -115,15 +121,13 @@ DEPENDENCIES
minitest-reporters
much-stub
object_identifier!
pdobb-style
pry
pry-byebug
rake
reek
rubocop
rubocop-minitest
rubocop-rake
simplecov
solargraph

BUNDLED WITH
2.4.22
2.4.13
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ Object Identifier works great with the [Object Inspector](https://github.com/pdo

### Benchmarking Formatters

Performance of Formatters can be tested by playing the [Formatters Benchmarking Scripts](https://github.com/pdobb/object_identifier/blob/master/scripts/benchmarking/formatters.rb) in the pry console for this gem.
Performance of Formatters can be tested by playing the [Formatters Benchmarking Scripts](https://github.com/pdobb/object_identifier/blob/master/script/benchmarking/formatters.rb) in the pry console for this gem.

Custom Formatters may be similarly gauged for comparison by adding them to the `custom_formatter_klasses` array before playing the script.

```ruby
custom_formatter_klasses = [MyCustomFormatter]

play scripts/benchmarking/formatters.rb
play script/benchmarking/formatters.rb
# ObjectIdentifier::StringFormatter
# 58.478k (± 0.8%) i/s - 295.776k in 5.058178s
# MyCustomFormatter
Expand Down
4 changes: 1 addition & 3 deletions object_identifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ 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 "pry-byebug"
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-rake"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "solargraph"
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Play from the pry console with:
# play scripts/benchmarking/formatters.rb
# play script/benchmarking/formatters.rb

require "benchmark/ips"

Expand Down

0 comments on commit 4d322fa

Please sign in to comment.