cookstyle 6.10.2 → 6.11.4

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: fe8edd0728c5a74a2496aa1fea1093bbcafbe584b37c2e3a65edc1103fa8580d
4
- data.tar.gz: 11abc23f923ef8b0e50bb91223cedc33c6b230ba1d30c2f4d37feb49df1452e4
3
+ metadata.gz: 4593dcbd93b8d0d668e0fe5e5551147db850c38deabcccf698b3f8ea391c281d
4
+ data.tar.gz: ef4557926f01a865f3ced43e0ad7a464659f597f4f6ffc8104c2f978d959324a
5
5
  SHA512:
6
- metadata.gz: 779695f4dd5a791a76ba01c59debefcc697826bbd3bbe2663369163a0d451d703dfc30f28c44017e34f9574c7c6365690ed1a4839fe116e51e1a42037bfb7144
7
- data.tar.gz: 87aed3d5935014296eae0b5280ef942011e31a546e92391d604eb581fcd0ea8f0882f03b08a50633c18ed876acbe895fc8dbd653adcd3345ac70a683b30afceb
6
+ metadata.gz: e3d3b5ed0ccd193ae9aad8d8e44a03935010a841c3cf551ce070c557f2f27e93ba2ffa2082042741f481ccabb7abf68e83d958ed06e3c5751556b7f0528aa3ae
7
+ data.tar.gz: e48e47c6d27316fe8054ecc45164aedf0385be8d8e8e1077781dd3ef9948ccb756864bb6adad422941f061232f0ca0d3c6c41679166bcf345dfa29fc71f79ed3
@@ -161,6 +161,16 @@ ChefStyle/NegatingOnlyIf:
161
161
  - '**/metadata.rb'
162
162
  - '**/Berksfile'
163
163
 
164
+ ChefStyle/IncludeRecipeWithParentheses:
165
+ Description: There is no need to wrap the recipe in parentheses when using the include_recipe helper
166
+ StyleGuide: '#includerecipewithparentheses'
167
+ VersionAdded: '6.11.0'
168
+ Enabled: true
169
+ Exclude:
170
+ - '**/attributes/*.rb'
171
+ - '**/metadata.rb'
172
+ - '**/Berksfile'
173
+
164
174
  ###############################
165
175
  # ChefCorrectness: Avoiding potential problems
166
176
  ###############################
@@ -300,8 +310,9 @@ ChefCorrectness/IncorrectLibraryInjection:
300
310
  StyleGuide: '#chefcorrectnessincorrectlibraryinjection'
301
311
  Enabled: true
302
312
  VersionAdded: '5.10.0'
303
- Include:
304
- - '**/libraries/*.rb'
313
+ Exclude:
314
+ - '**/metadata.rb'
315
+ - '**/Berksfile'
305
316
 
306
317
  ChefCorrectness/InvalidPlatformHelper:
307
318
  Description: Pass valid platforms to the platform? helper.
@@ -1541,6 +1552,16 @@ ChefModernize/ShellOutHelper:
1541
1552
  - '**/Berksfile'
1542
1553
  - '**/libraries/*.rb'
1543
1554
 
1555
+ ChefModernize/ConditionalUsingTest:
1556
+ Description: Use ::File.exist?('/foo/bar') instead of the slower 'test -f /foo/bar' which requires shelling out.
1557
+ StyleGuide: '#conditionalusingtest'
1558
+ Enabled: true
1559
+ VersionAdded: '6.11.0'
1560
+ Exclude:
1561
+ - '**/metadata.rb'
1562
+ - '**/Berksfile'
1563
+ - '**/attributes/*.rb'
1564
+
1544
1565
  ###############################
1545
1566
  # ChefRedundantCode: Cleanup unnecessary code in your cookbooks regardless of Chef Infra Client release
1546
1567
  ###############################
@@ -421,6 +421,8 @@ Naming/VariableNumber:
421
421
  Enabled: false
422
422
  Style/AccessModifierDeclarations:
423
423
  Enabled: false
424
+ Style/AccessorGrouping:
425
+ Enabled: false
424
426
  Style/Alias:
425
427
  Enabled: false
426
428
  Style/AndOr:
@@ -437,6 +439,8 @@ Style/BarePercentLiterals:
437
439
  Enabled: false
438
440
  Style/BeginBlock:
439
441
  Enabled: false
442
+ Style/BisectedAttrAccessor:
443
+ Enabled: false
440
444
  Style/BlockComments:
441
445
  Enabled: false
442
446
  Style/BlockDelimiters:
@@ -567,6 +571,8 @@ Style/MethodCallWithoutArgsParentheses:
567
571
  Enabled: false
568
572
  Style/MethodCallWithArgsParentheses:
569
573
  Enabled: false
574
+ Style/RedundantAssignment:
575
+ Enabled: false
570
576
  Style/RedundantFetchBlock:
571
577
  Enabled: false
572
578
  Style/MethodCalledOnDoEndBlock:
@@ -180,6 +180,9 @@ Bundler/OrderedGems:
180
180
  VersionAdded: '0.46'
181
181
  VersionChanged: '0.47'
182
182
  TreatCommentsAsGroupSeparators: true
183
+ # By default, "-" and "_" are ignored for order purposes.
184
+ # This can be overridden by setting this parameter to true.
185
+ ConsiderPunctuation: false
183
186
  Include:
184
187
  - '**/*.gemfile'
185
188
  - '**/Gemfile'
@@ -200,6 +203,9 @@ Gemspec/OrderedDependencies:
200
203
  Enabled: true
201
204
  VersionAdded: '0.51'
202
205
  TreatCommentsAsGroupSeparators: true
206
+ # By default, "-" and "_" are ignored for order purposes.
207
+ # This can be overridden by setting this parameter to true.
208
+ ConsiderPunctuation: false
203
209
  Include:
204
210
  - '**/*.gemspec'
205
211
 
@@ -1508,7 +1514,9 @@ Lint/InheritException:
1508
1514
  Lint/InterpolationCheck:
1509
1515
  Description: 'Raise warning for interpolation in single q strs.'
1510
1516
  Enabled: true
1517
+ SafeAutoCorrect: false
1511
1518
  VersionAdded: '0.50'
1519
+ VersionChanged: '0.87'
1512
1520
 
1513
1521
  Lint/LiteralAsCondition:
1514
1522
  Description: 'Checks of literals used in conditions.'
@@ -1736,6 +1744,7 @@ Lint/SafeNavigationWithEmpty:
1736
1744
  Description: 'Avoid `foo&.empty?` in conditionals.'
1737
1745
  Enabled: true
1738
1746
  VersionAdded: '0.62'
1747
+ VersionChanged: '0.87'
1739
1748
 
1740
1749
  Lint/ScriptPermission:
1741
1750
  Description: 'Grant script file execute permission.'
@@ -1902,9 +1911,10 @@ Metrics/BlockLength:
1902
1911
  Description: 'Avoid long blocks with many lines.'
1903
1912
  Enabled: true
1904
1913
  VersionAdded: '0.44'
1905
- VersionChanged: '0.66'
1914
+ VersionChanged: '0.87'
1906
1915
  CountComments: false # count full line comments?
1907
1916
  Max: 25
1917
+ CountAsOne: []
1908
1918
  ExcludedMethods:
1909
1919
  # By default, exclude the `#refine` method, as it tends to have larger
1910
1920
  # associated blocks.
@@ -1925,8 +1935,10 @@ Metrics/ClassLength:
1925
1935
  Description: 'Avoid classes longer than 100 lines of code.'
1926
1936
  Enabled: true
1927
1937
  VersionAdded: '0.25'
1938
+ VersionChanged: '0.87'
1928
1939
  CountComments: false # count full line comments?
1929
1940
  Max: 100
1941
+ CountAsOne: []
1930
1942
 
1931
1943
  # Avoid complex methods.
1932
1944
  Metrics/CyclomaticComplexity:
@@ -1944,17 +1956,20 @@ Metrics/MethodLength:
1944
1956
  StyleGuide: '#short-methods'
1945
1957
  Enabled: true
1946
1958
  VersionAdded: '0.25'
1947
- VersionChanged: '0.59.2'
1959
+ VersionChanged: '0.87'
1948
1960
  CountComments: false # count full line comments?
1949
1961
  Max: 10
1962
+ CountAsOne: []
1950
1963
  ExcludedMethods: []
1951
1964
 
