From 9d8d81e6449c9d0d868124a191f2d9b800dce5c8 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Fri, 11 Oct 2024 18:50:52 +0300 Subject: [PATCH] Handle legacy `LambdaNode --- .../class_instance_variable_spec.rb | 17 +++++++++++++++++ spec/spec_helper.rb | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/spec/rubocop/cop/thread_safety/class_instance_variable_spec.rb b/spec/rubocop/cop/thread_safety/class_instance_variable_spec.rb index 7476ec4..96d0db0 100644 --- a/spec/rubocop/cop/thread_safety/class_instance_variable_spec.rb +++ b/spec/rubocop/cop/thread_safety/class_instance_variable_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f662..0586e81 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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' @@ -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!