warning 0.9.0 → 0.10.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
2
  SHA1:
3
- metadata.gz: 70b1655bff238b444c9373002b6d1010812a9a71
4
- data.tar.gz: 2276292182d974e7fdb71802295ed1dc45771f82
3
+ metadata.gz: c0a00f58401bfb0c3b182b5e472de7d417e5e9c7
4
+ data.tar.gz: 6e4a3377be9ee85d5de9848e4eaaa20b367035a4
5
5
  SHA512:
6
- metadata.gz: 6a512057f73e7f275e806a9e9442919e128c0edcf312e730b4787f9b9630c8f088bdfce0af7a7b7f9d6e3811aa94ae95211a4b13d205353e1853c20f2f5a0a4d
7
- data.tar.gz: 16e8d3da29e75c5c6f1dd70fede11564006ad30201923d8750aa0d383e77820fa4355c6fd6f6b44600bd276d9afd38706581c123c34898bbbf2534bb64cab5b3
6
+ metadata.gz: 1e3c7971f5ec2a5b28ec263aa6847778f45790b3554cdfee4fc8b4c08af21e3459dcf148fd8618b4d632cbd285e6afd6518ededc69a01469ea676666df564a5c
7
+ data.tar.gz: 674820530875fa42a1920f06673add77b66210fee9b50bd150cbafdce603e275c30c422cf985838e6f5500096aeb815c40d2a5d7cb5766b430a7912bf7f2238b
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ === 0.10.0 (2016-11-16)
2
+
3
+ * Add support for :arg_prefix and :shadow as regexp argument to Warning.ignore (jeremyevans)
4
+
5
+ * Add support for :useless_operator as regexp argument to Warning.ignore (jeremyevans)
6
+
7
+ * Add support for :missing_gvar as regexp argument to Warning.ignore (jeremyevans)
8
+
9
+ * Add support for :ambiguous_slash and :unused_var as regexp arguments to Warning.ignore (jeremyevans)
10
+
11
+ * Add support for :fixnum and :bignum as regexp arguments to Warning.ignore (jeremyevans)
12
+
13
+ * Add support for array of symbols as regexp argument to Warning.ignore (jeremyevans)
14
+
15
+ * Add support for :not_reached as regexp argument to Warning.ignore (jeremyevans)
16
+
17
+ * Add support for :missing_ivar and :method_redefined as regexp argument to Warning.ignore (jeremyevans)
18
+
1
19
  === 0.9.0 (2016-08-09)
2
20
 
3
21
  * Initial Public Release
data/README.rdoc CHANGED
@@ -23,7 +23,20 @@ warnings, it just adds methods that allow you to customize the processing.
23
23
 
24
24
  <tt>Warning.ignore</tt> takes a regexp and optionally a path prefix, and ignores
25
25
  any warning that matches the regular expression if it starts with the path
26
- prefix.
26
+ prefix. It can also take a symbol or an array of symbols, and will use an
27
+ appropriate regexp. The supported symbols are:
28
+
29
+ * :arg_prefix
30
+ * :ambiguous_slash
31
+ * :bignum
32
+ * :fixnum
33
+ * :method_redefined
34
+ * :missing_gvar
35
+ * :missing_ivar
36
+ * :not_reached
37
+ * :shadow
38
+ * :unused_var
39
+ * :useless_operator
27
40
 
28
41
  <tt>Warning.process</tt> takes an optional path prefix and a block, and if the
29
42
  warning string starts with the path prefix, it calls the block with the warning
@@ -49,6 +62,12 @@ starts with the filename where the warning is used.
49
62
  # Ignore all uninitialized instance variable warnings in current file
50
63
  Warning.ignore(/instance variable @\w+ not initialized/, __FILE__)
51
64
 
65
+ # Ignore all uninitialized instance variable warnings in current file
66
+ Warning.ignore(:missing_ivar, __FILE__)
67
+
68
+ # Ignore all Fixnum and Bignum warnings in current file
69
+ Warning.ignore([:fixnum, :bignum], __FILE__)
70
+
52
71
  # Write warning to LOGGER at level warning
53
72
  Warning.process do |warning|
54
73
  LOGGER.warning(warning)
data/lib/warning.rb CHANGED
@@ -2,6 +2,21 @@ require 'monitor'
2
2
 
3
3
  module Warning
4
4
  module Processor
