Skip to content

Commit

Permalink
Add rubocop config, upgrade, and autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
gondalez committed Aug 20, 2024
1 parent f6e985d commit dada159
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 61 deletions.
139 changes: 132 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,138 @@
require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 3.1
Exclude:
- 'bin/*'
- 'vendor/bundle/**/*'
NewCops: enable
SuggestExtensions: false

Style/StringLiterals:
Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent
Enabled: true
EnforcedStyle: double_quotes
AutoCorrect: true

Style/StringLiteralsInInterpolation:
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
Enabled: true
EnforcedStyle: double_quotes
AutoCorrect: true

# Indent based on the start of the line, not based on the preceeding line. Reduces line length.
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutmultilinemethodcallindentation
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

# Indent based on the start of the line, not based on the preceeding line. Reduces line length.
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutargumentalignment
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation

# https://docs.rubocop.org/rubocop/cops_layout.html#layoutspaceinsidehashliteralbraces
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

# We have a mix of both and this one seems of limited value.
# variable_1 and variable1 usages.
# https://docs.rubocop.org/rubocop/cops_naming.html#namingvariablenumber
Naming/VariableNumber:
Enabled: false

# When enabled this requires a documentation comment at the top of every class, which feels very anti-rails
Style/Documentation:
Enabled: false

# This is default for rubocop because frozen literals were going to become the default in ruby 3.0 (unless disabled with the comment).
# That did not come to pass however: https://bugs.ruby-lang.org/issues/11473#note-53
# Also it seems even if it did, there is not a huge performance benefit: https://bugs.ruby-lang.org/issues/11473#note-59
Style/FrozenStringLiteralComment:
EnforcedStyle: never
SafeAutoCorrect: true

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

# This makes no sense in the context of RSpec where the whole spec is defined as a block
Metrics/BlockLength:
Exclude:
- 'spec/**/*'

Metrics/MethodLength:
CountAsOne: ['array', 'hash', 'heredoc']

# We have a bunch of code that uses the nested style for definitions, but we only access classes using the fully qualified style in new
# code to make things easier to grep for/tell at a glance which actual class is being used. Going forward it would be nice to fully
# qualify the definitions as well for easier readability/grepability/refactorability
Style/ClassAndModuleChildren:
Enabled: false

# We use this a lot and I could see no explicit benefit to the alternate form: expect { run }.to change(Foo, :bar)
RSpec/ExpectChange:
EnforcedStyle: block

# Enforces that context strings start with when, with, without.
# We have a lot of violations and vcr cassettes dependent on this.
RSpec/ContextWording:
Enabled: false

# Enforces that example/it strings do not start with should or it.
# We have a lot of violations and vcr cassettes dependent on this.
RSpec/ExampleWording:
Enabled: false

# We prefer `describe '#method_name' do` in a unit test style similar to:
# https://www.betterspecs.org/#describe
#
# Because of this we think that using `expect(subject).to eq(123)`:
# - saves an extra mental lookup when compared with having a named subject.
# - reduces friction when renaming and refactoring
#
# The default for RSpec/NamedSubject assumes a more behavioral style like the rspec docs:
# https://rspec.info/features/3-12/rspec-core/example-groups/basic-structure/
#
# Configure this cop to allow nameless subjects but only enforce that if a subject is named, the name must be used in assertions.
# This prevents usages like:
#
# subject(:x) { ... }
# subject(:y) { ... }
# it { is_expected.to eq(123) } # asserts on :y only because it is defined last
#
RSpec/NamedSubject:
EnforcedStyle: named_only

# We prefer `describe '#method_name' do` in a unit test style similar to:
# https://www.betterspecs.org/#describe
#
# The default for RSpec/NestedGroups assumes a more behavioral style like the rspec docs:
# https://rspec.info/features/3-12/rspec-core/example-groups/basic-structure/
#
# Configure this cop so the Max is the 3 to allow `describe '#method_name do` blocks but keeping it flat within them.
#
# Example with nesting levels:
#
# RSpec.describe TheClass do # 1
# describe '#the_method' do # 2
# context 'context A' do # 3
# it 'does things' do
# end
# end
# context 'context B' do # 3
# it 'does things' do
# end
# end
# end
# end
#
RSpec/NestedGroups:
# Note that at time of writing 3 is the default but set explicitly anyways as documentation since it caused us some confusion.
Max: 3

