cookstyle 6.12.6 → 6.13.3

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: f2a5a64113481754a334b8f95b80e976875672ca750c506dbdb586c2ccbab598
4
- data.tar.gz: 0ff373380e2f388e723a25b6ce1fae3e2447487cfe4c3692f3151e81f412a67a
3
+ metadata.gz: ddf96e2cc00a4c499396b6cb2b54297e64d0605edd2dba615fb28ecd0bcb91a9
4
+ data.tar.gz: 2ec5752d4202b2b7567f808346672b4a80c59967a8ebeed20fe354f0911236bb
5
5
  SHA512:
6
- metadata.gz: e4b62f764012b0f77378a0fa3d7b97abc249ece2fcc464234ce8c0b68d3bc41692324ce0557652f084a3d923f834973f660aa060206ab9d520fb09bbe75bc3de
7
- data.tar.gz: 6f3a5b63437a4dd752b211959915744fa6c6b7cce86c6da0711f950bcba8f1e3d8d40c3b661b19b4f2f5a871d3801316d12d39a29b367c097740852f704e78ee
6
+ metadata.gz: 4f5e75f32ca428f5b4395a3f42a50a37675e21dc79e89d4b7b1d731328c28e2cd1dfd116667c0c8c9b0887bfd1ca647901ecd6895c56e82bac5f4e9939c84e54
7
+ data.tar.gz: 6aa192abcf88b35034474eac2ebcfecd8c154e2f28e08f0995a53bb4e998e8a4af7f1e246a1f7fced0979bbd2bddd1bdd96bbde6c046fdc92299cede2b012742
@@ -454,6 +454,23 @@ ChefCorrectness/InvalidPlatformInCase:
454
454
  - '**/metadata.rb'
455
455
  - '**/Berksfile'
456
456
 
457
+ ChefCorrectness/InvalidDefaultAction:
458
+ Description: Default actions in resources should be a symbol or an array of symbols.
459
+ StyleGuide: '#chefcorrectnessinvaliddefaultaction'
460
+ Enabled: true
461
+ VersionAdded: '6.13.0'
462
+ Include:
463
+ - '**/libraries/*.rb'
464
+ - '**/resources/*.rb'
465
+
466
+ ChefCorrectness/SupportsMustBeFloat:
467
+ Description: Versions used in metadata.rb supports calls should be floats not integers.
468
+ StyleGuide: '#chefcorrectnesssupportsmustbefloat'
469
+ Enabled: true
470
+ VersionAdded: '6.13.0'
471
+ Include:
472
+ - '**/metadata.rb'
473
+
457
474
  ###############################
458
475
  # ChefSharing: Issues that prevent sharing code with other teams or with the Chef community in general
459
476
  ###############################
@@ -1581,7 +1598,7 @@ ChefModernize/ShellOutHelper:
1581
1598
 
1582
1599
  ChefModernize/ConditionalUsingTest:
1583
1600
  Description: Use ::File.exist?('/foo/bar') instead of the slower 'test -f /foo/bar' which requires shelling out.
1584
- StyleGuide: '#conditionalusingtest'
1601
+ StyleGuide: '#chefmodernizeconditionalusingtest'
1585
1602
  Enabled: true
1586
1603
  VersionAdded: '6.11.0'
1587
1604
  Exclude:
@@ -1589,6 +1606,26 @@ ChefModernize/ConditionalUsingTest:
1589
1606
  - '**/Berksfile'
1590
1607
  - '**/attributes/*.rb'
1591
1608
 
1609
+ ChefModernize/CronDFileOrTemplate:
1610
+ Description: Use the cron_d resource that ships with Chef Infra Client 14.4+ instead of manually creating the file with template, file, or cookbook_file resources
1611
+ StyleGuide: '#chefmodernizecrondfileortemplate'
1612
+ Enabled: true
1613
+ VersionAdded: '6.13.0'
1614
+ Exclude:
1615
+ - '**/metadata.rb'
1616
+ - '**/Berksfile'
1617
+ - '**/attributes/*.rb'
1618
+
1619
+ ChefModernize/ActionMethodInResource:
1620
+ Description: Use the custom resource language's `action :my_action` blocks instead of creating actions with methods.
1621
+ StyleGuide: '#chefmodernizeactionmethodinresource'
1622
+ Enabled: true
1623
+ VersionAdded: '6.13.0'
1624
+ Include:
1625
+ - '**/resources/*.rb'
1626
+ - '**/providers/*.rb'
1627
+ - '**/libraries/*.rb'
1628
+
1592
1629
  ###############################
