diff --git a/.rubocop.yml b/.rubocop.yml index 76f7f8c705..fa00f06148 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -239,6 +239,11 @@ Lint/UselessAssignment: Lint/DeprecatedClassMethods: Enabled: true +Style/EvalWithLocation: + Enabled: true + Exclude: + - '**/test/**/*' + Style/ParenthesesAroundCondition: Enabled: true diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb index aa205a3d3c..fa13cf31c1 100644 --- a/actionview/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb @@ -102,7 +102,7 @@ def atom_feed(options = {}, &block) options[:schema_date] = "2005" # The Atom spec copyright date end - xml = options.delete(:xml) || eval("xml", block.binding) + xml = options.delete(:xml) || block.binding.local_variable_get(:xml) xml.instruct! if options[:instruct] options[:instruct].each do |target, attrs| diff --git a/activerecord/lib/active_record/association_relation.rb b/activerecord/lib/active_record/association_relation.rb index 7bcefe71ad..3f71fa8345 100644 --- a/activerecord/lib/active_record/association_relation.rb +++ b/activerecord/lib/active_record/association_relation.rb @@ -16,7 +16,7 @@ def ==(other) end %w(insert insert_all insert! insert_all! upsert upsert_all).each do |method| - class_eval <<~RUBY + class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{method}(attributes, **kwargs) if @association.reflection.through_reflection? raise ArgumentError, "Bulk insert or upsert is currently not supported for has_many through association" diff --git a/activesupport/lib/active_support/testing/stream.rb b/activesupport/lib/active_support/testing/stream.rb index 55017d3535..0b8e0298a0 100644 --- a/activesupport/lib/active_support/testing/stream.rb +++ b/activesupport/lib/active_support/testing/stream.rb @@ -23,7 +23,7 @@ def quietly(&block) def capture(stream) stream = stream.to_s captured_stream = Tempfile.new(stream) - stream_io = eval("$#{stream}") + stream_io = eval("$#{stream}", binding, __FILE__, __LINE__) origin_stream = stream_io.dup stream_io.reopen(captured_stream) diff --git a/railties/lib/rails/generators/migration.rb b/railties/lib/rails/generators/migration.rb index fce42207b2..1dfaa56c5e 100644 --- a/railties/lib/rails/generators/migration.rb +++ b/railties/lib/rails/generators/migration.rb @@ -57,13 +57,12 @@ def migration_template(source, destination, config = {}) source = File.expand_path(find_in_source_paths(source.to_s)) set_migration_assigns!(destination) - context = instance_eval("binding") dir, base = File.split(destination) numbered_destination = File.join(dir, ["%migration_number%", base].join("_")) file = create_migration numbered_destination, nil, config do - ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context) + ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(binding) end Rails::Generators.add_generated_file(file) end