Skip to content

Commit

Permalink
Add support for :void_context as regexp argument to Warning.ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Feb 15, 2021
1 parent 22444e0 commit e11846b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Add support for :void_context as regexp argument to Warning.ignore (jeremyevans)

* Support :category keyword to Warning.warn on Ruby 3.0 (jeremyevans)

* Fix :taint warning handling on Ruby 3.0 (jeremyevans)
Expand Down
1 change: 1 addition & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ appropriate regexp. The supported symbols are:
* :taint
* :unused_var
* :useless_operator
* :void_context

<tt>Warning.process</tt> takes an optional path prefix and a block, and if the
warning string starts with the path prefix, it calls the block with the warning
Expand Down
3 changes: 3 additions & 0 deletions lib/warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Processor
safe: /: warning: (?:rb_safe_level_2_warning|rb_safe_level|rb_set_safe_level_force|rb_set_safe_level|rb_secure|rb_insecure_operation|rb_check_safe_obj|\$SAFE) will (?:be removed|become a normal global variable) in Ruby 3\.0\n\z/,
taint: /: warning: (?:rb_error_untrusted|rb_check_trusted|Pathname#taint|Pathname#untaint|rb_env_path_tainted|Object#tainted\?|Object#taint|Object#untaint|Object#untrusted\?|Object#untrust|Object#trust|rb_obj_infect|rb_tainted_str_new|rb_tainted_str_new_cstr) is deprecated and will be removed in Ruby 3\.2\.?\n\z/,
mismatched_indentations: /: warning: mismatched indentations at '.+' with '.+' at \d+\n\z/,
void_context: /possibly useless use of :: in void context/,
}

# Map of action symbols to procs that return the symbol
Expand Down Expand Up @@ -75,6 +76,8 @@ def freeze
# :unused_var :: Ignore warnings for unused variables.
# :useless_operator :: Ignore warnings when using operators such as == and > when the
# result is not used.
# :void_context :: Ignore warnings for :: to reference constants when the result is not
# used (often used to trigger autoload).
#
# Examples:
#
Expand Down
12 changes: 12 additions & 0 deletions test/test_warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ def test_warning_ignore_bignum
end
end

def test_warning_ignore_void_context
assert_warning(/warning: possibly useless use of :: in void context/) do
instance_eval('::Object; nil', __FILE__, __LINE__)
end

Warning.ignore(:void_context, __FILE__)

assert_warning '' do
instance_eval('::Object; nil', __FILE__, __LINE__)
end
end

def test_warning_ignore_ambiguous_slash
def self.d(re); end
assert_warning(/warning: ambi/) do
Expand Down

0 comments on commit e11846b

Please sign in to comment.