cookstyle 8.3.0 → 8.5.0
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 +4 -4
- data/config/chefstyle.yml +4 -0
- data/config/cookstyle.yml +14 -0
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/cop/chef/correctness/empty_resource_guard.rb +104 -0
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 388c63af17bc8af6ccee78b056d4fb74972c443a91737363f54d4dc41b1e1042
|
4
|
+
data.tar.gz: 23310602f2fba3002f6d4853881f5a432025473ea8c368b33b23b1798659974b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf74fe8aab73053ef3c723cdecb8a6d5a077bcba200a5986b90e5116fca9c2cd64eebfb3736355642a58df3b2c3960b99b6b23f7bfb2e432b1bdfb62f9b398d0
|
7
|
+
data.tar.gz: aa8ae4575701d1d4dae566277c429402c39f0785b5d36789d7d2740c91feafbaa3a179c3ab940e7caecfb17f4921fa5598985ff8e945b4adbed11e48878ee860
|
data/config/chefstyle.yml
CHANGED
@@ -868,6 +868,10 @@ Lint/UselessDefaultValueArgument:
|
|
868
868
|
Style/CollectionQuerying:
|
869
869
|
Enabled: true
|
870
870
|
|
871
|
+
# use `include?(element)` instead of `intersect?([element])`
|
872
|
+
Style/ArrayIntersectWithSingleElement:
|
873
|
+
Enabled: true
|
874
|
+
|
871
875
|
Chef/Deprecations/Ruby27KeywordArgumentWarnings:
|
872
876
|
Description: Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings.
|
873
877
|
Enabled: true
|
data/config/cookstyle.yml
CHANGED
@@ -391,6 +391,16 @@ Chef/Correctness/DnfPackageAllowDowngrades:
|
|
391
391
|
- '**/metadata.rb'
|
392
392
|
- '**/Berksfile'
|
393
393
|
|
394
|
+
Chef/Correctness/EmptyResourceGuard:
|
395
|
+
Description: Resource guards (not_if/only_if) should not be empty strings as empty strings will always evaluate to true.
|
396
|
+
StyleGuide: 'chef_correctness_emptyresourceguard'
|
397
|
+
Enabled: true
|
398
|
+
VersionAdded: '8.4.0'
|
399
|
+
Exclude:
|
400
|
+
- '**/attributes/*.rb'
|
401
|
+
- '**/metadata.rb'
|
402
|
+
- '**/Berksfile'
|
403
|
+
|
394
404
|
Chef/Correctness/ChefApplicationFatal:
|
395
405
|
Description: Use raise to force Chef Infra Client to fail instead of using Chef::Application.fatal
|
396
406
|
StyleGuide: 'chef_correctness_chefapplicationfatal'
|
@@ -3287,3 +3297,7 @@ Lint/UselessDefaultValueArgument:
|
|
3287
3297
|
# use helpers like .any?, .none?, and .one? instead of using count on collections which is much slower
|
3288
3298
|
Style/CollectionQuerying:
|
3289
3299
|
Enabled: true
|
3300
|
+
|
3301
|
+
# use `include?(element)` instead of `intersect?([element])`
|
3302
|
+
Style/ArrayIntersectWithSingleElement:
|
3303
|
+
Enabled: true
|
data/lib/cookstyle/version.rb
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2024, Chef Software Inc.
|
4
|
+
# Author:: Sumedha (<https://github.com/sumedha-lolur>)
|
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 Correctness
|
22
|
+
# Resource guards (not_if/only_if) should not be empty strings as empty strings will always evaluate to true.
|
23
|
+
# This will cause confusion in your cookbooks as the guard will always pass.
|
24
|
+
#
|
25
|
+
# Empty strings in Ruby are "truthy", which means:
|
26
|
+
# - `only_if ''` will ALWAYS execute the resource (guard always passes)
|
27
|
+
# - `not_if ''` will NEVER execute the resource (guard always blocks)
|
28
|
+
#
|
29
|
+
# This behavior is usually unintended and can lead to resources running when they shouldn't
|
30
|
+
# or never running when they should.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
#
|
34
|
+
# ### incorrect
|
35
|
+
# template '/etc/foo' do
|
36
|
+
# mode '0644'
|
37
|
+
# source 'foo.erb'
|
38
|
+
# only_if '' # This will always be true - resource always executes
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# cookbook_file '/logs/foo/error.log' do
|
42
|
+
# source 'error.log'
|
43
|
+
# not_if { '' } # This will always be true - resource never executes
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# service 'apache2' do
|
47
|
+
# action :restart
|
48
|
+
# only_if { '' } # Block form also problematic
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# ### correct
|
52
|
+
# template '/etc/foo' do
|
53
|
+
# mode '0644'
|
54
|
+
# source 'foo.erb'
|
55
|
+
# only_if 'test -f /etc/foo' # Actual shell command
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# cookbook_file '/logs/foo/error.log' do
|
59
|
+
# source 'error.log'
|
60
|
+
# not_if { ::File.exist?('/logs/foo/error.log') } # Proper Ruby expression
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# service 'apache2' do
|
64
|
+
# action :restart
|
65
|
+
# only_if { node['platform'] == 'ubuntu' } # Meaningful condition
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# # Or simply remove the guard if no condition is needed
|
69
|
+
# package 'curl' do
|
70
|
+
# action :install
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
class EmptyResourceGuard < Base
|
74
|
+
MSG = 'Resource guards (not_if/only_if) should not be empty strings as empty strings will always evaluate to true.'
|
75
|
+
RESTRICT_ON_SEND = [:not_if, :only_if].freeze
|
76
|
+
|
77
|
+
def_node_matcher :empty_string_guard?, <<-PATTERN
|
78
|
+
(send nil? {:not_if :only_if} (str #empty_string?))
|
79
|
+
PATTERN
|
80
|
+
|
81
|
+
def_node_matcher :empty_string_block_guard?, <<-PATTERN
|
82
|
+
(block (send nil? {:not_if :only_if}) (args) (str #empty_string?))
|
83
|
+
PATTERN
|
84
|
+
|
85
|
+
def empty_string?(str)
|
86
|
+
str.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
def on_send(node)
|
90
|
+
empty_string_guard?(node) do
|
91
|
+
add_offense(node, severity: :refactor)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def on_block(node)
|
96
|
+
empty_string_block_guard?(node) do
|
97
|
+
add_offense(node, severity: :refactor)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookstyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom May
|
8
8
|
- Tim Smith
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2025-09-25 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rubocop
|
@@ -16,14 +17,15 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - '='
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
20
|
+
version: 1.81.0
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - '='
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
27
|
+
version: 1.81.0
|
28
|
+
description:
|
27
29
|
email:
|
28
30
|
- thom@chef.io
|
29
31
|
- tsmith84@gmail.com
|
@@ -52,6 +54,7 @@ files:
|
|
52
54
|
- lib/rubocop/cop/chef/correctness/chef_application_fatal.rb
|
53
55
|
- lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb
|
54
56
|
- lib/rubocop/cop/chef/correctness/dnf_package_allow_downgrades.rb
|
57
|
+
- lib/rubocop/cop/chef/correctness/empty_resource_guard.rb
|
55
58
|
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
|
56
59
|
- lib/rubocop/cop/chef/correctness/invalid_cookbook_name.rb
|
57
60
|
- lib/rubocop/cop/chef/correctness/invalid_default_action.rb
|
@@ -322,6 +325,7 @@ metadata:
|
|
322
325
|
source_code_uri: https://github.com/chef/cookstyle
|
323
326
|
documentation_uri: https://docs.chef.io/workstation/cookstyle/
|
324
327
|
bug_tracker_uri: https://github.com/chef/cookstyle/issues
|
328
|
+
post_install_message:
|
325
329
|
rdoc_options: []
|
326
330
|
require_paths:
|
327
331
|
- lib
|
@@ -336,7 +340,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
336
340
|
- !ruby/object:Gem::Version
|
337
341
|
version: '0'
|
338
342
|
requirements: []
|
339
|
-
rubygems_version: 3.
|
343
|
+
rubygems_version: 3.3.27
|
344
|
+
signing_key:
|
340
345
|
specification_version: 4
|
341
346
|
summary: Cookstyle is a code linting tool that helps you to write better Chef Infra
|
342
347
|
cookbooks by detecting and automatically correcting style, syntax, and logic mistakes
|