Skip to content

Commit

Permalink
(CONT-803) Rubocop Unsafe Auto Fixes 4-5
Browse files Browse the repository at this point in the history
- Style/NumericPredicate
- Style/SlicingWithRange
  • Loading branch information
david22swan committed Apr 19, 2023
1 parent 5d249cc commit f91d02d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
16 changes: 0 additions & 16 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,29 +156,13 @@ Style/MixinUsage:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/puppet/provider/vcsrepo/git.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'spec/support/filesystem_helpers.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- 'lib/puppet/provider/vcsrepo/cvs.rb'
- 'lib/puppet/provider/vcsrepo/svn.rb'

# Offense count: 14
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/vcsrepo/cvs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def revision
if File.exist?(tag_file)
contents = File.read(tag_file).strip
# NOTE: Doesn't differentiate between N and T entries
@rev = contents[1..-1]
@rev = contents[1..]
else
@rev = 'HEAD'
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/vcsrepo/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def bare_git_config_exists?
# @!visibility private
def clone_repository(source, path)
args = ['clone']
if @resource.value(:depth) && @resource.value(:depth).to_i > 0
if @resource.value(:depth)&.to_i&.positive?
args.push('--depth', @resource.value(:depth).to_s)
args.push('--branch', @resource.value(:revision).to_s) if @resource.value(:revision) && !@resource.value(:branch)
end
Expand Down Expand Up @@ -415,7 +415,7 @@ def commits?
rescue Puppet::ExecutionFailure
commits = 0
end
return commits > 0
return commits.positive?
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/vcsrepo/svn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def sensitive?
def get_includes(directory)
at_path do
args = buildargs.push('info', directory)
return directory[2..-1].gsub(File::SEPARATOR, '/') if svn_wrapper(*args)[%r{^Depth:\s+(\w+)}m, 1] != 'empty'
return directory[2..].gsub(File::SEPARATOR, '/') if svn_wrapper(*args)[%r{^Depth:\s+(\w+)}m, 1] != 'empty'

Dir.entries(directory).map { |entry|
next if SKIP_DIRS.include?(entry)
Expand All @@ -181,7 +181,7 @@ def get_includes(directory)
if File.directory?(entry)
get_includes(entry)
elsif File.file?(entry)
entry[2..-1].gsub(File::SEPARATOR, '/')
entry[2..].gsub(File::SEPARATOR, '/')
end
}.flatten.compact!
end
Expand Down

2 comments on commit f91d02d

@Pakbon
Copy link

@Pakbon Pakbon commented on f91d02d Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke cvs.rb with a simple and avoidable syntax error on line 77
@rev = contents[1..]

@kenyon
Copy link

@kenyon kenyon commented on f91d02d Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke cvs.rb with a simple and avoidable syntax error on line 77 @rev = contents[1..]

@Pakbon if you get a syntax error, you're using this on a puppet version with too old of a ruby. See #624.

Please sign in to comment.