1593
1630
  # ChefRedundantCode: Cleanup unnecessary code in your cookbooks regardless of Chef Infra Client release
1594
1631
  ###############################
@@ -1785,7 +1822,7 @@ ChefRedundantCode/UseCreateIfMissing:
1785
1822
 
1786
1823
  ChefRedundantCode/OhaiAttributeToString:
1787
1824
  Description: Many Ohai node attributes are already strings and don't need to be cast to strings again
1788
- StyleGuide: '#ohaiattributetostring'
1825
+ StyleGuide: '#chefredundantcodeohaiattributetostring'
1789
1826
  Enabled: true
1790
1827
  VersionAdded: '6.10.0'
1791
1828
  Exclude:
@@ -1794,13 +1831,23 @@ ChefRedundantCode/OhaiAttributeToString:
1794
1831
 
1795
1832
  ChefRedundantCode/MultiplePlatformChecks:
1796
1833
  Description: You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.
1797
- StyleGuide: '#multipleplatformchecks'
1834
+ StyleGuide: '#chefredundantcodemultipleplatformchecks'
1798
1835
  Enabled: true
1799
1836
  VersionAdded: '6.10.0'
1800
1837
  Exclude:
1801
1838
  - '**/metadata.rb'
1802
1839
  - '**/Berksfile'
1803
1840
 
1841
+ ChefRedundantCode/DoubleCompileTime:
1842
+ Description: If a resource includes the `compile_time` property there's no need to also use `.run_action(:some_action)` on the resource block
1843
+ StyleGuide: '#chefredundantcodedoublecompiletime'
1844
+ Enabled: true
1845
+ VersionAdded: '6.13.0'
1846
+ Exclude:
1847
+ - '**/metadata.rb'
1848
+ - '**/attributes/*.rb'
1849
+ - '**/Berksfile'
1850
+
1804
1851
  ###############################
1805
1852
  # ChefEffortless: Migrating to new patterns
1806
1853
  ###############################
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.12.6" # rubocop: disable Style/StringLiterals
3
+ VERSION = "6.13.3" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '0.88.0'
5
5
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ # Default actions in resources should be symbols or an array of symbols.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # default_action 'create'
28
+ #
29
+ # # good
30
+ # default_action :create
31
+ #
32
+ module ChefCorrectness
33
+ class InvalidDefaultAction < Cop
34
+ MSG = 'Default actions in resources should be symbols or an array of symbols.'
35
+
36
+ def_node_matcher :default_action?, '(send nil? :default_action $_)'
37
+
38
+ def on_send(node)
39
+ default_action?(node) do |match|
40
+ return if %i(send sym array).include?(match.type)
41
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module RuboCop
20
+ module Cop
21
+ module Chef
22
+ module ChefCorrectness
23
+ # Versions used in metadata.rb supports calls should be floats not integers.
24
+ #
25
+ # @example
26
+ #
27
+ # # bad
28
+ # supports 'redhat', '> 8'
29
+ #
30
+ # # good
31
+ # supports 'redhat', '> 8.0'
32
+ #
33
+ class SupportsMustBeFloat < Base
34
+ extend RuboCop::Cop::AutoCorrector
35
+
36
+ MSG = 'Versions used in metadata.rb supports calls should be floats not integers.'
37
+
38
+ def_node_matcher :supports_with_constraint?, '(send nil? :supports str $str)'
39
+
40
+ def on_send(node)
41
+ supports_with_constraint?(node) do |ver|
42
+ return if ver.source.include?('.')
43
+ add_offense(ver.loc.expression, message: MSG, severity: :refactor) do |corrector|
44
+ corrector.replace(ver.loc.expression, ver.source.gsub(ver.value, (ver.value + '.0')))
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -49,7 +49,7 @@ module RuboCop
49
49
 
