rubocop-vendor 0.2.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: fe1f462290839dea864712489498d9692d77909835d10c3210f6188683f90e24
4
- data.tar.gz: d228e77bcc8c2df232f4160d98765bf2305c12d4fbed668aaaa3f535b0e1a65b
3
+ metadata.gz: e941792ad57c59310fce6a92c48ad1796ab2230c81b2ed8006e3e36352f8b52a
4
+ data.tar.gz: c192abde567896c48acbb26a7a48755c3c2279c91468bf759ba847c194d01d64
5
5
  SHA512:
6
- metadata.gz: 8f231f57b14ff0aeba3c034863f4dc5eec541c15b0f2d6e035c4205101739c6b23684ab1934c8b8e071e0f33c8fe14a9677a5ea224ab4e6905bec7f88dbe23c7
7
- data.tar.gz: 0c14aad1fc61dd8010d6b01476441a43293d29807051d5c4e0625eb9cea9e9a5705644826b7e9a1e0a5c8afdaec4f76e00bc45f7ec4007e61283e21903c69b4a
6
+ metadata.gz: edc5089daa67bacfc965c4180b2ddddcc3024b6ffcb32ba709d61d7e93ec5a8895d9304edb6fe4703053d810687d09900185955b5474c905f481cab251d46bf6
7
+ data.tar.gz: 624a00ad210f1bb3f1f9bc416f3b18b3d2f9a042e2347d00dcf50a97bb5a7aa61292f619bab3eab7b2142d54bb06ee63dc9a38a42495d02171b2558cb7a22e95
@@ -16,25 +16,41 @@ module RuboCop
16
16
  # Rollbar.info('Stale message')
17
17
  #
18
18
  class RollbarLog < Cop
19
+ include RangeHelp
20
+
19
21
  MSG = 'Use `Rollbar.%<method>s` instead of `Rollbar.log`.'
20
22
 
21
23
  def_node_matcher :bad_method?, <<-PATTERN
22
24
  (send
23
25
  (const nil? :Rollbar) :log
24
- $({str sym} _) ...)
26
+ ({str sym} _) ...)
25
27
  PATTERN
26
28
 
27
29
  def on_send(node)
28
- level = bad_method?(node)
29
- return unless level
30
+ return unless bad_method?(node)
31
+
32
+ add_offense(node, location: offending_range(node))
33
+ end
30
34
 
31
- add_offense(level)
35
+ def autocorrect(node)
36
+ range = offending_range(node)
37
+ replacement = "#{node.children[2].value}#{range.source.include?('(') ? '(' : ' '}"
38
+ lambda do |corrector|
39
+ corrector.replace(range, replacement)
40
+ end
32
41
  end
33
42
 
34
43
  private
35
44
 
45
+ def offending_range(node)
46
+ range_between(
47
+ node.children[0].loc.last_column + 1,
48
+ node.children[3].loc.column
49
+ )
50
+ end
51
+
36
52
  def message(node)
37
- format(MSG, method: node.value)
53
+ format(MSG, method: node.children[2].value)
38
54
  end
39
55
  end
40
56
  end
@@ -21,19 +21,18 @@ module RuboCop
21
21
  MSG = 'Use `Rails.logger` for `debug`, `info` or `warning` calls.'
22
22
 
23
23
  def_node_matcher :bad_method?, <<-PATTERN
24
- (send $(const nil? :Rollbar) {:debug :info :warning} ...)
24
+ (send (const nil? :Rollbar) {:debug :info :warning} {str hash})
25
25
  PATTERN
26
26
 
27
27
  def on_send(node)
28
- rollbar_call = bad_method?(node)
29
- return unless rollbar_call
28
+ return unless bad_method?(node)
30
29
 
31
- add_offense(rollbar_call)
30
+ add_offense(node, location: node.children[0].loc.expression)
32
31
  end
33
32
 
34
33
  def autocorrect(node)
35
34
  lambda do |corrector|
36
- corrector.replace(node.loc.expression, 'Rails.logger')
35
+ corrector.replace(node.children[0].loc.expression, 'Rails.logger')
37
36
  end
38
37
  end
39
38
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Vendor
5
5
  module Version
6
- STRING = '0.2.1'
6
+ STRING = '0.3.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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Cabello