5
+ # Map of symbols to regexps for warning messages to ignore.
6
+ IGNORE_MAP = {
7
+ ambiguous_slash: /: warning: ambiguous first argument; put parentheses or a space even after `\/' operator\n\z/,
8
+ arg_prefix: /: warning: `[&\*]' interpreted as argument prefix\n\z/,
9
+ bignum: /: warning: constant ::Bignum is deprecated\n\z/,
10
+ fixnum: /: warning: constant ::Fixnum is deprecated\n\z/,
11
+ method_redefined: /: warning: method redefined; discarding old .+\n\z|: warning: previous definition of .+ was here\n\z/,
12
+ missing_gvar: /: warning: global variable `\$.+' not initialized\n\z/,
13
+ missing_ivar: /: warning: instance variable @.+ not initialized\n\z/,
14
+ not_reached: /: warning: statement not reached\n\z/,
15
+ shadow: /: warning: shadowing outer local variable - \w+\n\z/,
16
+ unused_var: /: warning: assigned but unused variable - \w+\n\z/,
17
+ useless_operator: /: warning: possibly useless use of [><!=]+ in void context\n\z/,
18
+ }
19
+
5
20
  # Clear all current ignored warnings and warning processors.
6
21
  def clear
7
22
  synchronize do
@@ -11,14 +26,51 @@ module Warning
11
26
  end
12
27
 
13
28
  # Ignore any warning messages matching the given regexp, if they
14
- # start with the given path. Examples:
29
+ # start with the given path.
30
+ # The regexp can also be one of the following symbols (or an array including them), which will
31
+ # use an appropriate regexp for the given warning:
32
+ #
33
+ # :arg_prefix :: Ignore warnings when using * or & as an argument prefix
34
+ # :ambiguous_slash :: Ignore warnings for things like <tt>method /regexp/</tt>
35
+ # :bignum :: Ignore warnings when referencing the ::Bignum constant.
36
+ # :fixnum :: Ignore warnings when referencing the ::Fixnum constant.
37
+ # :method_redefined :: Ignore warnings when defining a method in a class/module where a
38
+ # method of the same name was already defined in that class/module.
39
+ # :missing_gvar :: Ignore warnings for accesses to global variables
40
+ # that have not yet been initialized
41
+ # :missing_ivar :: Ignore warnings for accesses to instance variables
42
+ # that have not yet been initialized
43
+ # :not_reached :: Ignore statement not reached warnings.
44
+ # :shadow :: Ignore warnings related to shadowing outer local variables.
45
+ # :unused_var :: Ignore warnings for unused variables.
46
+ # :useless_operator :: Ignore warnings when using operators such as == and > when the
47
+ # result is not used.
48
+ #
49
+ # Examples:
15
50
  #
16
51
  # # Ignore all uninitialized instance variable warnings
17
52
  # Warning.ignore(/instance variable @\w+ not initialized/)
18
53
  #
19
54
  # # Ignore all uninitialized instance variable warnings in current file
20
55
  # Warning.ignore(/instance variable @\w+ not initialized/, __FILE__)
56
+ #
57
+ # # Ignore all uninitialized instance variable warnings in current file
58
+ # Warning.ignore(:missing_ivar, __FILE__)
59
+ #
60
+ # # Ignore all uninitialized instance variable and method redefined warnings in current file
61
+ # Warning.ignore([:missing_ivar, :method_redefined], __FILE__)
21
62
  def ignore(regexp, path='')
63
+ case regexp
64
+ when Regexp
65
+ # already regexp
66
+ when Symbol
67
+ regexp = IGNORE_MAP.fetch(regexp)
68
+ when Array
69
+ regexp = Regexp.union(regexp.map{|re| IGNORE_MAP.fetch(re)})
70
+ else
71
+ raise TypeError, "first argument to Warning.ignore should be Regexp, Symbol, or Array of Symbols, got #{regexp.inspect}"
72
+ end
73
+
22
74
  synchronize do
23
75
  @ignore << [path, regexp]
24
76
  end
data/test/test_warning.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'minitest/unit'
2
1
  require 'minitest/autorun'
2
+ require 'warning'
3
3
 
4
4
  class WarningTest < Minitest::Test
5
5
  module EnvUtil
@@ -38,16 +38,18 @@ class WarningTest < Minitest::Test
38
38
  assert(pat === stderr, msg)
39
39
  end
40
40
 
41
+ def teardown
42
+ Warning.clear
43
+ end
44
+
41
45
  def test_warning_ignore
42
46
  obj = Object.new
43
47
 
44
- assert_warning /instance variable @ivar not initialized/ do
48
+ assert_warning(/instance variable @ivar not initialized/) do
45
49
  assert_nil(obj.instance_variable_get(:@ivar))
46
50
  end
47
51
 
48
- require 'warning'
49
-
50
- assert_warning /instance variable @ivar not initialized/ do
52
+ assert_warning(/instance variable @ivar not initialized/) do
51
53
  assert_nil(obj.instance_variable_get(:@ivar))
52
54
  end
53
55
 
@@ -57,7 +59,7 @@ class WarningTest < Minitest::Test
57
59
  assert_nil(obj.instance_variable_get(:@ivar))
58
60
  end
59
61
 
60
- assert_warning /instance variable @ivar2 not initialized/ do
62
+ assert_warning(/instance variable @ivar2 not initialized/) do
61
63
  assert_nil(obj.instance_variable_get(:@ivar2))
62
64
  end
63
65
 
@@ -67,36 +69,181 @@ class WarningTest < Minitest::Test
67
69
  assert_nil(obj.instance_variable_get(:@ivar2))
68
70
  end
69
71
 
70
- assert_warning /instance variable @ivar3 not initialized/ do
72
+ assert_warning(/instance variable @ivar3 not initialized/) do
71
73
  assert_nil(obj.instance_variable_get(:@ivar3))
72
74
  end
73
75
 
74
76
  Warning.ignore(/instance variable @ivar3 not initialized/, __FILE__+'a')
75
77
 
76
- assert_warning /instance variable @ivar3 not initialized/ do
78
+ assert_warning(/instance variable @ivar3 not initialized/) do
77
79
  assert_nil(obj.instance_variable_get(:@ivar3))
78
80
  end
81
+ end
79
82
 
83
+ def test_warning_ignore_missing_ivar
80
84
  Warning.clear
81
85
 
82
- assert_warning /instance variable @ivar not initialized/ do
83
- assert_nil(obj.instance_variable_get(:@ivar))
86
+ assert_warning(/instance variable @ivar not initialized/) do
87
+ assert_nil(instance_variable_get(:@ivar))
88
+ end
89
+
90
+ Warning.ignore(:missing_ivar, __FILE__)
91
+
92
+ assert_warning '' do
93
+ assert_nil(instance_variable_get(:@ivar))
94
+ end
95
+ end
96
+
97
+ def test_warning_ignore_missing_gvar
98
+ assert_warning(/global variable `\$gvar' not initialized/) do
99
+ $gvar
100
+ end
101
+
102
+ Warning.ignore(:missing_gvar, __FILE__)
103
+
104
+ assert_warning '' do
105
+ $gvar
106
+ end
107
+ end
108
+
109
+ def test_warning_ignore_method_redefined
110
+ def self.a; end
111
+
112
+ assert_warning(/method redefined; discarding old a.+previous definition of a was here/m) do
113
+ def self.a; end
114
+ end
115
+
116
+ Warning.ignore(:method_redefined, __FILE__)
117
+
118
+ assert_warning '' do
119
+ def self.a; end
120
+ end
121
+ end
122
+
123
+ def test_warning_ignore_not_reached
124
+ assert_warning(/: warning: statement not reached/) do
125
+ instance_eval('def self.b; return; 1 end', __FILE__)
126
+ end
127
+
128
+ Warning.ignore(:not_reached, __FILE__)
129
+
130
+ assert_warning '' do
131
+ instance_eval('def self.c; return; 1 end', __FILE__)
132
+ end
133
+ end
134
+
135
+ def test_warning_ignore_fixnum
136
+ assert_warning(/warning: constant ::Fixnum is deprecated/) do
137
+ ::Fixnum
138
+ end
139
+
140
+ Warning.ignore(:fixnum, __FILE__)
141
+
142
+ assert_warning '' do
143
+ ::Fixnum
144
+ end
145
+ end
146
+
147
+ def test_warning_ignore_bignum
148
+ assert_warning(/warning: constant ::Bignum is deprecated/) do
149
+ ::Bignum
150
+ end
151
+
152
+ Warning.ignore(:bignum, __FILE__)
153
+
154
+ assert_warning '' do
155
+ ::Bignum
156
+ end
157
+ end
158
+
159
+ def test_warning_ignore_ambiguous_slash
160
+ def self.d(re); end
161
+ assert_warning(/warning: ambiguous first argument; put parentheses or a space even after `\/' operator/) do
162
+ instance_eval('d /a/', __FILE__)
163
+ end
164
+
165
+ Warning.ignore(:ambiguous_slash, __FILE__)
166
+
167
+ assert_warning '' do
168
+ instance_eval('d /a/', __FILE__)
169
+ end
170
+ end
171
+
172
+ def test_warning_ignore_unused_var
173
+ assert_warning(/warning: assigned but unused variable - \w+/) do
174
+ instance_eval('def self.e; b = 1; 2 end', __FILE__)
175
+ end
176
+
177
+ Warning.ignore(:unused_var, __FILE__)
178
+
179
+ assert_warning '' do
180
+ instance_eval('def self.f; b = 1; 2 end', __FILE__)
181
+ end
182
+ end
183
+
184
+ def test_warning_ignore_useless_operator
185
+ assert_warning(/warning: possibly useless use of == in void context/) do
186
+ instance_eval('1 == 2; true', __FILE__)
187
+ end
188
+
189
+ Warning.ignore(:useless_operator, __FILE__)
190
+
191
+ assert_warning '' do
192
+ instance_eval('1 == 2; true', __FILE__)
193
+ end
194
+ end
195
+
196
+ def test_warning_ignore_arg_prefix
197
+ assert_warning(/: warning: `\*' interpreted as argument prefix/) do
198
+ instance_eval('Array *[nil]', __FILE__)
199
+ end
200
+
201
+ assert_warning(/: warning: `&' interpreted as argument prefix/) do
202
+ instance_eval('tap &proc{}', __FILE__)
203
+ end
204
+ Warning.ignore(:arg_prefix, __FILE__)
205
+
206
+ assert_warning '' do
207
+ instance_eval('Array *[nil]', __FILE__)
208
+ instance_eval('tap &proc{}', __FILE__)
209
+ end
210
+ end
211
+
212
+ def test_warning_ignore_shadow
213
+ assert_warning(/warning: shadowing outer local variable - a/) do
214
+ instance_eval('lambda{|a| lambda{|a|}}', __FILE__)
215
+ end
216
+
217
+ Warning.ignore(:shadow, __FILE__)
218
+
219
+ assert_warning '' do
220
+ instance_eval('lambda{|a| lambda{|a|}}', __FILE__)
221
+ end
222
+ end
223
+
224
+ def test_warning_ignore_symbol_array
225
+ def self.c; end
226
+
227
+ assert_warning(/statement not reached.+method redefined; discarding old c.+previous definition of c was here/m) do
228
+ instance_eval('def self.c; return; 1 end', __FILE__)
229
+ end
230
+
231
+ Warning.ignore([:method_redefined, :not_reached], __FILE__)
232
+
233
+ assert_warning '' do
234
+ instance_eval('def self.c; return; 1 end', __FILE__)
84
235
  end
85
- ensure
86
- Warning.clear
87
236
  end
88
237
 
89
238
  def test_warning_process
90
239
  obj = Object.new
91
240
  warn = nil
92
241
 
93
- require 'warning'
94
-
95
242
  Warning.process(__FILE__+'a') do |warning|
96
243
  warn = [0, warning]
97
244
  end
98
245
 
99
- assert_warning /instance variable @ivar not initialized/ do
246
+ assert_warning(/instance variable @ivar not initialized/) do
100
247
  assert_nil(obj.instance_variable_get(:@ivar))
101
248
  end
102
249
  assert_nil(warn)
@@ -136,7 +283,7 @@ class WarningTest < Minitest::Test
136
283
 
137
284
  Warning.clear
138
285
 
139
- assert_warning /instance variable @ivar5 not initialized/ do
286
+ assert_warning(/instance variable @ivar5 not initialized/) do
140
287
  assert_nil(obj.instance_variable_get(:@ivar5))
141
288
  end
142
289
  assert_nil(warn)
@@ -150,7 +297,5 @@ class WarningTest < Minitest::Test
150
297
  end
151
298
  assert_equal(4, warn.first)
152
299
  assert_match(/instance variable @ivar6 not initialized/, warn.last)
153
- ensure
154
- Warning.clear
155
300
  end
156
301
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.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: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  ruby-warning adds custom processing for warnings, including the
@@ -46,9 +46,9 @@ require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - ">="
49
+ - - ">"
50
50
  - !ruby/object:Gem::Version
51
- version: '2.4'
51
+ version: 2.3.99
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 2.5.1
59
+ rubygems_version: 2.6.8
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Add custom processing for warnings