cookstyle 7.28.2 → 7.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af05586e951fed9a9a11777583d2f8b0ec7634cca38b3b5b9641e2afb11be50b
|
|
4
|
+
data.tar.gz: 8d727e0f4898bf20149fa74ee6d15782840577c98eeb9fe25048ae71ab13c4b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dbd9a0129be207bd120c0ba860260726c4547b8e0356eda5c221b70d29aaf9ec92fdce5af7450b919f8a74774b79820c128220749e883c226de4c82f45c21915
|
|
7
|
+
data.tar.gz: 74e57634c9aef93e952858a542cac3966c849fa3e1deb2dd5b0ef4b7cd9f8167eba767e55635b72c2cbc7f3d08228a3fed26ed4f2e072e4eb6d8c78a09c3b151
|
data/lib/cookstyle/version.rb
CHANGED
|
@@ -111,6 +111,8 @@ module RuboCop
|
|
|
111
111
|
case node.type
|
|
112
112
|
when :send
|
|
113
113
|
yield(node) if node.receiver.nil? # if it's not nil then we're not in a property foo we're in bar.foo
|
|
114
|
+
when :block # ie: not_if { ruby_foo }
|
|
115
|
+
yield(node)
|
|
114
116
|
when :while
|
|
115
117
|
extract_send_types(node.body) { |t| yield(t) }
|
|
116
118
|
when :if
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
|
-
# Copyright:: 2019, Chef Software, Inc.
|
|
3
|
+
# Copyright:: 2019-2022, Chef Software, Inc.
|
|
4
4
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
|
5
5
|
#
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -26,6 +26,7 @@ module RuboCop
|
|
|
26
26
|
# #### incorrect
|
|
27
27
|
# depends 'poise'
|
|
28
28
|
# depends 'poise-service'
|
|
29
|
+
# depends 'poise-hoist'
|
|
29
30
|
#
|
|
30
31
|
class CookbookDependsOnPoise < Base
|
|
31
32
|
MSG = 'Cookbooks should not depend on the deprecated Poise framework'
|
|
@@ -37,7 +38,7 @@ module RuboCop
|
|
|
37
38
|
|
|
38
39
|
def on_send(node)
|
|
39
40
|
depends_method?(node) do |arg|
|
|
40
|
-
add_offense(node, message: MSG, severity: :warning) if %w(poise poise-service).include?(arg.value)
|
|
41
|
+
add_offense(node, message: MSG, severity: :warning) if %w(poise poise-service poise-hoist).include?(arg.value)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
|
-
# Copyright:: 2020, Chef Software, Inc.
|
|
3
|
+
# Copyright:: 2020-2022, Chef Software, Inc.
|
|
4
4
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
|
5
5
|
#
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
|
19
19
|
module Cop
|
|
20
20
|
module Chef
|
|
21
21
|
module RedundantCode
|
|
22
|
-
# Use the
|
|
22
|
+
# Use the `:create_if_missing` action instead of `not_if` with a `::File.exist(FOO)` check.
|
|
23
23
|
#
|
|
24
24
|
# @example
|
|
25
25
|
#
|
|
@@ -32,6 +32,15 @@ module RuboCop
|
|
|
32
32
|
# not_if { ::File.exists?('/logs/foo/error.log') }
|
|
33
33
|
# end
|
|
34
34
|
#
|
|
35
|
+
# remote_file 'Download file' do
|
|
36
|
+
# path '/foo/bar'
|
|
37
|
+
# source 'https://foo.com/bar'
|
|
38
|
+
# owner 'root'
|
|
39
|
+
# group 'root'
|
|
40
|
+
# mode '0644'
|
|
41
|
+
# not_if { ::File.exist?('/foo/bar') }
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
35
44
|
# #### correct
|
|
36
45
|
# cookbook_file '/logs/foo/error.log' do
|
|
37
46
|
# source 'error.log'
|
|
@@ -41,30 +50,61 @@ module RuboCop
|
|
|
41
50
|
# action :create_if_missing
|
|
42
51
|
# end
|
|
43
52
|
#
|
|
53
|
+
# remote_file 'Download file' do
|
|
54
|
+
# path '/foo/bar'
|
|
55
|
+
# source 'https://foo.com/bar'
|
|
56
|
+
# owner 'root'
|
|
57
|
+
# group 'root'
|
|
58
|
+
# mode '0644'
|
|
59
|
+
# action :create_if_missing
|
|
60
|
+
# end
|
|
61
|
+
#
|
|
44
62
|
class UseCreateIfMissing < Base
|
|
45
63
|
include RuboCop::Chef::CookbookHelpers
|
|
46
64
|
extend AutoCorrector
|
|
65
|
+
include RangeHelp
|
|
47
66
|
|
|
48
67
|
MSG = 'Use the :create_if_missing action instead of not_if with a ::File.exist(FOO) check.'
|
|
68
|
+
RESOURCES = %i(cookbook_file file remote_directory cron_d remote_file template).freeze
|
|
49
69
|
|
|
50
|
-
def_node_matcher :
|
|
51
|
-
(
|
|
70
|
+
def_node_matcher :file_exist_value, <<-PATTERN
|
|
71
|
+
(send (const {nil? (cbase)} :File) {:exist? :exists?} $(...))
|
|
52
72
|
PATTERN
|
|
53
73
|
|
|
54
|
-
|
|
55
|
-
(block (send nil? {:cookbook_file :file :remote_directory :cron_d :remote_file :template} $str) ... )
|
|
56
|
-
PATTERN
|
|
74
|
+
def_node_search :has_action?, '(send nil? :action ...)'
|
|
57
75
|
|
|
58
|
-
def_node_search :create_action
|
|
76
|
+
def_node_search :create_action, '(send nil? :action $sym)'
|
|
77
|
+
|
|
78
|
+
def_node_search :path_property_node, '(send nil? :path $...)'
|
|
59
79
|
|
|
60
80
|
def on_block(node)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
match_property_in_resource?(RESOURCES, :not_if, node) do |prop|
|
|
82
|
+
# if it's not a block type then it's not a ruby block with a file.exist
|
|
83
|
+
return unless prop.block_type?
|
|
84
|
+
|
|
85
|
+
file_exist_value(prop.body) do |exists_content| # check the contents of the ruby block that's passed
|
|
86
|
+
# not an offense if:
|
|
87
|
+
# - The resource block name (the last arg of the send) doesn't match the exists check content
|
|
88
|
+
# - If a path property is used it doesn't match the exists check content
|
|
89
|
+
return unless exists_content == node.send_node.last_argument ||
|
|
90
|
+
exists_content == path_property_node(node)&.first&.first
|
|
91
|
+
|
|
92
|
+
# we have an action so check if it is :create. If that's the case we can replace that value
|
|
93
|
+
# and delete the not_if line. Otherwise it's an action like :remove and while the whole resource
|
|
94
|
+
# no longer makes sense that's not our problem here.
|
|
95
|
+
create_action(node) do |create_action|
|
|
96
|
+
return unless create_action == s(:sym, :create)
|
|
97
|
+
add_offense(prop, message: MSG, severity: :refactor) do |corrector|
|
|
98
|
+
corrector.replace(create_action, ':create_if_missing')
|
|
99
|
+
corrector.remove(range_by_whole_lines(prop.source_range, include_final_newline: true))
|
|
100
|
+
end
|
|
101
|
+
return
|
|
102
|
+
end
|
|
65
103
|
|
|
66
|
-
|
|
67
|
-
|
|
104
|
+
# if we got this far we didn't return above when we had an action
|
|
105
|
+
# so we can just replace the not_if line with a new :create_if_missing action
|
|
106
|
+
add_offense(prop, message: MSG, severity: :refactor) do |corrector|
|
|
107
|
+
corrector.replace(prop, 'action :create_if_missing')
|
|
68
108
|
end
|
|
69
109
|
end
|
|
70
110
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cookstyle
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.30.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thom May
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2022-01-
|
|
12
|
+
date: 2022-01-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rubocop
|