From e95f878b3e154e64c8974aff1c78f3d18f25e41f Mon Sep 17 00:00:00 2001 From: Artem Dordovskyi Date: Fri, 17 May 2024 10:06:11 +0300 Subject: [PATCH 1/3] Add eval method redefined warning --- lib/ruby_warning_filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby_warning_filter.rb b/lib/ruby_warning_filter.rb index 08e0d0f..d16170e 100644 --- a/lib/ruby_warning_filter.rb +++ b/lib/ruby_warning_filter.rb @@ -81,6 +81,6 @@ def backtrace?(line) end def eval_redefined?(line) - line =~ /\(eval\):\d+: warning: previous definition of .+ was here/ + line =~ /\(eval\):\d+: (warning: previous definition of .+ was here|warning: method redefined; .+)/ end end From 9f4573af5d1c25dc7e5de89056ce60995568fc9a Mon Sep 17 00:00:00 2001 From: Artem Dordovskyi Date: Fri, 17 May 2024 11:07:57 +0300 Subject: [PATCH 2/3] Update tests according to new warning message --- test/ruby_warnings_filter_test.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/ruby_warnings_filter_test.rb b/test/ruby_warnings_filter_test.rb index 943d720..aca8554 100644 --- a/test/ruby_warnings_filter_test.rb +++ b/test/ruby_warnings_filter_test.rb @@ -5,7 +5,7 @@ require "stringio" STDOUT.sync = true -class RubyWarningsFilterTest < MiniTest::Test +class RubyWarningsFilterTest < Minitest::Test def setup @gems_dir = File.expand_path("../gems", __FILE__) @gems_link_dir = File.expand_path("../gems-link", __FILE__) @@ -62,19 +62,25 @@ def test_method_redefined_eval @err.write "/path/to/ruby/2.2.0/gems/compass-core-1.0.3/lib/gradient_support.rb:319: warning: method redefined; discarding old to_moz\n" @err.write "(eval):2: warning: previous definition of to_moz was here\n" + @err.write "/path/to/ruby/2.2.0/gems/sitemap_generator-6.3.0/lib/sitemap_generator/templates.rb:10: warning: method redefined; discarding old sitemap_sample\n" + @err.write "(eval):1: warning: method redefined; discarding old sitemap_sample\n" + # in app @err.write "/path/to/app.rb:123: warning: method redefined; discarding old foo\n" @err.write "(eval):2: warning: previous definition of foo was here\n" + @err.write "(eval):1: warning: method redefined; discarding old sitemap_sample\n" + @err.write "something other\n" assert_equal \ "/path/to/app.rb:123: warning: method redefined; discarding old foo\n"\ "(eval):2: warning: previous definition of foo was here\n"\ + "(eval):1: warning: method redefined; discarding old sitemap_sample\n"\ "something other\n", @err.string - - assert_equal 2, @err.ruby_warnings + + assert_equal 3, @err.ruby_warnings end def test_template_warning From c172519e936064ca898ac155f23b5d63e0caa035 Mon Sep 17 00:00:00 2001 From: Artem Dordovskyi Date: Fri, 17 May 2024 11:44:41 +0300 Subject: [PATCH 3/3] Ignore internal warnings with circular require for bundle 2.4.6 and above --- lib/ruby_warning_filter.rb | 18 +++++++++++++++++- test/ruby_warnings_filter_test.rb | 21 +++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/ruby_warning_filter.rb b/lib/ruby_warning_filter.rb index 08e0d0f..c1fffe2 100644 --- a/lib/ruby_warning_filter.rb +++ b/lib/ruby_warning_filter.rb @@ -63,13 +63,29 @@ def ruby_warning?(line) end def ignored_warning?(line) - external_warning?(line) || ignored_template_warning?(line) + external_warning?(line) || + ignored_template_warning?(line) || + internal_warning?(line) end def external_warning?(line) @ignore_path.any?{ |path| line.start_with?(path) } end + # Since bundler 2.4.6 there are some changes + # before: + # /home/user/.rbenv/gems/ruby-3.1.5/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32 + # warning: /home/user/.rbenv/gems/ruby-3.1.5/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32: + # warning: loading in progress, circular require considered harmful - /home/user/.rbenv/gems/ruby-3.1.5/gems/bugsnag-6.26.3/lib/bugsnag.rb + # after: + # :37: + # warning: :37: + # warning: loading in progress, circular require considered harmful - /home/user/.rbenv/gems/ruby-3.1.5/gems/bugsnag-6.26.3/lib/bugsnag.rb + def internal_warning?(line) + gem_path = line.split(/\n/).first.split(' ').last + @ignore_path.any?{ |path| line.start_with?(':319: warning: loading in progress, circular require considered harmful - /path/to/ruby/2.2.0/gems/bugsnag-6.26.3/lib/bugsnag.rb\n" + + # in app + @err.write ":319: warning: loading in progress, circular require considered harmful - /path/to/app.rb\n" + + @err.write "something other\n" + + assert_equal \ + ":319: warning: loading in progress, circular require considered harmful - /path/to/app.rb\n"\ + "something other\n", + @err.string + + assert_equal 1, @err.ruby_warnings + end end