cookstyle 5.12.13 → 5.13.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: 6e756b583acf014633d6e2e08d00ea74c3992c66969f2c4628e8ab9871904418
4
- data.tar.gz: ba48e16104dbeb7a5767993b2cf6bd6e6abb53cf8f0f1f39e2cf0b9fd2fa06f9
3
+ metadata.gz: 536183d50b038f3bd9db265813f38f29502167e80aca88124b8419d5124b786d
4
+ data.tar.gz: a13c369bc38ce2c8dda503438d86988bff7d6899972df4b3b8f2773d3b96d631
5
5
  SHA512:
6
- metadata.gz: efcccd7869348c77ea7f39467f670199ba4150ae3b8ecdb3f599186d24a890632971a9e0868ab837d6c439c615ed1d9734991a4a45862a7022706f374a0140ea
7
- data.tar.gz: cc9506bc309032cb1a66e4130782cae81aa18773673f4fe9f8f58148587b788ca6b6c4c38bcd759b1fc34018276d3703316cd24321624af24cb07eb1d7e571af
6
+ metadata.gz: d6d0cd3db208a387271bbb6afd4c8ba4afc5e5f625e6e715c03cffe2360f0ef16de1d9d1c6e7e1d3b7d610a891b0cf40281e2691ca47b56931a9144e18ffd260
7
+ data.tar.gz: 76d0d91643ed7837f8c2316a811e79adf68dc6092ef2b764c4f41c9c4c96bead89db404fdc83bc75f485d83c11b3f8980691208fb8b393f9b08ee82af3afb3ab
@@ -610,6 +610,21 @@ ChefDeprecations/Cheffile:
610
610
  Include:
611
611
  - '**/Cheffile'
612
612
 
613
+ ChefDeprecations/LegacyNotifySyntax:
614
+ Description: Use the new-style notification syntax which allows you to notify resources defined later in a recipe or resource.
615
+ Enabled: true
616
+ VersionAdded: '5.13.0'
617
+ Exclude:
618
+ - '**/metadata.rb'
619
+
620
+ ChefDeprecations/NodeSetWithoutLevel:
621
+ Description: When setting a node attribute in Chef Infra Client 11 and later you must specify the precedence level.
622
+ Enabled: true
623
+ VersionAdded: '5.13.0'
624
+ Exclude:
625
+ - '**/metadata.rb'
626
+ - '**/attributes/*.rb'
627
+
613
628
  ###############################
614
629
  # ChefModernize: Cleaning up legacy code and using new built-in resources
615
630
  ###############################
@@ -905,6 +920,14 @@ ChefModernize/UnnecessaryMixlibShelloutRequire:
905
920
  - '**/resources/*.rb'
906
921
  - '**/providers/*.rb'
907
922
 
923
+ ChefModernize/EmptyResourceInitializeMethod:
924
+ Description: There is no need for an empty initialize method in a resource
925
+ Enabled: true
926
+ VersionAdded: '5.13.0'
927
+ Include:
928
+ - '**/resources/*.rb'
929
+ - '**/providers/*.rb'
930
+
908
931
  ###############################
909
932
  # Migrating to new patterns
910
933
  ###############################
@@ -7,6 +7,7 @@ require 'yaml'
7
7
  gem 'rubocop', "= #{Cookstyle::RUBOCOP_VERSION}"
8
8
  require 'rubocop'
9
9
  require 'rubocop/monkey_patches/comment_config.rb'
10
+ require 'rubocop/monkey_patches/json_formatter.rb'
10
11
 
11
12
  module RuboCop
12
13
  class ConfigLoader
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.12.13".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "5.13.7".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.75.1'.freeze
4
4
  end
@@ -0,0 +1,85 @@
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
+ module ChefDeprecations
21
+ # Use the new-style notification syntax which allows you to notify resources defined later in a recipe or resource.
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # template '/etc/www/configures-apache.conf' do
27
+ # notifies :restart, resources(service: 'apache')
28
+ # end
29
+ #
30
+ # template '/etc/www/configures-apache.conf' do
31
+ # notifies :restart, resources(service: 'apache'), :immediately
32
+ # end
33
+ #
34
+ # template '/etc/www/configures-apache.conf' do
35
+ # notifies :restart, resources(service: service_name_variable), :immediately
36
+ # end
37
+ #
38
+ # # good
39
+ # template '/etc/www/configures-apache.conf' do
40
+ # notifies :restart, 'service[apache]'
41
+ # end
42
+ #
43
+ # template '/etc/www/configures-apache.conf' do
44
+ # notifies :restart, 'service[apache]', :immediately
45
+ # end
46
+ #
47
+ # template '/etc/www/configures-apache.conf' do
48
+ # notifies :restart, "service[#{service_name_variable}]", :immediately
49
+ # end
50
+ #
51
+ class LegacyNotifySyntax < Cop
52
+ MSG = 'Use the new-style notification syntax which allows you to notify resources defined later in a recipe or resource.'.freeze
53
+
54
+ def_node_matcher :legacy_notify?, <<-PATTERN
55
+ (send nil? :notifies $(sym _) (send nil? :resources (hash (pair $(sym _) $(...) ) ) ) $... )
56
+ PATTERN
57
+
58
+ def on_send(node)
59
+ legacy_notify?(node) do
60
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
61
+ end
62
+ end
63
+
64
+ def autocorrect(node)
65
+ lambda do |corrector|
66
+ legacy_notify?(node) do |action, type, name, timing|
67
+ service_value = case name.type
68
+ when :str
69
+ "'#{type.source}[#{name.value}]'"
70
+ when :dstr
71
+ "\"#{type.source}[#{name.value.source}]\""
72
+ else
73
+ "\"#{type.source}[\#{#{name.source}}]\""
74
+ end
75
+ new_val = "notifies #{action.source}, #{service_value}"
76
+ new_val << ", #{timing.first.source}" unless timing.empty?
77
+ corrector.replace(node.loc.expression, new_val)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,66 @@
1
+ #
2
+ # Copyright:: Copyright 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
+ module ChefDeprecations
20
+ # When setting a node attribute in Chef Infra Client 11 and later you must specify the precedence level.
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # node['foo']['bar'] = 1
26
+ # node['foo']['bar'] << 1
27
+ # node['foo']['bar'] += 1
28
+ # node['foo']['bar'] -= 1
29
+ #
30
+ # # good
31
+ # node.default['foo']['bar'] = 1
32
+ # node.default['foo']['bar'] << 1
33
+ # node.default['foo']['bar'] += 1
34
+ # node.default['foo']['bar'] -= 1
35
+ #
36
+ class NodeSetWithoutLevel < Cop
37
+ MSG = 'When setting a node attribute in Chef Infra Client 11 and later you must specify the precedence level.'.freeze
38
+
39
+ def on_op_asgn(node)
40
+ # make sure it was a += or -=
41
+ if %i(- +).include?(node.node_parts[1])
42
+ add_offense_for_bare_assignment(node.children&.first)
43
+ end
44
+ end
45
+
46
+ def on_send(node)
47
+ # make sure the method being send is []= and then make sure the receiver is a send
48
+ if %i([]= <<).include?(node.method_name) && node.receiver.send_type?
49
+ add_offense_for_bare_assignment(node)
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def add_offense_for_bare_assignment(sub_node)
56
+ if sub_node.receiver == s(:send, nil, :node) # node['foo'] scenario
57
+ add_offense(sub_node.receiver, location: :selector, message: MSG, severity: :refactor)
58
+ elsif sub_node.receiver && sub_node.receiver&.node_parts[0] == s(:send, nil, :node) && sub_node.receiver&.node_parts[1] == :[] # node['foo']['bar'] scenario
59
+ add_offense(sub_node.receiver.node_parts.first, location: :selector, message: MSG, severity: :refactor)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -47,13 +47,17 @@ module RuboCop
47
47
  end
48
48
  end
49
49
 
50
+ def_node_search :default_action_method?, '(send nil? :default_action ... )'
51
+
50
52
  def_node_search :intialize_method, '(def :initialize ... )'
51
53
 
52
54
  def autocorrect(node)
53
55
  lambda do |corrector|
54
- # insert the new default_action call above the initialize method
55
- initialize_node = intialize_method(processed_source.ast).first
56
- corrector.insert_before(initialize_node.source_range, "default_action #{node.descendants.first.source}\n\n")
56
+ # insert the new default_action call above the initialize method, but not if one already exists (this is sadly common)
57
+ unless default_action_method?(processed_source.ast)
58
+ initialize_node = intialize_method(processed_source.ast).first
59
+ corrector.insert_before(initialize_node.source_range, "default_action #{node.descendants.first.source}\n\n")
60
+ end
57
61
 
58
62
  # remove the variable from the initialize method
59
63
  corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
@@ -0,0 +1,52 @@
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
+ module ChefModernize
21
+ # There is no need for an empty initialize method in a resource
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # def initialize(*args)
27
+ # super
28
+ # end
29
+ #
30
+ class EmptyResourceInitializeMethod < Cop
31
+ MSG = 'There is no need for an empty initialize method in a resource'.freeze
32
+
33
+ def_node_matcher :empty_initialize?, <<-PATTERN
34
+ (def :initialize (args (restarg :args)) (zsuper))
35
+ PATTERN
36
+
37
+ def on_def(node)
38
+ empty_initialize?(node) do
39
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
40
+ end
41
+ end
42
+
43
+ def autocorrect(node)
44
+ lambda do |corrector|
45
+ corrector.remove(node.loc.expression)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Formatter
5
+ # This formatter formats the report data in JSON format.
6
+ class JSONFormatter < BaseFormatter
7
+ # We need to expose the correctable status until https://github.com/rubocop-hq/rubocop/pull/7514 is merged
8
+ def hash_for_offense(offense)
9
+ {
10
+ severity: offense.severity.name,
11
+ message: offense.message,
12
+ cop_name: offense.cop_name,
13
+ corrected: offense.corrected?,
14
+ correctable: offense.status != :unsupported,
15
+ location: hash_for_location(offense),
16
+ }
17
+ end
18
+ end
19
+ end
20
+ 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: 5.12.13
4
+ version: 5.13.7
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: 2019-11-14 00:00:00.000000000 Z
12
+ date: 2019-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -91,6 +91,7 @@ files:
91
91
  - lib/rubocop/cop/chef/deprecation/erl_call.rb
92
92
  - lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb
93
93
  - lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb
94
+ - lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb
94
95
  - lib/rubocop/cop/chef/deprecation/legacy_yum_cookbook_recipes.rb
95
96
  - lib/rubocop/cop/chef/deprecation/locale_lc_all_property.rb
96
97
  - lib/rubocop/cop/chef/deprecation/long_description_metadata.rb
@@ -99,6 +100,7 @@ files:
99
100
  - lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb
100
101
  - lib/rubocop/cop/chef/deprecation/node_set.rb
101
102
  - lib/rubocop/cop/chef/deprecation/node_set_unless.rb
103
+ - lib/rubocop/cop/chef/deprecation/node_set_without_level.rb
102
104
  - lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb
103
105
  - lib/rubocop/cop/chef/deprecation/partial_search_helper_usage.rb
104
106
  - lib/rubocop/cop/chef/deprecation/poise_archive.rb
@@ -135,6 +137,7 @@ files:
135
137
  - lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
136
138
  - lib/rubocop/cop/chef/modernize/definitions.rb
137
139
  - lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
140
+ - lib/rubocop/cop/chef/modernize/empty_resource_initialize.rb
138
141
  - lib/rubocop/cop/chef/modernize/execute_apt_update.rb
139
142
  - lib/rubocop/cop/chef/modernize/execute_tzutil.rb
140
143
  - lib/rubocop/cop/chef/modernize/if_provides_default_action.rb
@@ -175,6 +178,7 @@ files:
175
178
  - lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb
176
179
  - lib/rubocop/cop/chef/style/use_platform_helpers.rb
177
180
  - lib/rubocop/monkey_patches/comment_config.rb
181
+ - lib/rubocop/monkey_patches/json_formatter.rb
178
182
  homepage: https://github.com/chef/cookstyle
179
183
  licenses:
180
184
  - Apache-2.0