cookstyle 5.0.4 → 5.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +9 -0
- data/bin/cookstyle +7 -0
- data/config/cookstyle.yml +195 -7
- data/config/upstream.yml +1 -1
- data/lib/cookstyle.rb +1 -0
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/chef/cookbook_only.rb +4 -3
- data/lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb +60 -0
- data/lib/rubocop/cop/chef/correctness/name_property_and_required.rb +94 -0
- data/lib/rubocop/cop/chef/correctness/node_normal.rb +53 -0
- data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +53 -0
- data/lib/rubocop/cop/chef/correctness/property_with_default_and_required.rb +67 -0
- data/lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb +59 -0
- data/lib/rubocop/cop/chef/{service_resource.rb → correctness/service_resource.rb} +1 -1
- data/lib/rubocop/cop/chef/{tmp_path.rb → correctness/tmp_path.rb} +1 -1
- data/lib/rubocop/cop/chef/deprecation/attribute_metadata.rb +49 -0
- data/lib/rubocop/cop/chef/deprecation/conflicts_metadata.rb +44 -0
- data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +48 -0
- data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +42 -0
- data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +42 -0
- data/lib/rubocop/cop/chef/deprecation/easy_install.rb +39 -0
- data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +50 -0
- data/lib/rubocop/cop/chef/deprecation/erl_call.rb +39 -0
- data/lib/rubocop/cop/chef/{node_set.rb → deprecation/node_set.rb} +2 -2
- data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +53 -0
- data/lib/rubocop/cop/chef/deprecation/provides_metadata.rb +44 -0
- data/lib/rubocop/cop/chef/deprecation/replaces_metadata.rb +44 -0
- data/lib/rubocop/cop/chef/deprecation/suggests_metadata.rb +44 -0
- data/lib/rubocop/cop/chef/effortless/data_bags.rb +36 -0
- data/lib/rubocop/cop/chef/effortless/search_used.rb +36 -0
- data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +59 -0
- data/lib/rubocop/cop/chef/modernize/build_essential.rb +52 -0
- data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +54 -0
- data/lib/rubocop/cop/chef/modernize/why_run_supported_true.rb +46 -0
- data/lib/rubocop/cop/chef/{attribute_keys.rb → style/attribute_keys.rb} +2 -2
- data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +42 -0
- data/lib/rubocop/cop/chef/{comments_copyright_format.rb → style/comments_copyright_format.rb} +5 -2
- data/lib/rubocop/cop/chef/{comments_format.rb → style/comments_format.rb} +4 -2
- data/lib/rubocop/cop/chef/{file_mode.rb → style/file_mode.rb} +1 -3
- metadata +34 -9
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software, Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
# Cookbooks should not depend on the deprecated Poise framework. They should instead
|
21
|
+
# be refactored as standard custom resources.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# depends 'poise'
|
27
|
+
class CookbookDependsOnPoise < Cop
|
28
|
+
MSG = 'Cookbooks should not depend on the deprecated Poise framework'.freeze
|
29
|
+
|
30
|
+
def_node_matcher :depends_method?, <<-PATTERN
|
31
|
+
(send nil? :depends $str)
|
32
|
+
PATTERN
|
33
|
+
|
34
|
+
def on_send(node)
|
35
|
+
depends_method?(node) do |arg|
|
36
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if arg == s(:str, 'poise')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
# Don't use the deprecated easy_install resource removed in Chef 13
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# easy_install "my_thing" do
|
27
|
+
# bar
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
class EasyInstallResource < Cop
|
31
|
+
MSG = "Don't use the deprecated easy_install resource removed in Chef 13".freeze
|
32
|
+
|
33
|
+
def on_send(node)
|
34
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :easy_install
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
# Make sure ignore_failure is used instead of epic_fail
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# package "foo" do
|
27
|
+
# epic_fail true
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# package "foo" do
|
32
|
+
# ignore_failure true
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
class EpicFail < Cop
|
36
|
+
MSG = 'Use ignore_failure method instead of the deprecated epic_fail method'.freeze
|
37
|
+
|
38
|
+
def on_send(node)
|
39
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :epic_fail
|
40
|
+
end
|
41
|
+
|
42
|
+
def autocorrect(node)
|
43
|
+
lambda do |corrector|
|
44
|
+
corrector.replace(node.loc.expression, 'ignore_failure true')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
# Don't use the deprecated erl_call resource
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# erl_call "foo" do
|
27
|
+
# bar
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
class ErlCallResource < Cop
|
31
|
+
MSG = "Don't use the deprecated erl_call resource removed in Chef 13".freeze
|
32
|
+
|
33
|
+
def on_send(node)
|
34
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :erl_call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019
|
2
|
+
# Copyright:: Copyright 2019, Chef Software Inc.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
|
39
39
|
def on_send(node)
|
40
40
|
node_set?(node) do
|
41
|
-
add_offense(node, location: :expression, message: MSG, severity: :
|
41
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2019-2019, Chef Software Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module RuboCop
|
17
|
+
module Cop
|
18
|
+
module Chef
|
19
|
+
# The node.set_unless method has been removed in Chef-13 and must be replaced by node.normal_unless.
|
20
|
+
#
|
21
|
+
# Note that node.normal_unless keeps the semantics identical, but the use of node.normal is
|
22
|
+
# also discouraged.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# node.set_unless['foo'] = true
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# node.normal_unless['foo'] = true
|
31
|
+
#
|
32
|
+
class NodeSetUnless < Cop
|
33
|
+
MSG = 'Do not use node.set_unless. Replace with node.normal_unless to keep identical behavior.'.freeze
|
34
|
+
|
35
|
+
def_node_matcher :node_set_unless?, <<-PATTERN
|
36
|
+
(send (send _ :node) :set_unless)
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
node_set_unless?(node) do
|
41
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def autocorrect(node)
|
46
|
+
lambda do |corrector|
|
47
|
+
corrector.replace(node.loc.expression, 'node.normal_unless')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
# Don't use the deprecated 'provides' metadata value
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad in metadata.rb:
|
26
|
+
#
|
27
|
+
# provides "some_thing"
|
28
|
+
#
|
29
|
+
class ProvidesMetadata < Cop
|
30
|
+
MSG = "Don't use the deprecated 'provides' metadata value".freeze
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :provides
|
34
|
+
end
|
35
|
+
|
36
|
+
def autocorrect(node)
|
37
|
+
lambda do |corrector|
|
38
|
+
corrector.remove(node.loc.expression)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
# Don't use the deprecated 'replaces' metadata value
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad in metadata.rb:
|
26
|
+
#
|
27
|
+
# replaces "another_cookbook"
|
28
|
+
#
|
29
|
+
class ReplacesMetadata < Cop
|
30
|
+
MSG = "Don't use the deprecated 'replaces' metadata value".freeze
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :replaces
|
34
|
+
end
|
35
|
+
|
36
|
+
def autocorrect(node)
|
37
|
+
lambda do |corrector|
|
38
|
+
corrector.remove(node.loc.expression)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
# Don't use the deprecated 'suggests' metadata value
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad in metadata.rb:
|
26
|
+
#
|
27
|
+
# suggests "another_cookbook"
|
28
|
+
#
|
29
|
+
class SuggestsMetadata < Cop
|
30
|
+
MSG = "Don't use the deprecated 'suggests' metadata value".freeze
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :suggests
|
34
|
+
end
|
35
|
+
|
36
|
+
def autocorrect(node)
|
37
|
+
lambda do |corrector|
|
38
|
+
corrector.remove(node.loc.expression)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
# Data bags cannot be used with the Effortless Infra pattern
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# data_bag_item('admins', login)
|
26
|
+
# data_bag(data_bag_name)
|
27
|
+
class CookbookUsesDatabags < Cop
|
28
|
+
MSG = 'Cookbook uses data bags, which cannot be used in the Effortless Infra pattern'.freeze
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if %i(data_bag data_bag_item).include?(node.method_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2019, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
# Search is not compatible with the Effortless Infra pattern
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# search(:node, 'run_list:recipe\[bacula\:\:server\]')
|
26
|
+
#
|
27
|
+
class CookbookUsesSearch < Cop
|
28
|
+
MSG = 'Cookbook uses search, which cannot be used in the Effortless Infra pattern'.freeze
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :search
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|