Skip to content

Commit

Permalink
Handle legacy `LambdaNode
Browse files Browse the repository at this point in the history
  • Loading branch information
viralpraxis committed Oct 11, 2024
1 parent 3c7acba commit 9d8d81e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/rubocop/cop/thread_safety/class_instance_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ def some_method(params)
RUBY
end

# rubocop:disable RSpec/ExampleLength
it 'registers an offense for assigning an ivar in class_methods within lambda', :with_legacy_lambda_node do
expect_offense(<<~RUBY)
module Test
class_methods do
->() {
def some_method(params)
@params = params
^^^^^^^ #{msg}
end
}
end
end
RUBY
end
# rubocop:enable RSpec/ExampleLength

it 'registers an offense for assigning an ivar in a class singleton method' do
expect_offense(<<~RUBY)
class Test
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'rubocop-thread_safety'
require 'rubocop-ast'

require 'rubocop/rspec/support'
require_relative 'shared_contexts'
Expand All @@ -40,6 +41,15 @@
config.fail_fast = ENV.key? 'RSPEC_FAIL_FAST'
end

config.around :each, :with_legacy_lambda_node do |example|
initial_value = RuboCop::AST::Builder.emit_lambda
RuboCop::AST::Builder.emit_lambda = true

example.call
ensure
RuboCop::AST::Builder.emit_lambda = initial_value
end

config.filter_run_excluding unsupported_on: :prism if ENV['PARSER_ENGINE'] == 'parser_prism'

config.disable_monkey_patching!
Expand Down

0 comments on commit 9d8d81e

Please sign in to comment.