1952
1965
  Metrics/ModuleLength:
1953
1966
  Description: 'Avoid modules longer than 100 lines of code.'
1954
1967
  Enabled: true
1955
1968
  VersionAdded: '0.31'
1969
+ VersionChanged: '0.87'
1956
1970
  CountComments: false # count full line comments?
1957
1971
  Max: 100
1972
+ CountAsOne: []
1958
1973
 
1959
1974
  Metrics/ParameterLists:
1960
1975
  Description: 'Avoid parameter lists longer than three or four parameters.'
@@ -1992,10 +2007,12 @@ Naming/AccessorMethodName:
1992
2007
  VersionAdded: '0.50'
1993
2008
 
1994
2009
  Naming/AsciiIdentifiers:
1995
- Description: 'Use only ascii symbols in identifiers.'
2010
+ Description: 'Use only ascii symbols in identifiers and constants.'
1996
2011
  StyleGuide: '#english-identifiers'
1997
2012
  Enabled: true
1998
2013
  VersionAdded: '0.50'
2014
+ VersionChanged: '0.87'
2015
+ AsciiConstants: true
1999
2016
 
2000
2017
  Naming/BinaryOperatorParameterName:
2001
2018
  Description: 'When defining binary operators, name the argument other.'
@@ -2288,6 +2305,17 @@ Style/AccessModifierDeclarations:
2288
2305
  - group
2289
2306
  AllowModifiersOnSymbols: true
2290
2307
 
2308
+ Style/AccessorGrouping:
2309
+ Description: 'Checks for grouping of accessors in `class` and `module` bodies.'
2310
+ Enabled: 'pending'
2311
+ VersionAdded: '0.87'
2312
+ EnforcedStyle: grouped
2313
+ SupportedStyles:
2314
+ # separated: each accessor goes in a separate statement.
2315
+ # grouped: accessors are grouped into a single statement.
2316
+ - separated
2317
+ - grouped
2318
+
2291
2319
  Style/Alias:
2292
2320
  Description: 'Use alias instead of alias_method.'
2293
2321
  StyleGuide: '#alias-method-lexically'
@@ -2355,6 +2383,13 @@ Style/BeginBlock:
2355
2383
  Enabled: true
2356
2384
  VersionAdded: '0.9'
2357
2385
 
2386
+ Style/BisectedAttrAccessor:
2387
+ Description: >-
2388
+ Checks for places where `attr_reader` and `attr_writer`
2389
+ for the same method can be combined into single `attr_accessor`.
2390
+ Enabled: 'pending'
2391
+ VersionAdded: '0.87'
2392
+
2358
2393
  Style/BlockComments:
2359
2394
  Description: 'Do not use block comments.'
2360
2395
  StyleGuide: '#no-block-comments'
@@ -2729,6 +2764,7 @@ Style/DoubleNegation:
2729
2764
  VersionAdded: '0.19'
2730
2765
  VersionChanged: '0.84'
2731
2766
  EnforcedStyle: allowed_in_returns
2767
+ SafeAutoCorrect: false
2732
2768
  SupportedStyles:
2733
2769
  - allowed_in_returns
2734
2770
  - forbidden
@@ -2995,6 +3031,7 @@ Style/IfUnlessModifierOfIfUnless:
2995
3031
  Avoid modifier if/unless usage on conditionals.
2996
3032
  Enabled: true
2997
3033
  VersionAdded: '0.39'
3034
+ VersionChanged: '0.87'
2998
3035
 
2999
3036
  Style/IfWithSemicolon:
3000
3037
  Description: 'Do not use if x; .... Use the ternary operator instead.'
@@ -3581,6 +3618,11 @@ Style/RandomWithOffset:
3581
3618
  Enabled: true
3582
3619
  VersionAdded: '0.52'
3583
3620
 
3621
+ Style/RedundantAssignment:
3622
+ Description: 'Checks for redundant assignment before returning.'
3623
+ Enabled: 'pending'
3624
+ VersionAdded: '0.87'
3625
+
3584
3626
  Style/RedundantBegin:
3585
3627
  Description: "Don't use begin blocks when they are not needed."
3586
3628
  StyleGuide: '#begin-implicit'
@@ -3924,7 +3966,7 @@ Style/SymbolLiteral:
3924
3966
  Style/SymbolProc:
3925
3967
  Description: 'Use symbols as procs instead of blocks when possible.'
3926
3968
  Enabled: true
3927
- SafeAutoCorrect: false
3969
+ Safe: false
3928
3970
  VersionAdded: '0.26'
3929
3971
  VersionChanged: '0.64'
3930
3972
  # A list of method names to be ignored by the check.
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "6.10.2".freeze # rubocop: disable Style/StringLiterals
3
- RUBOCOP_VERSION = '0.86.0'.freeze
2
+ VERSION = "6.11.4".freeze # rubocop: disable Style/StringLiterals
3
+ RUBOCOP_VERSION = '0.87.1'.freeze
4
4
  end
@@ -25,6 +25,8 @@ module RuboCop
25
25
  # # bad
26
26
  # ::Chef::Recipe.send(:include, Filebeat::Helpers)
27
27
  # ::Chef::Provider.send(:include, Filebeat::Helpers)
28
+ # ::Chef::Recipe.include Filebeat::Helpers
29
+ # ::Chef::Provider.include Filebeat::Helpers
28
30
  #
29
31
  # # good
30
32
  # ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
@@ -36,10 +38,18 @@ module RuboCop
36
38
  (send (const (const (cbase) :Chef) {:Recipe :Provider}) :send (sym :include) ... )
37
39
  PATTERN
38
40
 
41
+ def_node_matcher :legacy_class_includes?, <<-PATTERN
42
+ (send (const (const (cbase) :Chef) {:Recipe :Provider}) :include ... )
43
+ PATTERN
44
+
39
45
  def on_send(node)
40
46
  legacy_class_sends?(node) do
41
47
  add_offense(node, location: :expression, message: MSG, severity: :refactor)
42
48
  end
49
+
50
+ legacy_class_includes?(node) do
51
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
52
+ end
43
53
  end
44
54
 
45
55
  def autocorrect(node)
@@ -0,0 +1,56 @@
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
+ # Use ::File.exist?('/foo/bar') instead of the slower 'test -f /foo/bar' which requires shelling out
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # only_if 'test -f /bin/foo'
27
+ #
28
+ # # good
29
+ # only_if { ::File.exist?('bin/foo') }
30
+ #
31
+ class ConditionalUsingTest < Cop
32
+ MSG = "Use ::File.exist?('/foo/bar') instead of the slower 'test -f /foo/bar' which requires shelling out".freeze
33
+
34
+ def_node_matcher :resource_conditional?, <<~PATTERN
35
+ (send nil? {:not_if :only_if} $str )
36
+ PATTERN
37
+
38
+ def on_send(node)
39
+ resource_conditional?(node) do |conditional|
40
+ add_offense(node, location: :expression, message: MSG, severity: :refactor) if conditional.value.match?(/^test -[ef] \S*$/)
41
+ end
42
+ end
43
+
44
+ def autocorrect(node)
45
+ lambda do |corrector|
46
+ resource_conditional?(node) do |conditional|
47
+ new_string = "{ ::File.exist?('#{conditional.value.match(/^test -[ef] (\S*)$/)[1]}') }"
48
+ corrector.replace(conditional.loc.expression, new_string)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -27,18 +27,20 @@ module RuboCop
27
27
  # ::File.open('/proc/1/comm').chomp == 'systemd'
28
28
  # File.open('/proc/1/comm').gets.chomp == 'systemd'
29
29
  # File.open('/proc/1/comm').chomp == 'systemd'
30
- # File.exist?('/proc/1/comm') && File.open('/proc/1/comm').chomp == 'systemd'
31
- #
32
30
  # IO.read('/proc/1/comm').chomp == 'systemd'
33
31
  # IO.read('/proc/1/comm').gets.chomp == 'systemd'
34
32
  # ::IO.read('/proc/1/comm').chomp == 'systemd'
35
33
  # ::IO.read('/proc/1/comm').gets.chomp == 'systemd'
36
34
  # File.exist?('/proc/1/comm') && File.open('/proc/1/comm').chomp == 'systemd'
35
+ # only_if 'test -f /bin/systemctl && /bin/systemctl'
37
36
  #
38
37
  # # good
39
38
  # node['init_package'] == 'systemd'
