-
-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix all remaining rubocop violations #241
Changes from 3 commits
8504493
865401d
4f1fd3f
3f6cef9
27af372
7d6ff09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,11 @@ def self.pearlist(hash) | |
pearhash[:provider] = :pear | ||
pearhash | ||
end | ||
else | ||
if pearhash = pearsplit(set, channel) # rubocop:disable Lint/AssignmentInCondition | ||
pearhash[:provider] = :pear | ||
pearhash | ||
end | ||
elsif pearhash = pearsplit(set, channel) # rubocop:disable Lint/AssignmentInCondition | ||
pearhash[:provider] = :pear | ||
pearhash | ||
end | ||
end.reject { |p| p.nil? } | ||
end.reject(&:nil?) | ||
|
||
rescue Puppet::ExecutionFailure => detail | ||
raise Puppet::Error, format('Could not list pears: %s', detail) | ||
|
@@ -87,12 +85,10 @@ def install(useversion = true) | |
|
||
command << if @resource[:source] | ||
@resource[:source] | ||
elsif ([email protected](:ensure).is_a? Symbol) && useversion | ||
"#{@resource[:name]}-#{@resource.should(:ensure)}" | ||
else | ||
if ([email protected](:ensure).is_a? Symbol) && useversion | ||
"#{@resource[:name]}-#{@resource.should(:ensure)}" | ||
else | ||
@resource[:name] | ||
end | ||
@resource[:name] | ||
end | ||
|
||
pearcmd(*command) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,19 +20,17 @@ def self.pecllist(hash) | |
begin | ||
list = execute(command).split("\n").map do |set| | ||
if hash[:justme] | ||
if %r{^#{hash[:justme]}$}i.match(set) | ||
if %r{^#{hash[:justme]}$}i =~ set | ||
if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these conditionals be merged into one if (to avoid nesting)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good spot. It certainly looks like it, doesn't it? Lets look at the original code before any rubocop and refactoring started... https://github.com/voxpupuli/puppet-php/blob/4.0.0-beta1/lib/puppet/provider/package/pear.rb#L29 So assuming 6bbdc78 was correct and It's a real shame there are no spec tests covering this code... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two versions should be functionally equivalent, as a non-branching if returns nil in Ruby. I guess the real question is if this: if %r{^#{hash[:justme]}$}i =~ set
if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition
peclhash[:provider] = :peclcmd
peclhash
end
end is more readable than: if %r{^#{hash[:justme]}$}i =~ set &&
peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition
peclhash[:provider] = :peclcmd
peclhash
end btw: Are you sure using a disable comment everywhere were you want to use assignment in a condition is the best way to do it? Rubocop also allows assignment in condition if it is wrapped in parentheses, like so: if %r{^#{hash[:justme]}$}i =~ set &&
(peclhash = peclsplit(set))
peclhash[:provider] = :peclcmd
peclhash
end |
||
peclhash[:provider] = :peclcmd | ||
peclhash | ||
end | ||
end | ||
else | ||
if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition | ||
peclhash[:provider] = :peclcmd | ||
peclhash | ||
end | ||
elsif peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition | ||
peclhash[:provider] = :peclcmd | ||
peclhash | ||
end | ||
end.reject { |p| p.nil? } | ||
end.reject(&:nil?) | ||
rescue Puppet::ExecutionFailure => detail | ||
raise Puppet::Error, format('Could not list pecls: %s', detail) | ||
end | ||
|
@@ -79,13 +77,11 @@ def install(useversion = true) | |
|
||
if @resource[:source] | ||
command << @resource[:source] | ||
elsif ([email protected](:ensure).is_a? Symbol) && useversion | ||
command << '-f' | ||
command << "#{peclname}-#{@resource.should(:ensure)}" | ||
else | ||
if ([email protected](:ensure).is_a? Symbol) && useversion | ||
command << '-f' | ||
command << "#{peclname}-#{@resource.should(:ensure)}" | ||
else | ||
command << peclname | ||
end | ||
command << peclname | ||
end | ||
|
||
if pipe == @resource[:pipe] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if this could actually be replaced with
end.compact
, but was too scared!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array#compact
should work, the only difference to this manual solution I could find was thatcompact
will only remove actualnil
, whereas this will work on classes that define a custom#nil?
(I see no reason why that would be something you want though).