rubocop-vendor 0.3.0 → 0.4.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: e941792ad57c59310fce6a92c48ad1796ab2230c81b2ed8006e3e36352f8b52a
4
- data.tar.gz: c192abde567896c48acbb26a7a48755c3c2279c91468bf759ba847c194d01d64
3
+ metadata.gz: cfa5c71a43d700d91d855e340c1518a5f56158557a2d67043deb8dc1659ef581
4
+ data.tar.gz: 03d35e4c72b4b5f6f22a14ac8b407d9c5214daebdaaeadb3b63071f1bdf908d3
5
5
  SHA512:
6
- metadata.gz: edc5089daa67bacfc965c4180b2ddddcc3024b6ffcb32ba709d61d7e93ec5a8895d9304edb6fe4703053d810687d09900185955b5474c905f481cab251d46bf6
7
- data.tar.gz: 624a00ad210f1bb3f1f9bc416f3b18b3d2f9a042e2347d00dcf50a97bb5a7aa61292f619bab3eab7b2142d54bb06ee63dc9a38a42495d02171b2558cb7a22e95
6
+ metadata.gz: 171f091f8d6bd081c0a669b12ec4610b8e3b8874b32cfd69d8325b094dfd6c5f841d93b14aacf61567c9ab70ca988ecf2244b7350f69db83b6c1e1d6becffbdb
7
+ data.tar.gz: fc669e34d8d27b3d8ced74cf5852baf94067ae9cec52263aa82ba1b1fecd8d42716716e3bfbd75ec84c7c658f08e49bac0c1b4afbedd840d92733506b5e05764
data/README.md CHANGED
@@ -59,7 +59,7 @@ In your `.rubocop.yml`, you may treat the Vendor cops just like any other
59
59
  cop. For example:
60
60
 
61
61
  ```yaml
62
- Vednor/RollbarLogger:
62
+ Vendor/RollbarLogger:
63
63
  Exclude:
64
64
  - lib/example.rb
65
65
  ```
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Vendor
6
+ # This cop checks for Rollbar calls outside `rescue` blocks.
7
+ #
8
+ # The main reason for this suggestion is that Rollbar should not be used
9
+ # as a logger given it has a quota that is often multiple times smaller
10
+ # than the log quota. By reporting errors outside rescue blocks
11
+ # the developer is most likely in control of the exceptional flow and
12
+ # won't need a stack trace.
13
+ #
14
+ # @example
15
+ # # bad
16
+ # Rollbar.error("Unable to sync account")
17
+ #
18
+ # # good
19
+ # begin
20
+ # 1 / 0
21
+ # rescue StandardError => exception
22
+ # Rollbar.error(exception, "Unable to sync account")
23
+ # end
24
+ #
25
+ class RollbarInsideRescue < Cop
26
+ MSG = 'Only call Rollbar when handling errors inside a `rescue` block.'
27
+
28
+ def_node_matcher :rollbar?, <<-PATTERN
29
+ (send
30
+ (const nil? :Rollbar) {:log :debug :info :warning :error :critical} ...)
31
+ PATTERN
32
+
33
+ def on_send(node)
34
+ return unless rollbar?(node)
35
+
36
+ current_node = node.parent
37
+ until current_node.nil?
38
+ return if current_node.rescue_type?
39
+
40
+ break if current_node.def_type?
41
+ break if current_node.class_type?
42
+
43
+ current_node = current_node.parent
44
+ end
45
+
46
+ add_offense(node, location: node.children[0].loc.expression)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -3,6 +3,7 @@
3
3
  module RuboCop
4
4
  end
5
5
 
6
+ require_relative 'vendor/rollbar_inside_rescue'
6
7
  require_relative 'vendor/rollbar_interpolation'
7
8
  require_relative 'vendor/rollbar_log'
8
9
  require_relative 'vendor/rollbar_logger'
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Vendor
5
5
  module Version
6
- STRING = '0.3.0'
6
+ STRING = '0.4.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-vendor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Cabello
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-25 00:00:00.000000000 Z
13
+ date: 2019-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -82,6 +82,7 @@ files:
82
82
  - README.md
83
83
  - config/default.yml
84
84
  - lib/rubocop-vendor.rb
85
+ - lib/rubocop/cop/vendor/rollbar_inside_rescue.rb
85
86
  - lib/rubocop/cop/vendor/rollbar_interpolation.rb
86
87
  - lib/rubocop/cop/vendor/rollbar_log.rb
87
88
  - lib/rubocop/cop/vendor/rollbar_logger.rb