39
+ # only_if { node['init_package'] == 'systemd' }
40
40
  #
41
- class NodeInitPackage < Cop
41
+ class NodeInitPackage < Base
42
+ extend RuboCop::Cop::AutoCorrector
43
+
42
44
  MSG = "Use node['init_package'] to check for systemd instead of reading the contents of '/proc/1/comm'".freeze
43
45
 
44
46
  def_node_matcher :file_reads_proc_1_comm?, <<-PATTERN
@@ -58,18 +60,24 @@ module RuboCop
58
60
  :== (str "systemd"))
59
61
  PATTERN
60
62
 
63
+ def_node_matcher :file_systemd_conditional?, <<~PATTERN
64
+ (send nil? {:not_if :only_if} $(str "test -f /bin/systemctl && /bin/systemctl"))
65
+ PATTERN
66
+
61
67
  def on_send(node)
62
68
  compare_init_system?(node) do
63
69
  # if there's a ::File.exist?('/proc/1/comm') check first we want to match that as well
64
70
  node = node.parent if node.parent&.and_type? && proc_1_comm_exists?(node.parent.conditions.first)
65
71
 
66
- add_offense(node, location: :expression, message: MSG, severity: :refactor)
72
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
73
+ corrector.replace(node, "node['init_package'] == 'systemd'")
74
+ end
67
75
  end
68
- end
69
76
 
70
- def autocorrect(node)
71
- lambda do |corrector|
72
- corrector.replace(node.loc.expression, "node['init_package'] == 'systemd'")
77
+ file_systemd_conditional?(node) do |conditional|
78
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
79
+ corrector.replace(conditional.loc.expression, "{ node['init_package'] == 'systemd' }")
80
+ end
73
81
  end
74
82
  end
75
83
  end
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright:: 2020, 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
+ module ChefStyle
22
+ # There is no need to wrap the recipe in parentheses when using the include_recipe helper.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # include_recipe('foo::bar')
28
+ #
29
+ # # good
30
+ # include_recipe 'foo::bar'
31
+ #
32
+ class IncludeRecipeWithParentheses < Base
33
+ extend RuboCop::Cop::AutoCorrector
34
+
35
+ MSG = 'There is no need to wrap the recipe in parentheses when using the include_recipe helper'.freeze
36
+
37
+ def_node_matcher :include_recipe?, <<-PATTERN
38
+ (send nil? :include_recipe $(str _))
39
+ PATTERN
40
+
41
+ def on_send(node)
42
+ include_recipe?(node) do |recipe|
43
+ return unless node.parenthesized?
44
+
45
+ # avoid chefspec: expect(chef_run).to include_recipe('foo')
46
+ return if node.parent&.send_type?
47
+
48
+ add_offense(node.loc.expression, message: MSG, severity: :refactor) do |corrector|
49
+ corrector.replace(node.loc.expression, "include_recipe #{recipe.source}")
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ 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.10.2
4
+ version: 6.11.4
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-07 00:00:00.000000000 Z
12
+ date: 2020-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.86.0
20
+ version: 0.87.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 0.86.0
27
+ version: 0.87.1
28
28
  description:
29
29
  email:
30
30
  - thom@chef.io
@@ -149,6 +149,7 @@ files:
149
149
  - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
150
150
  - lib/rubocop/cop/chef/modernize/chef_gem_nokogiri.rb
151
151
  - lib/rubocop/cop/chef/modernize/compile_time_resources.rb
152
+ - lib/rubocop/cop/chef/modernize/conditional_using_test.rb
152
153
  - lib/rubocop/cop/chef/modernize/cron_manage_resource.rb
153
154
  - lib/rubocop/cop/chef/modernize/databag_helpers.rb
154
155
  - lib/rubocop/cop/chef/modernize/default_action_initializer.rb
@@ -239,6 +240,7 @@ files:
239
240
  - lib/rubocop/cop/chef/style/comments_format.rb
240
241
  - lib/rubocop/cop/chef/style/file_mode.rb
241
242
  - lib/rubocop/cop/chef/style/immediate_notification_timing.rb
243
+ - lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb
242
244
  - lib/rubocop/cop/chef/style/negating_only_if.rb
243
245
  - lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb
244
246
  - lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb