From b68591bb7da53257544c5d18a0467b92c9ddc0d5 Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Mon, 19 Jul 2021 21:53:32 -0400 Subject: [PATCH 1/7] Update Rubocop to latest version [#177398947] --- cw-style.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cw-style.gemspec b/cw-style.gemspec index 5c69584..03eaf80 100644 --- a/cw-style.gemspec +++ b/cw-style.gemspec @@ -28,8 +28,8 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "rubocop", "~> 0.89.1" spec.add_dependency "rubocop-rspec-focused", "= 0.0.3" + spec.add_dependency "rubocop", "~> 1.18.3" spec.add_dependency "rubocop-thread_safety" spec.add_dependency "rubocop-rails" spec.add_development_dependency "bundler", "~> 2.2.4" From 66618da7cfc19376d55e249b0a94afd91a317528 Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Mon, 19 Jul 2021 21:53:52 -0400 Subject: [PATCH 2/7] Replace rspec-focused w/ more general library That covers all things Rspec, including lingering `focus`es. [#177398947] --- cw-style.gemspec | 2 +- default.yml | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cw-style.gemspec b/cw-style.gemspec index 03eaf80..d47e55d 100644 --- a/cw-style.gemspec +++ b/cw-style.gemspec @@ -28,10 +28,10 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "rubocop-rspec-focused", "= 0.0.3" spec.add_dependency "rubocop", "~> 1.18.3" spec.add_dependency "rubocop-thread_safety" spec.add_dependency "rubocop-rails" + spec.add_dependency "rubocop-rspec" spec.add_development_dependency "bundler", "~> 2.2.4" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec" diff --git a/default.yml b/default.yml index 2abb1b8..b400ef0 100644 --- a/default.yml +++ b/default.yml @@ -1,7 +1,7 @@ require: - - rubocop/rspec/focused - rubocop-thread_safety - rubocop-rails + - rubocop-rspec - ./lib/unless_with_multiple_conditions - ./lib/private_attribute_accessors - ./lib/update_not_update_attributes @@ -92,9 +92,6 @@ Rails/Output: Rails/TimeZone: EnforcedStyle: 'flexible' -RSpec/Focused: - Enabled: true - Style/Documentation: Enabled: false @@ -194,3 +191,9 @@ Style/TrailingCommaInHashLiteral: Style/IfUnlessModifier: Enabled: false + +RSpec: + Enabled: false + +RSpec/Focus: + Enabled: true From f8b125fe98936019a92601aa6481ee130be1dae3 Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Mon, 19 Jul 2021 21:54:32 -0400 Subject: [PATCH 3/7] Bump version [#177398947] --- lib/charity_water/style/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/charity_water/style/version.rb b/lib/charity_water/style/version.rb index df8eb4c..37793fd 100644 --- a/lib/charity_water/style/version.rb +++ b/lib/charity_water/style/version.rb @@ -1,5 +1,5 @@ module CharityWater module Style - VERSION = '4.0.4'.freeze + VERSION = '4.1'.freeze end end From 31d1a17888986f2a880ccf989850dd15cddfd404 Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Wed, 21 Jul 2021 15:44:16 -0400 Subject: [PATCH 4/7] Disable not very useful rule We _mostly_ use snakecase for variables with numbers, but not always, and I don't think it's worth the effort to standardize that. [#177398947] --- default.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/default.yml b/default.yml index b400ef0..27b9626 100644 --- a/default.yml +++ b/default.yml @@ -192,6 +192,9 @@ Style/TrailingCommaInHashLiteral: Style/IfUnlessModifier: Enabled: false +Naming/VariableNumber: + Enabled: false + RSpec: Enabled: false From 8258ecc35793338f8c7dc67bf9a0ceb9fa9403fa Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Wed, 21 Jul 2021 15:45:35 -0400 Subject: [PATCH 5/7] Disable cop that conflicts w/ Prettier Prettier undoes what autocorrecting this cop does. [#177398947] --- default.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/default.yml b/default.yml index 27b9626..1cf96b0 100644 --- a/default.yml +++ b/default.yml @@ -147,6 +147,9 @@ Layout/HashAlignment: Layout/HeredocIndentation: Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false + Layout/MultilineMethodCallIndentation: Enabled: false From 9aead1c8fd275455a3fc6590c18f7868b71eaf54 Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Wed, 21 Jul 2021 15:50:33 -0400 Subject: [PATCH 6/7] Disable cop that we do not need We are purposeful about our use of symbols with and without quoted strings and I don't think we need this. [#177398947] --- default.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/default.yml b/default.yml index 1cf96b0..a6da8c8 100644 --- a/default.yml +++ b/default.yml @@ -37,6 +37,9 @@ Lint/RaiseException: Lint/StructNewOverride: Enabled: true +Lint/SymbolConversion: + Enabled: false + Style/ExponentialNotation: Enabled: true From 49a74da35c988165a81a58860479cd24ad2e0ba9 Mon Sep 17 00:00:00 2001 From: David Flaherty Date: Wed, 21 Jul 2021 16:12:50 -0400 Subject: [PATCH 7/7] Replace custom cop w/ built-in one Per PR feedback. [#177398947] --- default.yml | 5 +- lib/unless_with_multiple_conditions.rb | 29 ---------- spec/unless_with_multiple_conditions_spec.rb | 61 -------------------- 3 files changed, 4 insertions(+), 91 deletions(-) delete mode 100644 lib/unless_with_multiple_conditions.rb delete mode 100644 spec/unless_with_multiple_conditions_spec.rb diff --git a/default.yml b/default.yml index a6da8c8..ce6b325 100644 --- a/default.yml +++ b/default.yml @@ -2,7 +2,6 @@ require: - rubocop-thread_safety - rubocop-rails - rubocop-rspec - - ./lib/unless_with_multiple_conditions - ./lib/private_attribute_accessors - ./lib/update_not_update_attributes @@ -55,6 +54,10 @@ Style/HashTransformValues: Style/SlicingWithRange: Enabled: true +Style/UnlessLogicalOperators: + Enabled: true + EnforcedStyle: forbid_logical_operators + Metrics/AbcSize: Enabled: false diff --git a/lib/unless_with_multiple_conditions.rb b/lib/unless_with_multiple_conditions.rb deleted file mode 100644 index c5c5ada..0000000 --- a/lib/unless_with_multiple_conditions.rb +++ /dev/null @@ -1,29 +0,0 @@ -module RuboCop - module Cop - module Style - class UnlessWithMultipleConditions < ::RuboCop::Cop::Cop - MSG = 'Do not use `unless` with multiple conditions because it is error prone & difficult to debug.'.freeze - - def on_if(node) - @node = node - return unless unless_with_multiple_conditions? - add_offense(node) - end - - private - - def unless_with_multiple_conditions? - unless? && contains_multiple_conditions? - end - - def unless? - @node.loc.respond_to?(:keyword) && @node.loc.keyword.is?('unless') - end - - def contains_multiple_conditions? - @node.child_nodes.first.and_type? || @node.child_nodes.first.or_type? - end - end - end - end -end diff --git a/spec/unless_with_multiple_conditions_spec.rb b/spec/unless_with_multiple_conditions_spec.rb deleted file mode 100644 index 245c7a4..0000000 --- a/spec/unless_with_multiple_conditions_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require './lib/unless_with_multiple_conditions' - -describe RuboCop::Cop::Style::UnlessWithMultipleConditions do - # These helper methods are from https://github.com/bbatsov/rubocop/blob/4b26354497f32da8d771f35c66b2f47224f9674b/spec/support/cop_helper.rb#L10 - def inspect_source(cop, source, file = nil) - if source.is_a?(Array) && source.size == 1 - fail "Don't use an array for a single line of code: #{source}" - end - RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {} - processed_source = parse_source(source, file) - fail 'Error parsing example code' unless processed_source.valid_syntax? - _investigate(cop, processed_source) - end - - def parse_source(source, file = nil) - source = source.join($RS) if source.is_a?(Array) - - if file&.respond_to?(:write) - file.write(source) - file.rewind - file = file.path - end - - RuboCop::ProcessedSource.new(source, 2.6, file) - end - - def _investigate(cop, processed_source) - team = RuboCop::Cop::Team.new([cop], nil, raise_error: true) - report = team.investigate(processed_source) - @last_corrector = report.correctors.first || RuboCop::Cop::Corrector.new(processed_source) - report.offenses - end - - it "isn't offended by single conditions, if statements with multiple conditions" do - [ - ['if(:foo)', 'end'], - ['unless(:foo)', 'end'], - ['if(:foo || :bar)', 'end'], - ['if(:foo && :bar)', 'end'], - ].each do |source| - cop = described_class.new - inspect_source(cop, source) - expect(cop.offenses.size).to eq(0) - end - end - - it 'is offended by unless statements with multiple conditions' do - [ - ['unless :foo && :bar', 'end'], - ['unless :foo and :bar', 'end'], - ['unless :foo || :bar', 'end'], - ['unless :foo or :bar', 'end'], - ].each do |source| - cop = described_class.new - inspect_source(cop, source) - expect(cop.offenses.size).to eq(1) - end - end -end