warning_signs 0.0.1 → 0.3.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
  SHA256:
3
- metadata.gz: 55b5a8c89a3c99603f0b3878a341c8ab5cce9833a364ae43e6fa6e2f4a601b77
4
- data.tar.gz: 288ec53101a4c0fcfc17b326521ed49b88bfb081e642795c6667d0adbdf687c9
3
+ metadata.gz: d5dd43f86a3822293460f2d79efb2c2e98a5cb6a86ca5b85a3d762b4e9b82a8e
4
+ data.tar.gz: 9dd3da0dbd012564356f1c477038f9cd5b00652149c064aea4006224b408940f
5
5
  SHA512:
6
- metadata.gz: b6bbbff2c40d7299d8f559172a929d549f31ed5b1555262cae957d6958450e7fc9cadd87e4d6adcb23c15f9e16a0590336b9e036b54cbddcd32b097baf3e4929
7
- data.tar.gz: c24f89c8d34ff9ea560998af85d6ae6385945e35fdb6d5acd0a01a3258e5bb09186308d730760bc7b9f2657628d673d1776c5bf00e9b08bc8eba545999efe92d
6
+ metadata.gz: 4e73a2bc35a1283b56061fad2717c6b0c9ce19f91c34b81645bf57c9e4c09eee2f93f727529c107a54c2e47fa6a8d88b9958af522b3a12929d18f505924b734f
7
+ data.tar.gz: eb2050074df9f17103a57ebbf506cba97a9f0a4b17d82db8b968c359751edbb8787033c708d19b5bb2e2b57b49346f138576f9cd98552cca80f12578d4ce908a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 0.3.0
2
+
3
+ * Allow multiple behaviors in a single environment
4
+ * Allow only and except matchers to be regular expressions
5
+
6
+ ## 0.2.0
7
+
8
+ * Test for "other environment"
9
+
1
10
  ## 0.1.0
2
11
 
12
+ * Smarter caller information for Ruby warnings
13
+
14
+ ## 0.0.1
15
+
3
16
  * Initial public release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- warning_signs (0.0.1)
4
+ warning_signs (0.3.0)
5
5
  awesome_print
6
6
  railties
7
7
 
@@ -48,6 +48,10 @@ GEM
48
48
  minitest (5.18.0)
49
49
  nokogiri (1.14.3-arm64-darwin)
50
50
  racc (~> 1.4)
51
+ nokogiri (1.14.3-x86_64-darwin)
52
+ racc (~> 1.4)
53
+ nokogiri (1.14.3-x86_64-linux)
54
+ racc (~> 1.4)
51
55
  parallel (1.23.0)
52
56
  parser (3.2.2.1)
53
57
  ast (~> 2.4.1)
@@ -104,7 +108,7 @@ GEM
104
108
  rubocop-ast (>= 1.28.0, < 2.0)
105
109
  ruby-progressbar (~> 1.7)
106
110
  unicode-display_width (>= 2.4.0, < 3.0)
107
- rubocop-ast (1.28.0)
111
+ rubocop-ast (1.28.1)
108
112
  parser (>= 3.2.1.0)
109
113
  rubocop-performance (1.16.0)
110
114
  rubocop (>= 1.7.0, < 2.0)
@@ -115,7 +119,7 @@ GEM
115
119
  json (>= 1.8, < 3)
116
120
  simplecov-html (~> 0.10.0)
117
121
  simplecov-html (0.10.2)
118
- standard (1.28.0)
122
+ standard (1.28.2)
119
123
  language_server-protocol (~> 3.17.0.2)
120
124
  lint_roller (~> 1.0)
121
125
  rubocop (~> 1.50.2)
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.
@@ -11,18 +11,23 @@ module WarningSigns
11
11
  World.instance.handler_for(self)
12
12
  end
13
13
 
14
- def behavior
15
- handler&.environment&.behavior
14
+ # force raise to be the last element if it is present
15
+ def behaviors
16
+ result = (handler&.environment&.behaviors || []).inquiry
17
+ return result if !result.raise?
18
+ (result - ["raise"]) << "raise"
16
19
  end
17
20
 
18
21
  def invoke
19
- case behavior
20
- when "raise"
21
- raise UnhandledDeprecationError, message
22
- when "log"
23
- Rails.logger.warn(message)
24
- when "stderr"
25
- $stderr.puts(message) # standard:disable Style/StderrPuts
22
+ behaviors.each do |behavior|
23
+ case behavior
24
+ when "raise"
25
+ raise UnhandledDeprecationError, message
26
+ when "log"
27
+ Rails.logger.warn(message)
28
+ when "stderr"
29
+ $stderr.puts(message) # standard:disable Style/StderrPuts
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -1,10 +1,12 @@
1
1
  module WarningSigns
2
2
  class Environment
3
- attr_accessor :environment, :behavior
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
- @behavior = behavior.to_s.downcase.inquiry
7
+ @behaviors = (behaviors + [behavior])
8
+ .compact
9
+ .map { _1.to_s.downcase.inquiry }
8
10
  end
9
11
  end
10
12
  end
@@ -1,25 +1,25 @@
1
1
  module WarningSigns
2
2
  class Handler
3
- attr_accessor :behavior, :environments, :except, :only, :source
3
+ attr_accessor :environments, :except, :only, :source
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: "ignore",
10
+ behavior: nil,
11
+ behaviors: [],
11
12
  environment: nil,
12
13
  except: [],
13
14
  only: [],
14
15
  source: "any",
15
16
  environments: []
16
17
  )
17
- @behavior = behavior.to_s.downcase.inquiry
18
- @except = except
19
- @only = only
18
+ @except = except.map { Pattern.for(_1) }
19
+ @only = only.map { Pattern.for(_1) }
20
20
  @environments = environments.map { Environment.new(**_1.symbolize_keys) }
21
21
  if environment.present?
22
- @environments << Environment.new(environment: environment, behavior: behavior)
22
+ @environments << Environment.new(environment: environment, behaviors: behaviors, behavior: behavior)
23
23
  end
24
24
  @source = source.to_s.downcase.inquiry
25
25
  raise InvalidHandlerError unless valid?
@@ -50,14 +50,14 @@ module WarningSigns
50
50
  def only_match?(message)
51
51
  return true if only.empty?
52
52
  only.any? do |only_pattern|
53
- message.include?(only_pattern)
53
+ only_pattern.match?(message)
54
54
  end
55
55
  end
56
56
 
57
57
  def except_match?(message)
58
58
  return true if except.empty?
59
- except.none? do |only_pattern|
60
- message.include?(only_pattern)
59
+ except.none? do |except_pattern|
60
+ except_pattern.match?(message)
61
61
  end
62
62
  end
63
63
 
@@ -0,0 +1,11 @@
1
+ module WarningSigns
2
+ class Pattern
3
+ def self.for(raw_pattern)
4
+ if raw_pattern.starts_with?("/") && raw_pattern.ends_with?("/")
5
+ RegexPattern.new(raw_pattern)
6
+ else
7
+ StringPattern.new(raw_pattern)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module WarningSigns
2
+ class RegexPattern
3
+ attr_accessor :pattern
4
+
5
+ def initialize(raw_pattern)
6
+ @pattern = Regexp.new(raw_pattern[1...-1])
7
+ end
8
+
9
+ def match?(message)
10
+ pattern.match?(message)
11
+ end
12
+ end
13
+ end
@@ -5,7 +5,16 @@ module WarningSigns
5
5
  end
6
6
 
7
7
  def augmented_message(message)
8
- "RUBY DEPRECATION WARNING: #{message} called from #{caller_locations(2..2).first}"
8
+ "RUBY DEPRECATION WARNING: #{message} called from #{caller_location}"
9
+ end
10
+
11
+ def caller_location
12
+ caller_locations.find do |location|
13
+ !location.to_s.include?("internal:warning") &&
14
+ !location.to_s.include?("warning_signs") &&
15
+ !location.to_s.include?("rubygems") &&
16
+ !location.to_s.include?("/gems")
17
+ end
9
18
  end
10
19
  end
11
20
  end
@@ -0,0 +1,13 @@
1
+ module WarningSigns
2
+ class StringPattern
3
+ attr_accessor :pattern
4
+
5
+ def initialize(raw_pattern)
6
+ @pattern = raw_pattern
7
+ end
8
+
9
+ def match?(message)
10
+ message.include?(pattern)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module WarningSigns
2
- VERSION = "0.0.1"
2
+ VERSION = "0.3.0"
3
3
  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.0.1
4
+ version: 0.3.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-01 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -173,9 +173,12 @@ 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
178
180
  - lib/warning_signs/ruby_deprecation_catcher.rb
181
+ - lib/warning_signs/string_pattern.rb
179
182
  - lib/warning_signs/version.rb
180
183
  - lib/warning_signs/world.rb
181
184
  - warning_signs.gemspec