Skip to content

Commit be2c3e6

Browse files
committed
(PUP-11993) Style/RedundantCondition
This commit enables the Style/RedundantCondition cop and fixes 20 autocorrectable offenses.
1 parent d954105 commit be2c3e6

File tree

14 files changed

+20
-57
lines changed

14 files changed

+20
-57
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -646,23 +646,6 @@ Style/OptionalBooleanParameter:
646646
Style/PreferredHashMethods:
647647
Enabled: false
648648

649-
# This cop supports safe auto-correction (--auto-correct).
650-
Style/RedundantCondition:
651-
Exclude:
652-
- 'ext/windows/service/daemon.rb'
653-
- 'lib/puppet/application/describe.rb'
654-
- 'lib/puppet/environments.rb'
655-
- 'lib/puppet/external/dot.rb'
656-
- 'lib/puppet/graph/simple_graph.rb'
657-
- 'lib/puppet/indirector/request.rb'
658-
- 'lib/puppet/parser/templatewrapper.rb'
659-
- 'lib/puppet/provider/package/blastwave.rb'
660-
- 'lib/puppet/provider/package/pkgutil.rb'
661-
- 'lib/puppet/provider/package/portage.rb'
662-
- 'lib/puppet/type.rb'
663-
- 'lib/puppet/util/command_line/trollop.rb'
664-
- 'lib/puppet/util/inifile.rb'
665-
666649
# This cop supports safe auto-correction (--auto-correct).
667650
Style/RedundantConditional:
668651
Exclude:

ext/windows/service/daemon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def parse_log_level(puppet_path, cmdline_debug)
182182
loglevel = :notice
183183
end
184184

185-
LEVELS.index(cmdline_debug ? cmdline_debug : loglevel.to_sym)
185+
LEVELS.index(cmdline_debug || loglevel.to_sym)
186186
end
187187

188188
private

lib/puppet/application/describe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def wrap(txt, opts)
1111
return "" unless txt && !txt.empty?
1212

1313
work = (opts[:scrub] ? scrub(txt) : txt)
14-
indent = (opts[:indent] ? opts[:indent] : 0)
14+
indent = (opts[:indent] || 0)
1515
textLen = @width - indent
1616
patt = Regexp.new("\\A(.{0,#{textLen}})[ \n]")
1717
prefix = " " * indent

lib/puppet/environments.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ module EnvironmentLoader
3535
# @!macro loader_get_or_fail
3636
def get!(name)
3737
environment = get(name)
38-
if environment
39-
environment
40-
else
41-
raise EnvironmentNotFound, name
42-
end
38+
environment || raise(EnvironmentNotFound, name)
4339
end
4440

4541
def clear_all

lib/puppet/external/dot.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class DOTSimpleElement
119119
attr_accessor :name
120120

121121
def initialize(params = {})
122-
@label = params['name'] ? params['name'] : ''
122+
@label = params['name'] || ''
123123
end
124124

125125
def to_s
@@ -135,8 +135,8 @@ class DOTElement < DOTSimpleElement
135135

136136
def initialize(params = {}, option_list = [])
137137
super(params)
138-
@name = params['name'] ? params['name'] : nil
139-
@parent = params['parent'] ? params['parent'] : nil
138+
@name = params['name'] || nil
139+
@parent = params['parent'] || nil
140140
@options = {}
141141
option_list.each { |i|
142142
@options[i] = params[i] if params[i]
@@ -161,7 +161,7 @@ class DOTPort < DOTSimpleElement
161161

162162
def initialize(params = {})
163163
super(params)
164-
@name = params['label'] ? params['label'] : ''
164+
@name = params['label'] || ''
165165
end
166166

167167
def to_s
@@ -174,7 +174,7 @@ def to_s
174174
class DOTNode < DOTElement
175175
def initialize(params = {}, option_list = NODE_OPTS)
176176
super(params, option_list)
177-
@ports = params['ports'] ? params['ports'] : []
177+
@ports = params['ports'] || []
178178
end
179179

180180
def each_port
@@ -233,7 +233,7 @@ def stringify(s)
233233
class DOTSubgraph < DOTElement
234234
def initialize(params = {}, option_list = GRAPH_OPTS)
235235
super(params, option_list)
236-
@nodes = params['nodes'] ? params['nodes'] : []
236+
@nodes = params['nodes'] || []
237237
@dot_string = 'graph'
238238
end
239239

@@ -287,8 +287,8 @@ class DOTEdge < DOTElement
287287

288288
def initialize(params = {}, option_list = EDGE_OPTS)
289289
super(params, option_list)
290-
@from = params['from'] ? params['from'] : nil
291-
@to = params['to'] ? params['to'] : nil
290+
@from = params['from'] || nil
291+
@to = params['to'] || nil
292292
end
293293

294294
def edge_link

lib/puppet/graph/simple_graph.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def path_between(f, t)
449449
# which match +dot+ properties will be used as well.
450450
def to_dot_graph(params = {})
451451
params['name'] ||= self.class.name.tr(':', '_')
452-
fontsize = params['fontsize'] ? params['fontsize'] : '8'
452+
fontsize = params['fontsize'] || '8'
453453
graph = (directed? ? DOT::DOTDigraph : DOT::DOTSubgraph).new(params)
454454
edge_klass = directed? ? DOT::DOTDirectedEdge : DOT::DOTEdge
455455
vertices.each do |v|

lib/puppet/indirector/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def to_hash
140140
end
141141

142142
def description
143-
return(uri ? uri : "/#{indirection_name}/#{key}")
143+
return(uri || "/#{indirection_name}/#{key}")
144144
end
145145

146146
def remote?

lib/puppet/parser/templatewrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ def result(string = nil)
100100
end
101101

102102
def to_s
103-
"template[#{(@__file__ ? @__file__ : "inline")}]"
103+
"template[#{(@__file__ || "inline")}]"
104104
end
105105
end

lib/puppet/provider/package/blastwave.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ def latest
9595

9696
def query
9797
hash = self.class.blastlist(:justme => @resource[:name])
98-
if hash
99-
hash
100-
else
101-
{ :ensure => :absent }
102-
end
98+
hash || { :ensure => :absent }
10399
end
104100

105101
# Remove the old package, and install the new one

lib/puppet/provider/package/pkgutil.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,7 @@ def latest
172172

173173
def query
174174
hash = pkgsingle(@resource)
175-
if hash
176-
hash
177-
else
178-
{ :ensure => :absent }
179-
end
175+
hash || { :ensure => :absent }
180176
end
181177

182178
def update

0 commit comments

Comments
 (0)