Skip to content

Commit

Permalink
Merge pull request #10 from charitywater/update-cop-for-new-rubocop-v…
Browse files Browse the repository at this point in the history
…ersions

Update cop for new RuboCop versions
  • Loading branch information
flats committed Nov 20, 2018
2 parents 8b98281 + 5bbaf7b commit 603beb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/charity_water/style/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module CharityWater
module Style
VERSION = '2.1.1'.freeze
VERSION = '2.2.0'.freeze
end
end
5 changes: 3 additions & 2 deletions lib/private_attribute_accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ def private_block_attrs(body)
return [] unless body

private_nodes(body).select do |node|
%i(attr_reader attr_writer attr_accessor).include?(node.method_name)
node.send_type? && %i(attr_reader attr_writer attr_accessor).include?(node.method_name)
end
end

def private_nodes(body)
index = body.child_nodes.index { |x| x.method_name == :private }
index = body.child_nodes.index { |x| x.send_type? && x.access_modifier? && x.method_name == :private }
return [] unless index

body.child_nodes[(index + 1)..-1]
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/private_attribute_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ class SmallThing < Thing
'Do not use private attribute accessors'])
end

it 'can handle non-access modifier node types' do
inspect_source cop, <<-RUBY.strip_indent
class AwesomeController < RighteousController
def create
case variable_name
when 'something'
OtherClass::WorkerClass.perform_async argument
when 'something else'
OtherClass::WorkerClass.perform_async argument
end
head :ok
end
end
RUBY

expect(cop.offenses.size).to eq(0)
end

it 'isn\'t offend by using any attr_* methods in public scope' do
inspect_source cop, <<-RUBY.strip_indent
class SmallThing < Thing
Expand Down

0 comments on commit 603beb3

Please sign in to comment.