cookstyle 6.17.6 → 6.17.7
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: '0385aed05c2f7b990958984ace106ea1f8b12d62feae5ba63fc0c382a880f678'
|
4
|
+
data.tar.gz: e7888f5a8f5959069e00a5d3be8ce8a80325b34fe0d943baddb8a414f97947fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a89eab0482fd1c1c158b9f5ead6f61b4693a391fd88855bba6b5e46f60ae3ebb28074ef7782e4d249cd097ebd8093461c25baaff2c699ae214bc12d8584b95ef
|
7
|
+
data.tar.gz: b125b09055b3388353ac3374ea1aa5061dc6dfe75f051a538004ed13d064820e40920d2d13fd2a0557cfe3b602237f346b7316adaa2e1174f9b0e4400ff7e71b
|
data/lib/cookstyle/version.rb
CHANGED
@@ -33,30 +33,58 @@ module RuboCop
|
|
33
33
|
# ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
|
34
34
|
#
|
35
35
|
class IncorrectLibraryInjection < Base
|
36
|
+
include RangeHelp
|
36
37
|
extend AutoCorrector
|
37
38
|
|
38
39
|
MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
|
39
40
|
|
41
|
+
def_node_search :correct_send?, <<-PATTERN
|
42
|
+
(send
|
43
|
+
(const
|
44
|
+
(const
|
45
|
+
(const {cbase nil?} :Chef) :DSL) :Recipe) :send
|
46
|
+
(sym :include)
|
47
|
+
... )
|
48
|
+
PATTERN
|
49
|
+
|
50
|
+
def_node_search :correct_include?, <<-PATTERN
|
51
|
+
(send
|
52
|
+
(const
|
53
|
+
(const
|
54
|
+
(const {cbase nil?} :Chef) :DSL) :Recipe) :include
|
55
|
+
... )
|
56
|
+
PATTERN
|
57
|
+
|
40
58
|
def_node_matcher :legacy_class_sends?, <<-PATTERN
|
41
59
|
(send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
|
42
60
|
PATTERN
|
43
61
|
|
44
|
-
def_node_matcher :
|
62
|
+
def_node_matcher :legacy_class_include?, <<-PATTERN
|
45
63
|
(send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )
|
46
64
|
PATTERN
|
47
65
|
|
66
|
+
# @todo: This is highly repetitive and could be simplified into a single node_matcher
|
67
|
+
# call with some matcher magic that should be figured out
|
48
68
|
def on_send(node)
|
49
69
|
legacy_class_sends?(node) do
|
50
70
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
51
|
-
|
52
|
-
|
71
|
+
if node.parent && correct_send?(node.parent)
|
72
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
73
|
+
else
|
74
|
+
corrector.replace(node.loc.expression,
|
75
|
+
node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
|
76
|
+
end
|
53
77
|
end
|
54
78
|
end
|
55
79
|
|
56
|
-
|
80
|
+
legacy_class_include?(node) do
|
57
81
|
add_offense(node, message: MSG, severity: :refactor) do |corrector|
|
58
|
-
|
59
|
-
|
82
|
+
if node.parent && correct_include?(node.parent)
|
83
|
+
corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
|
84
|
+
else
|
85
|
+
corrector.replace(node.loc.expression,
|
86
|
+
node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
|
87
|
+
end
|
60
88
|
end
|
61
89
|
end
|
62
90
|
end
|