Skip to content

Commit

Permalink
Merge pull request #33 from RadiusNetworks/upgrade-rubocop-1.0
Browse files Browse the repository at this point in the history
Upgrade `rubocop` (1.0 Edition 🎉 )
  • Loading branch information
jnebeker authored Nov 5, 2021
2 parents 4452970 + fdc1e23 commit 049c6aa
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

### Enhancements

- TODO
- Adjust common Rubocop configuration (Aaron Hill, Aaron Kromer, Ben Reynolds, James Nebeker, JC Avena, Sam Kim)
- Enable `Lint/NoReturnInBeginEndBlocks` by default

### Bug Fixes

- TODO


## 0.10.0 (October 18, 2021)

[Full Changelog](https://github.com/RadiusNetworks/radius-spec/compare/v0.9.0...v0.10.0)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/format_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# rubocop:disable Style/FormatString
section "Format String" do |bench|
bench.report("String#%") do
'%10s' % 'hoge' # rubocop:disable Style/FormatStringToken
'%10s' % 'hoge'
end

bench.report("format") do
format '%10s', 'hoge' # rubocop:disable Style/FormatStringToken
format '%10s', 'hoge'
end

bench.report("sprintf") do
sprintf '%10s', 'hoge' # rubocop:disable Style/FormatStringToken
sprintf '%10s', 'hoge'
end
end
# rubocop:enable Style/FormatString
Expand Down
36 changes: 27 additions & 9 deletions common_rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Layout/AccessModifierIndentation:
similar to `rescue` and `ensure` in a method.
EnforcedStyle: outdent

# This cop checks whether the end keyword of begin is aligned properly.
#
# Two modes are supported through the EnforcedStyleAlignWith configuration parameter. If it’s set to
# begin, the end shall be aligned with the begin keyword. We chose this to be consistent with our if
# statement styles, if you want the end to be aligned with the start of the line just put the begin
# on the next line.
#
# Configuration parameters: EnforcedStyleAlignWith
# SupportedStyles: start_of_line, begin
Layout/BeginEndAlignment:
EnforcedStyleAlignWith: begin

# Rubocop 0.60.0 changed how it handled value alignments in this cop. This
# breaks our preference for wanting keys to be aligned, but allowing values to
# either use the `key` or `table` style:
Expand Down Expand Up @@ -194,16 +206,11 @@ Lint/Void:
- 'benchmarks/**/*'

Metrics/AbcSize:
# TODO: When we are able to upgrade to Rubocop 1.5.0 we want to enable the
# following `CountRepeatedAttributes` option. We often find the
# multi-references to the same object to be necessary for reability and that
# for our team it does not increase complexity.
#
# CountRepeatedAttributes: false
CountRepeatedAttributes: false
Max: 17

# Configuration parameters: CountComments, ExcludedMethods, Max.
# ExcludedMethods: refine
# Configuration parameters: CountComments, IgnoredMethods, Max.
# IgnoredMethods: refine
Metrics/BlockLength:
CountAsOne:
- 'array'
Expand All @@ -215,7 +222,7 @@ Metrics/BlockLength:
- 'spec/spec_helper.rb'
- 'spec/**/*_spec.rb'
- 'spec/support/model_factories.rb'
ExcludedMethods:
IgnoredMethods:
- 'chdir'
- 'describe'
- 'refine'
Expand Down Expand Up @@ -557,6 +564,12 @@ Style/MultilineBlockChain:
Style/NumericPredicate:
Enabled: false

# As a general rule, we want to be explicit here instead of requiring readers
# of our code to know what the default arguments to methods like `#join` and
# and `#split` so we disable this cop here.
Style/RedundantArgument:
Enabled: false

# In Ruby every method returns a value. Implicitly this is the value of the
# last line of the method. This means using `return` is often redundant.
# However, there isn't anything inherently wrong about doing so. In fact, in
Expand Down Expand Up @@ -669,6 +682,11 @@ Style/RescueStandardError:
Style/SlicingWithRange:
Enabled: false

# We want to turn this cop on so that rubocop can yell at us instead of Aaron
# yelling at us.
Style/StaticClass:
Enabled: true

# We generally prefer double quotes but many generators use single quotes. We
# don't view the performance difference to be all that much so we don't care
# if the style is mixed or double quotes are used for static strings.
Expand Down
4 changes: 1 addition & 3 deletions lib/radius/spec/model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ module ModelFactory
# factory {Radius::Spec::ModelFactory.catalog}.
class TemplateNotFound < KeyError; end

class << self
# rubocop:disable Style/ClassMethodsDefinitions
class << self # rubocop:disable Style/ClassMethodsDefinitions
# Style Note: We are using this class method style because we need to
# call `alias_method` within this module's singleton class context.
# Ruby did not introduce access to `singleton_class` until 2.7. Once we
Expand Down Expand Up @@ -291,7 +290,6 @@ def template(name)
def templates
@templates ||= {}
end
# rubocop:enable Style/ClassMethodsDefinitions
end

module_function
Expand Down
8 changes: 4 additions & 4 deletions lib/radius/spec/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
config.ignore_localhost = true

record_mode = case
when ENV['CI']
# Never let CI record
:none
when RSpec.configuration.files_to_run.one?
# When developing new features we often run new specs in
# isolation as we write the code. This is the time to allow
# creating the cassettes.
:once
when ENV['CI']
# Never let CI record
:none
else
else # rubocop:disable Lint/DuplicateBranch
# Default to blocking new requests to catch issues
:none
end
Expand Down
2 changes: 1 addition & 1 deletion radius-spec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.5" # rubocop:disable Gemspec/RequiredRubyVersion

spec.add_runtime_dependency "rspec", "~> 3.7"
spec.add_runtime_dependency "rubocop", "~> 0.90.0"
spec.add_runtime_dependency "rubocop", "~> 1.7.0"
spec.add_runtime_dependency "rubocop-rails", "~> 2.9.1"

spec.add_development_dependency "bundler", ">= 2.2.10"
Expand Down
3 changes: 2 additions & 1 deletion spec/support/model_factories.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

TEMP_SPEC_LOAD_CHECK = true

Radius::Spec::ModelFactory.catalog do |catalog|
TEMP_SPEC_LOAD_CHECK = true
catalog.factory "AnyClass", any_arg: :any_value
end

0 comments on commit 049c6aa

Please sign in to comment.