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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e941792ad57c59310fce6a92c48ad1796ab2230c81b2ed8006e3e36352f8b52a
|
4
|
+
data.tar.gz: c192abde567896c48acbb26a7a48755c3c2279c91468bf759ba847c194d01d64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
26
|
+
({str sym} _) ...)
|
25
27
|
PATTERN
|
26
28
|
|
27
29
|
def on_send(node)
|
28
|
-
|
29
|
-
|
30
|
+
return unless bad_method?(node)
|
31
|
+
|
32
|
+
add_offense(node, location: offending_range(node))
|
33
|
+
end
|
30
34
|
|
31
|
-
|
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
|
24
|
+
(send (const nil? :Rollbar) {:debug :info :warning} {str hash})
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def on_send(node)
|
28
|
-
|
29
|
-
return unless rollbar_call
|
28
|
+
return unless bad_method?(node)
|
30
29
|
|
31
|
-
add_offense(
|
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
|