diff --git a/cw-style.gemspec b/cw-style.gemspec index 5c69584..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", "~> 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_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..ce6b325 100644 --- a/default.yml +++ b/default.yml @@ -1,8 +1,7 @@ require: - - rubocop/rspec/focused - rubocop-thread_safety - rubocop-rails - - ./lib/unless_with_multiple_conditions + - rubocop-rspec - ./lib/private_attribute_accessors - ./lib/update_not_update_attributes @@ -37,6 +36,9 @@ Lint/RaiseException: Lint/StructNewOverride: Enabled: true +Lint/SymbolConversion: + Enabled: false + Style/ExponentialNotation: Enabled: true @@ -52,6 +54,10 @@ Style/HashTransformValues: Style/SlicingWithRange: Enabled: true +Style/UnlessLogicalOperators: + Enabled: true + EnforcedStyle: forbid_logical_operators + Metrics/AbcSize: Enabled: false @@ -92,9 +98,6 @@ Rails/Output: Rails/TimeZone: EnforcedStyle: 'flexible' -RSpec/Focused: - Enabled: true - Style/Documentation: Enabled: false @@ -150,6 +153,9 @@ Layout/HashAlignment: Layout/HeredocIndentation: Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false + Layout/MultilineMethodCallIndentation: Enabled: false @@ -194,3 +200,12 @@ Style/TrailingCommaInHashLiteral: Style/IfUnlessModifier: Enabled: false + +Naming/VariableNumber: + Enabled: false + +RSpec: + Enabled: false + +RSpec/Focus: + Enabled: true 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 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