50
50
  def autocorrect(node)
51
51
  lambda do |corrector|
52
- # @todo when we drop ruby 2.4 support we can convert to to just delete_prefix delete_suffix
52
+ # @todo when we drop ruby 2.4 support we can convert this to just delete_prefix delete_suffix
53
53
  corrector.replace(node.loc.expression, node.loc.expression.source.gsub(/^{/, '').gsub(/}$/, ''))
54
54
  end
55
55
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module ChefModernize
22
+ # Use the custom resource language's `action :my_action` blocks instead of creating actions with methods.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # def action_create
28
+ # # :create action code here
29
+ # end
30
+ #
31
+ # # good
32
+ # action :create do
33
+ # # :create action code here
34
+ # end
35
+ #
36
+ class ActionMethodInResource < Base
37
+ extend AutoCorrector
38
+
39
+ MSG = "Use the custom resource language's `action :my_action` blocks instead of creating actions with methods."
40
+
41
+ def_node_search :includes_poise?, '(send nil? :include (const nil? :Poise))'
42
+
43
+ def on_def(node)
44
+ return unless node.method_name.to_s.start_with?('action_') # when we stop support for Ruby < 2.7 the .to_s can go away here
45
+ return if node.arguments? # if they passed in arguments they may actually need this
46
+ return if node.parent && includes_poise?(node.parent)
47
+
48
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
49
+ # @todo when we drop ruby 2.4 support we can convert this to use delete_suffix
50
+ corrector.replace(node.loc.expression, node.source.gsub("def #{node.method_name}", "action :#{node.method_name.to_s.gsub(/^action_/, '')} do"))
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module ChefModernize
22
+ # Use the cron_d resource that ships with Chef Infra Client 14.4+ instead of manually creating the file with template, file, or cookbook_file resources.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # template '/etc/cron.d/backup' do
28
+ # source 'cron_backup_job.erb'
29
+ # owner 'root'
30
+ # group 'root'
31
+ # mode '644'
32
+ # end
33
+ #
34
+ # cookbook_file '/etc/cron.d/backup' do
35
+ # owner 'root'
36
+ # group 'root'
37
+ # mode '644'
38
+ # end
39
+ #
40
+ # file '/etc/cron.d/backup' do
41
+ # content '*/30 * * * * backup /usr/local/bin/backup_script.sh'
42
+ # owner 'root'
43
+ # group 'root'
44
+ # mode '644'
45
+ # end
46
+ #
47
+ # file '/etc/cron.d/blogs' do
48
+ # action :delete
49
+ # end
50
+ #
51
+ # # good
52
+ # cron_d 'backup' do
53
+ # minute '1'
54
+ # hour '1'
55
+ # mailto 'sysadmins@example.com'
56
+ # command '/usr/local/bin/backup_script.sh'
57
+ # end
58
+ #
59
+ # cron_d 'blogs' do
60
+ # action :delete
61
+ # end
62
+ #
63
+ class CronDFileOrTemplate < Cop
64
+ extend TargetChefVersion
65
+
66
+ minimum_target_chef_version '14.4'
67
+
68
+ MSG = 'Use the cron_d resource that ships with Chef Infra Client 14.4+ instead of manually creating the file with template, file, or cookbook_file resources'
69
+
70
+ def_node_matcher :file_or_template?, <<-PATTERN
71
+ (block
72
+ (send nil? {:template :file :cookbook_file}
73
+ (str $_))
74
+ ...
75
+ )
76
+ PATTERN
77
+
78
+ def on_block(node)
79
+ file_or_template?(node) do |file_name|
80
+ return unless file_name.start_with?('/etc/cron.d/')
81
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: 2020, Chef Software, Inc.
4
+ # Author:: Tim Smith (<tsmith@chef.io>)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ module ChefRedundantCode
22
+ # If a resource includes the `compile_time` property there's no need to also use `.run_action(:some_action)` on the resource block
23
+ #
24
+ # # bad
25
+ # chef_gem 'deep_merge' do
26
+ # action :nothing
27
+ # compile_time true
28
+ # end.run_action(:install)
29
+ #
30
+ # # good
31
+ # chef_gem 'deep_merge' do
32
+ # action :install
33
+ # compile_time true
34
+ # end
35
+ #
36
+ class DoubleCompileTime < Base
37
+ extend RuboCop::Cop::AutoCorrector
38
+
39
+ MSG = "If a resource includes the `compile_time` property there's no need to also use `.run_action(:some_action)` on the resource block."
40
+
41
+ def_node_matcher :compile_time_and_run_action?, <<-PATTERN
42
+ (send
43
+ $(block
44
+ (send nil? ... )
45
+ (args)
46
+ (begin <
47
+ (send nil? :action (sym $_) )
48
+ (send nil? :compile_time (true) )
49
+ ...
50
+ >)
51
+ ) :run_action (sym $_) )
52
+ PATTERN
53
+
54
+ def on_send(node)
55
+ compile_time_and_run_action?(node) do |resource, action, run_action|
56
+ add_offense(node.loc.selector, message: MSG, severity: :refactor) do |corrector|
57
+ corrector.replace(node.loc.expression, resource.source.gsub(action.to_s, run_action.to_s))
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ 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: 6.12.6
4
+ version: 6.13.3
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: 2020-07-14 00:00:00.000000000 Z
12
+ date: 2020-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -56,6 +56,7 @@ files:
56
56
  - lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb
57
57
  - lib/rubocop/cop/chef/correctness/dnf_package_allow_downgrades.rb
58
58
  - lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
59
+ - lib/rubocop/cop/chef/correctness/invalid_default_action.rb
59
60
  - lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb
60
61
  - lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb
61
62
  - lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb
@@ -79,6 +80,7 @@ files:
79
80
  - lib/rubocop/cop/chef/correctness/resource_with_none_action.rb
80
81
  - lib/rubocop/cop/chef/correctness/scoped_file_exist.rb
81
82
  - lib/rubocop/cop/chef/correctness/service_resource.rb
83
+ - lib/rubocop/cop/chef/correctness/supports_must_be_float.rb
82
84
  - lib/rubocop/cop/chef/correctness/tmp_path.rb
83
85
  - lib/rubocop/cop/chef/deprecation/ use_automatic_resource_name.rb
84
86
  - lib/rubocop/cop/chef/deprecation/chef_handler_recipe.rb
@@ -146,6 +148,7 @@ files:
146
148
  - lib/rubocop/cop/chef/effortless/node_roles.rb
147
149
  - lib/rubocop/cop/chef/effortless/search_for_environments_or_roles.rb
148
150
  - lib/rubocop/cop/chef/effortless/search_used.rb
151
+ - lib/rubocop/cop/chef/modernize/action_method_in_resource.rb
149
152
  - lib/rubocop/cop/chef/modernize/allowed_actions_initializer.rb
150
153
  - lib/rubocop/cop/chef/modernize/apt_default_recipe.rb
151
154
  - lib/rubocop/cop/chef/modernize/berksfile_source.rb
@@ -154,6 +157,7 @@ files:
154
157
  - lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
155
158
  - lib/rubocop/cop/chef/modernize/compile_time_resources.rb
156
159
  - lib/rubocop/cop/chef/modernize/conditional_using_test.rb
160
+ - lib/rubocop/cop/chef/modernize/cron_d_file_or_template.rb
157
161
  - lib/rubocop/cop/chef/modernize/cron_manage_resource.rb
158
162
  - lib/rubocop/cop/chef/modernize/databag_helpers.rb
159
163
  - lib/rubocop/cop/chef/modernize/default_action_initializer.rb
@@ -212,6 +216,7 @@ files:
212
216
  - lib/rubocop/cop/chef/redundant/attribute_metadata.rb
213
217
  - lib/rubocop/cop/chef/redundant/conflicts_metadata.rb
214
218
  - lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb
219
+ - lib/rubocop/cop/chef/redundant/double_compile_time.rb
215
220
  - lib/rubocop/cop/chef/redundant/grouping_metadata.rb
216
221
  - lib/rubocop/cop/chef/redundant/long_description_metadata.rb
217
222
  - lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb