warning 0.10.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '08cf870b5689f1fc79b3a2c1c9bd787c10802ed0'
4
- data.tar.gz: 43f33015143cf420dd92f3db2ad0c5b91f05335d
2
+ SHA256:
3
+ metadata.gz: 0fd71447749bdaad9176ecb3eb6302104bcaf5401516719beed80594d2fa234a
4
+ data.tar.gz: 18eee8db50ef702428bcfd5690c3f92d013b4b8013dd6cd28e554ff808cccbd6
5
5
  SHA512:
6
- metadata.gz: 2f35fc384e25902773a66ec191ccdf522a762a3c6006d339b66ce4b16c11e1e67df9454d12be4a941c2ad0458b978707b1fc98bfde052c0918c48304d9bea30e
7
- data.tar.gz: 6cd8864633508b1bcf4928d4d25c4d8e19763a48f58b1160eb9f03aa3a178413f4b42270bb92b9bf7f7d8941de2c5f02c53f05463ea5f003ab0eff769f535bea
6
+ metadata.gz: 8038062c8d96ec8eb800be734041654d3dd24a1a5ddda523c5c44f465f7cbdf3fdbaa3537e4d360ad9673effb4a54e27de544325235b0fe343ec13f6ee3ec948
7
+ data.tar.gz: 26324dfc9591fda0a4627d515c3b18738e55f3213c0ff76b15f7493616980c54cf3cf3b945985d460d230db69b57ccd687f2b4ac5f367feec1b1efeae72319f0
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ === 1.0.0 (2020-01-21)
2
+
3
+ * Add support for :taint as regexp argument to Warning.ignore (jeremyevans)
4
+
5
+ * Add support for :safe as regexp argument to Warning.ignore (jeremyevans)
6
+
7
+ * Add Warning.dedup for deduplicating warnings (jeremyevans)
8
+
9
+ * Add support for :keyword_separation as regexp argument to Warning.ignore (jeremyevans)
10
+
1
11
  === 0.10.1 (2017-11-16)
2
12
 
3
13
  * Correctly handle Warning.freeze (jeremyevans)
@@ -2,8 +2,8 @@
2
2
 
3
3
  ruby-warning adds custom processing for warnings, including the
4
4
  ability to ignore specific warning messages, ignore warnings
5
- in specific files/directories, and add custom handling for all
6
- warnings in specific files/directories.
5
+ in specific files/directories, deduplicate warnings, and add
6
+ custom handling for all warnings in specific files/directories.
7
7
 
8
8
  ruby-warning requires ruby 2.4+, as previous versions of ruby do
9
9
  not support custom processing of warnings.
@@ -30,11 +30,14 @@ appropriate regexp. The supported symbols are:
30
30
  * :ambiguous_slash
31
31
  * :bignum
32
32
  * :fixnum
33
+ * :keyword_separation
33
34
  * :method_redefined
34
35
  * :missing_gvar
35
36
  * :missing_ivar
36
37
  * :not_reached
38
+ * :safe
37
39
  * :shadow
40
+ * :taint
38
41
  * :unused_var
39
42
  * :useless_operator
40
43
 
@@ -44,15 +47,27 @@ string instead of performing the default behavior. You can call
44
47
  <tt>Warning.process</tt> multiple times and it will operate intelligently,
45
48
  choosing the longest path prefix that the string starts with.
46
49
 
47
- <tt>Warning.clear</tt> just clears the current ignored warnings and warning
48
- processors.
50
+ <tt>Warning.dedup</tt> deduplicates warnings, so that if a warning is received
51
+ that is the same as a warning that has already been processed, the warning is
52
+ ignored. Note that this should be used with care, since if the application
53
+ generates an arbitrary number of unique warnings, that can lead to unbounded
54
+ memory growth.
55
+
56
+ <tt>Warning.clear</tt> resets the library to its initial state, clearing the
57
+ current ignored warnings and warning processors, and turning off deduplication.
49
58
 
50
59
  By using path prefixes, it's fairly easy for a gem to set that specific warnings
51
60
  should be ignored inside the gem's directory.
