warning_signs 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +65 -1
- data/lib/warning_signs/deprecation.rb +17 -11
- data/lib/warning_signs/environment.rb +5 -3
- data/lib/warning_signs/handler.rb +18 -11
- data/lib/warning_signs/pattern.rb +11 -0
- data/lib/warning_signs/regex_pattern.rb +13 -0
- data/lib/warning_signs/ruby_category_matcher.rb +29 -0
- data/lib/warning_signs/ruby_deprecation_catcher.rb +12 -5
- data/lib/warning_signs/string_pattern.rb +13 -0
- data/lib/warning_signs/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffe169d3fa9e10de71c8ca43c6ac4cf8dd3c036f716d9a9f608fc37ce01a1879
|
4
|
+
data.tar.gz: a7511cdd8e836b8e1906b8c44a9ea3ec3309918fd033935a05480f7179bc4722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: babffad1137746742209cf4fe4adc14f7b2a905684b31f8e68569ccdcc9806945b88e690b75262bf62b9c4d09be77eb87cc5c7aeac58bc947d3ff3165eda9854
|
7
|
+
data.tar.gz: 23750e8b4849c3a1bd2d349fb26696e36eb34afcd71e0e3cb04619ed32234549f880cdc5f28e2d1da5fc57b1b1b519fc705ea75fe00de582c82e8612129473e8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 0.4.0
|
2
|
+
|
3
|
+
* Allow handlers to take into account Ruby warning categories
|
4
|
+
* Ruby warning message better handles Ruby warning categories
|
5
|
+
|
6
|
+
## 0.3.0
|
7
|
+
|
8
|
+
* Allow multiple behaviors in a single environment
|
9
|
+
* Allow only and except matchers to be regular expressions
|
10
|
+
|
11
|
+
## 0.2.0
|
12
|
+
|
13
|
+
* Test for "other environment"
|
14
|
+
|
1
15
|
## 0.1.0
|
2
16
|
|
3
17
|
* Smarter caller information for Ruby warnings
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,21 @@ handlers:
|
|
83
83
|
behavior: ignore
|
84
84
|
```
|
85
85
|
|
86
|
+
A single environment can have multiple behaviors. This is helpful if you are,
|
87
|
+
say dealing with end-to-end specs that swallow exceptions:
|
88
|
+
|
89
|
+
```yaml
|
90
|
+
handlers:
|
91
|
+
- environment: all
|
92
|
+
behaviors:
|
93
|
+
- raise
|
94
|
+
- log
|
95
|
+
```
|
96
|
+
|
97
|
+
No matter what order you have the behaviors in, a `raise` behavior will be
|
98
|
+
executed last so that the other behaviors happen before the exception is
|
99
|
+
invoked.
|
100
|
+
|
86
101
|
A common pattern is to focus only on specific deprecations and ignore others.
|
87
102
|
For example, this setting file would raise on Ruby keyword argument
|
88
103
|
deprecations and ignore other ruby deprecations
|
@@ -99,7 +114,22 @@ handlers:
|
|
99
114
|
```
|
100
115
|
|
101
116
|
Patterns are matched if the deprecation message contains the pattern as a
|
102
|
-
substring
|
117
|
+
substring.
|
118
|
+
|
119
|
+
The pattern can be a regular expression, denoted by using regular expression
|
120
|
+
syntax _inside_ the string in the YAML:
|
121
|
+
|
122
|
+
```yaml
|
123
|
+
handlers:
|
124
|
+
- source: ruby
|
125
|
+
only:
|
126
|
+
- "/Using .* argument/"
|
127
|
+
environment: all
|
128
|
+
behavior: log
|
129
|
+
```
|
130
|
+
|
131
|
+
The pattern inside the slashes is converted to a Ruby `Regexp` and patterns
|
132
|
+
are matched if the regexp and the deprecation warning message match.
|
103
133
|
|
104
134
|
Another pattern is to have a list of ignored deprecations and then remove
|
105
135
|
messages one by one and manage them individually.
|
@@ -120,3 +150,37 @@ handlers:
|
|
120
150
|
- environment: other
|
121
151
|
behavior: log
|
122
152
|
```
|
153
|
+
|
154
|
+
Ruby warnings can have an optional category, there are two predefined
|
155
|
+
categories, `deprecated` and `experimental`. You can specify a handler to
|
156
|
+
match those categories based on an "only" or "except" matcher. If you want
|
157
|
+
to specially handle warnings that do not have a defined category, you can
|
158
|
+
refer to them as `blank`,
|
159
|
+
|
160
|
+
This handler only handles Ruby warnings that are deprecated, other warnings
|
161
|
+
are ignored.
|
162
|
+
|
163
|
+
```yaml
|
164
|
+
handlers:
|
165
|
+
- environment: all
|
166
|
+
ruby_warnings:
|
167
|
+
only:
|
168
|
+
- deprecated
|
169
|
+
behavior: log
|
170
|
+
```
|
171
|
+
|
172
|
+
This handler handles any Ruby warning with a category
|
173
|
+
|
174
|
+
```yaml
|
175
|
+
handlers:
|
176
|
+
- environment: all
|
177
|
+
ruby_warnings:
|
178
|
+
except:
|
179
|
+
- blank
|
180
|
+
behavior: log
|
181
|
+
```
|
182
|
+
|
183
|
+
## To Do:
|
184
|
+
|
185
|
+
* write to standard out as a behavior
|
186
|
+
* Ability to customize output message format
|
@@ -1,28 +1,34 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class Deprecation
|
3
|
-
attr_accessor :message, :source
|
3
|
+
attr_accessor :message, :source, :category
|
4
4
|
|
5
|
-
def initialize(message, source:)
|
5
|
+
def initialize(message, source:, category: nil)
|
6
6
|
@message = message
|
7
7
|
@source = source.to_s.downcase.inquiry
|
8
|
+
@category = category
|
8
9
|
end
|
9
10
|
|
10
11
|
def handler
|
11
12
|
World.instance.handler_for(self)
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
# force raise to be the last element if it is present
|
16
|
+
def behaviors
|
17
|
+
result = (handler&.environment&.behaviors || []).inquiry
|
18
|
+
return result unless result.raise?
|
19
|
+
(result - ["raise"]) << "raise"
|
16
20
|
end
|
17
21
|
|
18
22
|
def invoke
|
19
|
-
|
20
|
-
|
21
|
-
raise
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
behaviors.each do |behavior|
|
24
|
+
case behavior
|
25
|
+
when "raise"
|
26
|
+
raise UnhandledDeprecationError, message
|
27
|
+
when "log"
|
28
|
+
Rails.logger.warn(message)
|
29
|
+
when "stderr"
|
30
|
+
$stderr.puts(message) # standard:disable Style/StderrPuts
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class Environment
|
3
|
-
attr_accessor :environment, :
|
3
|
+
attr_accessor :environment, :behaviors
|
4
4
|
|
5
|
-
def initialize(environment:, behavior:)
|
5
|
+
def initialize(environment:, behaviors: [], behavior: nil)
|
6
6
|
@environment = environment.to_s.downcase.inquiry
|
7
|
-
@
|
7
|
+
@behaviors = (behaviors + [behavior])
|
8
|
+
.compact
|
9
|
+
.map { _1.to_s.downcase.inquiry }
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,27 +1,29 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
class Handler
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :environments, :except, :only, :source, :category_matcher
|
4
4
|
|
5
5
|
def self.from_hash(hash)
|
6
6
|
new(**hash.symbolize_keys)
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(
|
10
|
-
behavior:
|
10
|
+
behavior: nil,
|
11
|
+
behaviors: [],
|
11
12
|
environment: nil,
|
12
13
|
except: [],
|
13
14
|
only: [],
|
14
15
|
source: "any",
|
15
|
-
environments: []
|
16
|
+
environments: [],
|
17
|
+
ruby_warnings: {}
|
16
18
|
)
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@only = only
|
19
|
+
@except = except.map { Pattern.for(_1) }
|
20
|
+
@only = only.map { Pattern.for(_1) }
|
20
21
|
@environments = environments.map { Environment.new(**_1.symbolize_keys) }
|
21
22
|
if environment.present?
|
22
|
-
@environments << Environment.new(environment: environment, behavior: behavior)
|
23
|
+
@environments << Environment.new(environment: environment, behaviors: behaviors, behavior: behavior)
|
23
24
|
end
|
24
25
|
@source = source.to_s.downcase.inquiry
|
26
|
+
@category_matcher = RubyCategoryMatcher.new(**ruby_warnings.symbolize_keys)
|
25
27
|
raise InvalidHandlerError unless valid?
|
26
28
|
end
|
27
29
|
|
@@ -35,7 +37,12 @@ module WarningSigns
|
|
35
37
|
|
36
38
|
def match?(deprecation)
|
37
39
|
source_match?(deprecation.source) &&
|
38
|
-
pattern_match?(deprecation.message)
|
40
|
+
pattern_match?(deprecation.message) &&
|
41
|
+
category_match?(deprecation.category)
|
42
|
+
end
|
43
|
+
|
44
|
+
def category_match?(category)
|
45
|
+
category_matcher.match?(category)
|
39
46
|
end
|
40
47
|
|
41
48
|
def pattern_match?(message)
|
@@ -50,14 +57,14 @@ module WarningSigns
|
|
50
57
|
def only_match?(message)
|
51
58
|
return true if only.empty?
|
52
59
|
only.any? do |only_pattern|
|
53
|
-
|
60
|
+
only_pattern.match?(message)
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
57
64
|
def except_match?(message)
|
58
65
|
return true if except.empty?
|
59
|
-
except.none? do |
|
60
|
-
|
66
|
+
except.none? do |except_pattern|
|
67
|
+
except_pattern.match?(message)
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WarningSigns
|
2
|
+
class RubyCategoryMatcher
|
3
|
+
attr_accessor :only, :except
|
4
|
+
|
5
|
+
def initialize(only: [], except: [])
|
6
|
+
@only = only.compact.map { _1.to_sym }
|
7
|
+
@except = except.compact.map { _1.to_sym }
|
8
|
+
end
|
9
|
+
|
10
|
+
def match?(category)
|
11
|
+
category = :blank if category.blank?
|
12
|
+
only_match?(category) && except_match?(category)
|
13
|
+
end
|
14
|
+
|
15
|
+
def only_match?(category)
|
16
|
+
return true if only.empty?
|
17
|
+
only.any? do |only_pattern|
|
18
|
+
only_pattern === category&.to_sym
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def except_match?(category)
|
23
|
+
return true if except.empty?
|
24
|
+
except.none? do |except_pattern|
|
25
|
+
except_pattern === category&.to_sym
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,17 +1,24 @@
|
|
1
1
|
module WarningSigns
|
2
2
|
module RubyDeprecationCatcher
|
3
|
-
def warn(message)
|
4
|
-
Deprecation.new(
|
3
|
+
def warn(message, category: nil)
|
4
|
+
Deprecation.new(
|
5
|
+
augmented_message(message, category),
|
6
|
+
source: "ruby",
|
7
|
+
category: category
|
8
|
+
).invoke
|
5
9
|
end
|
6
10
|
|
7
|
-
def augmented_message(message)
|
8
|
-
|
11
|
+
def augmented_message(message, category)
|
12
|
+
category_part = category.present? ? " #{category.upcase}: " : ": "
|
13
|
+
"RUBY WARNING#{category_part}#{message} called from #{caller_location}"
|
9
14
|
end
|
10
15
|
|
11
16
|
def caller_location
|
12
17
|
caller_locations.find do |location|
|
13
18
|
!location.to_s.include?("internal:warning") &&
|
14
|
-
!location.to_s.include?("warning_signs")
|
19
|
+
!location.to_s.include?("warning_signs") &&
|
20
|
+
!location.to_s.include?("rubygems") &&
|
21
|
+
!location.to_s.include?("/gems")
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warning_signs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noel Rappin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|
@@ -173,9 +173,13 @@ files:
|
|
173
173
|
- lib/warning_signs/deprecation.rb
|
174
174
|
- lib/warning_signs/environment.rb
|
175
175
|
- lib/warning_signs/handler.rb
|
176
|
+
- lib/warning_signs/pattern.rb
|
176
177
|
- lib/warning_signs/rails_deprecation_catcher.rb
|
177
178
|
- lib/warning_signs/railtie.rb
|
179
|
+
- lib/warning_signs/regex_pattern.rb
|
180
|
+
- lib/warning_signs/ruby_category_matcher.rb
|
178
181
|
- lib/warning_signs/ruby_deprecation_catcher.rb
|
182
|
+
- lib/warning_signs/string_pattern.rb
|
179
183
|
- lib/warning_signs/version.rb
|
180
184
|
- lib/warning_signs/world.rb
|
181
185
|
- warning_signs.gemspec
|