Layout/LineLength:
Max: 120
RSpec/ExampleLength:
CountAsOne: ['array', 'heredoc', 'method_call']
11 changes: 5 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in simplecov-inline.gemspec
gemspec

gem "rake", "~> 13.0"
gem 'rake', '~> 13.0'

gem "rspec", "~> 3.0"
gem 'rspec', '~> 3.0'

gem "rubocop", "~> 1.21"
gem 'rubocop', '~> 1.21'
gem 'rubocop-rspec', require: false
25 changes: 15 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ GEM
diff-lcs (1.5.1)
docile (1.4.0)
json (2.7.2)
parallel (1.24.0)
parser (3.3.4.0)
language_server-protocol (3.17.0.3)
parallel (1.26.3)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
racc (1.8.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.3.2)
rexml (3.3.5)
strscan
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand All @@ -34,18 +35,21 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.50.2)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-ast (1.32.1)
parser (>= 3.3.1.0)
rubocop-rspec (3.0.4)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
Expand All @@ -65,6 +69,7 @@ DEPENDENCIES
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.21)
rubocop-rspec
simplecov-inline!

BUNDLED WITH
Expand Down
8 changes: 3 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"
require 'rubocop/rake_task'

RuboCop::RakeTask.new

Expand Down
4 changes: 1 addition & 3 deletions lib/simplecov/inline.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# frozen_string_literal: true

require_relative "inline/version"
require_relative 'inline/version'

module Simplecov
module Inline
Expand Down
4 changes: 1 addition & 3 deletions lib/simplecov/inline/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

module Simplecov
module Inline
VERSION = "0.1.0"
VERSION = '0.1.0'.freeze
end
end
29 changes: 14 additions & 15 deletions simplecov-inline.gemspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# frozen_string_literal: true

require_relative "lib/simplecov/inline/version"
require_relative 'lib/simplecov/inline/version'

Gem::Specification.new do |spec|
spec.name = "simplecov-inline"
spec.name = 'simplecov-inline'
spec.version = Simplecov::Inline::VERSION
spec.authors = ["tris"]
spec.email = ["[email protected]"]
spec.authors = ['tris']
spec.email = ['[email protected]']

spec.summary = "See missed lines of coverage inline with rspec output."
spec.homepage = "https://github.com/appbot/simplecov-inline"
spec.license = "MIT"
spec.summary = 'See missed lines of coverage inline with rspec output.'
spec.homepage = 'https://github.com/appbot/simplecov-inline'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.1.0'

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/appbot/simplecov-inline"
spec.metadata["changelog_uri"] = "https://github.com/appbot/simplecov-inline/CHANGELOG.md"
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/appbot/simplecov-inline'
spec.metadata['changelog_uri'] = 'https://github.com/appbot/simplecov-inline/CHANGELOG.md'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -24,12 +22,13 @@ Gem::Specification.new do |spec|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "simplecov", "~> 0.22"
spec.add_dependency 'simplecov', '~> 0.22'

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
spec.metadata['rubygems_mfa_required'] = 'true'
end
10 changes: 2 additions & 8 deletions spec/simplecov/inline_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# frozen_string_literal: true

RSpec.describe Simplecov::Inline do
it "has a version number" do
expect(Simplecov::Inline::VERSION).not_to be nil
end

it "does something useful" do
expect(false).to eq(true)
it 'has a version number' do
expect(Simplecov::Inline::VERSION).not_to be_nil
end
end
6 changes: 2 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# frozen_string_literal: true

require "simplecov/inline"
require 'simplecov/inline'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
config.example_status_persistence_file_path = '.rspec_status'

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
Expand Down

0 comments on commit dada159

Please sign in to comment.