52
61
 
53
62
  Note that path prefixes will not correctly handle warnings raised by
54
63
  <tt>Kernel#warn</tt>, unless the warning message given to <tt>Kernel#warn</tt>
55
- starts with the filename where the warning is used.
64
+ starts with the filename where the warning is used. The <tt>Kernel#warn</tt>
65
+ +:uplevel+ option will make sure the warning starts with the filename.
66
+
67
+ Note that many of the warnings this library can ignore are warnings caused
68
+ during compilation (i.e. when files are loaded via require). You should
69
+ require this library and setup the appropriate warning handling before
70
+ loading any code that could cause warnings.
56
71
 
57
72
  = Examples
58
73
 
@@ -78,6 +93,14 @@ starts with the filename where the warning is used.
78
93
  LOGGER.error(warning)
79
94
  end
80
95
 
96
+ # Deduplicate warnings
97
+ Warning.dedup
98
+
99
+ # Ignore all warnings in Gem dependencies
100
+ Gem.path.each do |path|
101
+ Warning.ignore(//, path)
102
+ end
103
+
81
104
  = License
82
105
 
83
106
  MIT
@@ -15,16 +15,28 @@ module Warning
15
15
  shadow: /: warning: shadowing outer local variable - \w+\n\z/,
16
16
  unused_var: /: warning: assigned but unused variable - \w+\n\z/,
17
17
  useless_operator: /: warning: possibly useless use of [><!=]+ in void context\n\z/,
18
+ keyword_separation: /: warning: (?:Using the last argument (?:for `.+' )?as keyword parameters is deprecated; maybe \*\* should be added to the call|Passing the keyword argument (?:for `.+' )?as the last hash parameter is deprecated|Splitting the last argument (?:for `.+' )?into positional and keyword parameters is deprecated|The called method (?:`.+' )?is defined here)\n\z/,
19
+ 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/,
20
+ 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/,
18
21
  }
19
22
 
20
- # Clear all current ignored warnings and warning processors.
23
+ # Clear all current ignored warnings, warning processors, and duplicate check cache.
24
+ # Also disables deduplicating warnings if that is currently enabled.
21
25
  def clear
22
26
  synchronize do
23
27
  @ignore.clear
24
28
  @process.clear
29
+ @dedup = false
25
30
  end
26
31
  end
27
32
 
33
+ # Deduplicate warnings, supress warning messages if the same warning message
34
+ # has already occurred. Note that this can lead to unbounded memory use
35
+ # if unique warnings are generated.
36
+ def dedup
37
+ @dedup = {}
38
+ end
39
+
28
40
  def freeze
29
41
  @ignore.freeze
30
42
  @process.freeze
@@ -40,6 +52,7 @@ module Warning
40
52
  # :ambiguous_slash :: Ignore warnings for things like <tt>method /regexp/</tt>
41
53
  # :bignum :: Ignore warnings when referencing the ::Bignum constant.
42
54
  # :fixnum :: Ignore warnings when referencing the ::Fixnum constant.
55
+ # :keyword_separation :: Ignore warnings related to keyword argument separation.
43
56
  # :method_redefined :: Ignore warnings when defining a method in a class/module where a
44
57
  # method of the same name was already defined in that class/module.
45
58
  # :missing_gvar :: Ignore warnings for accesses to global variables
@@ -47,7 +60,9 @@ module Warning
47
60
  # :missing_ivar :: Ignore warnings for accesses to instance variables
48
61
  # that have not yet been initialized
49
62
  # :not_reached :: Ignore statement not reached warnings.
63
+ # :safe :: Ignore warnings related to $SAFE and related C-API functions.
50
64
  # :shadow :: Ignore warnings related to shadowing outer local variables.
65
+ # :taint :: Ignore warnings related to taint and related methods and C-API functions.
51
66
  # :unused_var :: Ignore warnings for unused variables.
52
67
  # :useless_operator :: Ignore warnings when using operators such as == and > when the
53
68
  # result is not used.
@@ -105,7 +120,8 @@ module Warning
105
120
  end
106
121
 
107
122
  # Handle ignored warnings and warning processors. If the warning is
108
- # not ignored and there is no warning processor setup for the warning
123
+ # not ignored, is not a duplicate warning (if checking for duplicates)
124
+ # and there is no warning processor setup for the warning
109
125
  # string, then use the default behavior of writing to $stderr.
110
126
  def warn(str)
111
127
  synchronize{@ignore.dup}.each do |path, regexp|
@@ -114,6 +130,14 @@ module Warning
114
130
  end
115
131
  end
116
132
 
133
+ if @dedup
134
+ if synchronize{@dedup[str]}
135
+ return
136
+ end
137
+
138
+ synchronize{@dedup[str] = true}
139
+ end
140
+
117
141
  synchronize{@process.dup}.each do |path, block|
118
142
  if str.start_with?(path)
119
143
  block.call(str)
@@ -133,6 +157,7 @@ module Warning
133
157
 
134
158
  @ignore = []
135
159
  @process = []
160
+ @dedup = false
136
161
  @monitor = Monitor.new
137
162
 
138
163
  extend Processor
@@ -1,4 +1,5 @@
1
- require 'minitest/autorun'
1
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
2
+ require 'minitest/global_expectations/autorun'
2
3
  require 'warning'
3
4
 
4
5
  class WarningFreezeTest < Minitest::Test
@@ -1,5 +1,7 @@
1
- require 'minitest/autorun'
1
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
2
+ require 'minitest/global_expectations/autorun'
2
3
  require 'warning'
4
+ require 'pathname'
3
5
 
4
6
  class WarningTest < Minitest::Test
5
7
  module EnvUtil
@@ -42,6 +44,28 @@ class WarningTest < Minitest::Test
42
44
  Warning.clear
43
45
  end
44
46
 
47
+ def ivar
48
+ Object.new.instance_variable_get(:@ivar)
49
+ end
50
+
51
+ def test_warning_dedup
52
+ assert_warning(/instance variable @ivar not initialized/) do
53
+ ivar
54
+ end
55
+ assert_warning(/instance variable @ivar not initialized/) do
56
+ ivar
57
+ end
58
+
59
+ Warning.dedup
60
+
61
+ assert_warning(/instance variable @ivar not initialized/) do
62
+ ivar
63
+ end
64
+ assert_warning('') do
65
+ ivar
66
+ end
67
+ end
68
+
45
69
  def test_warning_ignore
46
70
  obj = Object.new
47
71
 
@@ -219,6 +243,98 @@ class WarningTest < Minitest::Test
219
243
  assert_warning '' do
220
244
  instance_eval('lambda{|a| lambda{|a|}}', __FILE__)
221
245
  end
246
+ end if RUBY_VERSION < '2.6'
247
+
248
+ if RUBY_VERSION > '2.7' && RUBY_VERSION < '2.8'
249
+ def h2kw(**kw)
250
+ end
251
+ def kw2h(h, **kw)
252
+ end
253
+ def skw(h=1, a: 1)
254
+ end
255
+
256
+ def test_warning_ignore_keyword
257
+ assert_warning(/warning: Using the last argument as keyword parameters is deprecated; maybe \*\* should be added to the call.*The called method `h2kw' is defined here/m) do
258
+ h2kw({})
259
+ end
260
+ assert_warning(/warning: Passing the keyword argument as the last hash parameter is deprecated.*The called method `kw2h' is defined here/m) do
261
+ kw2h(a: 1)
262
+ end
263
+ assert_warning(/warning: Splitting the last argument into positional and keyword parameters is deprecated.*The called method `skw' is defined here/m) do
264
+ skw("b" => 1, a: 2)
265
+ end
266
+ assert_warning(/warning: Splitting the last argument into positional and keyword parameters is deprecated.*The called method `skw' is defined here/m) do
267
+ skw({"b" => 1, a: 2})
268
+ end
269
+
270
+ Warning.ignore(:keyword_separation, __FILE__)
271
+
272
+ assert_warning '' do
273
+ h2kw({})
274
+ kw2h(a: 1)
275
+ skw("b" => 1, a: 2)
276
+ skw({"b" => 1, a: 2})
277
+ end
278
+ end
279
+
280
+ def test_warning_ignore_safe
281
+ assert_warning(/\$SAFE will become a normal global variable in Ruby 3\.0/) do
282
+ $SAFE = 0
283
+ end
284
+
285
+ Warning.ignore(:safe, __FILE__)
286
+
287
+ assert_warning("") do
288
+ $SAFE = 0
289
+ end
290
+ end
291
+ end
292
+
293
+ if RUBY_VERSION > '2.7' && RUBY_VERSION < '3.2'
294
+
295
+ def test_warning_ignore_taint
296
+ o = Object.new
297
+
298
+ assert_warning(/Object#taint is deprecated and will be removed in Ruby 3\.2/) do
299
+ o.taint
300
+ end
301
+ assert_warning(/Object#untaint is deprecated and will be removed in Ruby 3\.2/) do
302
+ o.untaint
303
+ end
304
+ assert_warning(/Object#tainted\? is deprecated and will be removed in Ruby 3\.2/) do
305
+ o.tainted?
306
+ end
307
+ assert_warning(/Object#trust is deprecated and will be removed in Ruby 3\.2/) do
308
+ o.trust
309
+ end
310
+ assert_warning(/Object#untrust is deprecated and will be removed in Ruby 3\.2/) do
311
+ o.untrust
312
+ end
313
+ assert_warning(/Object#untrusted\? is deprecated and will be removed in Ruby 3\.2/) do
314
+ o.untrusted?
315
+ end
316
+
317
+ path = Pathname.new(__FILE__)
318
+ assert_warning(/Pathname#taint is deprecated and will be removed in Ruby 3\.2/) do
319
+ path.taint
320
+ end
321
+ assert_warning(/Pathname#untaint is deprecated and will be removed in Ruby 3\.2/) do
322
+ path.untaint
323
+ end
324
+
325
+ Warning.ignore(:taint, __FILE__)
326
+
327
+ assert_warning("") do
328
+ o.taint
329
+ o.untaint
330
+ o.tainted?
331
+ o.trust
332
+ o.untrust
333
+ o.untrusted?
334
+ p.taint
335
+ p.untaint
336
+ end
337
+ end
222
338
  end
223
339
 
224
340
  def test_warning_ignore_symbol_array
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest-global_expectations
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: |
14
28
  ruby-warning adds custom processing for warnings, including the
15
29
  ability to ignore specific warning messages, ignore warnings
@@ -33,7 +47,11 @@ files:
33
47
  homepage: https://github.com/jeremyevans/ruby-warning
34
48
  licenses:
35
49
  - MIT
36
- metadata: {}
50
+ metadata:
51
+ bug_tracker_uri: https://github.com/jeremyevans/ruby-warning/issues
52
+ changelog_uri: https://github.com/jeremyevans/ruby-warning/blob/master/CHANGELOG
53
+ documentation_uri: https://github.com/jeremyevans/ruby-warning/blob/master/README.rdoc
54
+ source_code_uri: https://github.com/jeremyevans/ruby-warning
37
55
  post_install_message:
38
56
  rdoc_options:
39
57
  - "--quiet"
@@ -47,17 +65,16 @@ require_paths:
47
65
  - lib
48
66
  required_ruby_version: !ruby/object:Gem::Requirement
49
67
  requirements:
50
- - - ">"
68
+ - - ">="
51
69
  - !ruby/object:Gem::Version
52
- version: 2.3.99
70
+ version: 2.4.0
53
71
  required_rubygems_version: !ruby/object:Gem::Requirement
54
72
  requirements:
55
73
  - - ">="
56
74
  - !ruby/object:Gem::Version
57
75
  version: '0'
58
76
  requirements: []
59
- rubyforge_project:
60
- rubygems_version: 2.6.13
77
+ rubygems_version: 3.1.2
61
78
  signing_key:
62
79
  specification_version: 4
63
80
  summary: Add custom processing for warnings