Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore internal warnings for bundler 2.4.6 and above #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/ruby_warning_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# <internal:/home/user/.rbenv/rubies/ruby-3.1.5/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:37:
# warning: <internal:/home/user/.rbenv/rubies/ruby-3.1.5/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>: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?('<internal:') && gem_path.start_with?(path) }
end

# Variables used in tag attributes (Slim) always cause a warning.
# TODO: Report this.
def ignored_template_warning?(line)
Expand All @@ -81,6 +97,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
29 changes: 26 additions & 3 deletions test/ruby_warnings_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand All @@ -87,4 +93,21 @@ def test_template_warning
@err.string
assert_equal 1, @err.ruby_warnings
end

def test_internal_warning
# in gem
@err.write "<internal:/path/to/ruby/2.2.0/rubygems/core_ext/kernel_require.rb>: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 "<internal:/path/to/ruby/2.2.0/rubygems/core_ext/kernel_require.rb>:319: warning: loading in progress, circular require considered harmful - /path/to/app.rb\n"

@err.write "something other\n"

assert_equal \
"<internal:/path/to/ruby/2.2.0/rubygems/core_ext/kernel_require.rb>: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