Skip to content

Commit 4bc011a

Browse files
committed
(CONT-803) Rubocop Unsafe Auto Fixes 6-7
- Style/StringConcatenation - Style/SymbolProc
1 parent f91d02d commit 4bc011a

File tree

8 files changed

+19
-39
lines changed

8 files changed

+19
-39
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,3 @@ Style/MixinUsage:
162162
Style/OptionalBooleanParameter:
163163
Exclude:
164164
- 'spec/support/filesystem_helpers.rb'
165-
166-
# Offense count: 14
167-
# This cop supports unsafe autocorrection (--autocorrect-all).
168-
# Configuration parameters: Mode.
169-
Style/StringConcatenation:
170-
Exclude:
171-
- 'lib/puppet/provider/vcsrepo.rb'
172-
- 'lib/puppet/provider/vcsrepo/cvs.rb'
173-
- 'lib/puppet/provider/vcsrepo/p4.rb'
174-
- 'spec/unit/puppet/provider/vcsrepo/git_spec.rb'
175-
- 'spec/unit/puppet/provider/vcsrepo/p4_spec.rb'
176-
177-
# Offense count: 5
178-
# This cop supports unsafe autocorrection (--autocorrect-all).
179-
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
180-
# AllowedMethods: define_method
181-
Style/SymbolProc:
182-
Exclude:
183-
- 'lib/puppet/provider/vcsrepo/dummy.rb'
184-
- 'lib/puppet/provider/vcsrepo/git.rb'

lib/puppet/provider/vcsrepo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def at_path # :nodoc:
5656
end
5757

5858
def tempdir
59-
@tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path)))
59+
@tempdir ||= File.join(Dir.tmpdir, "vcsrepo-#{Digest::MD5.hexdigest(@resource.value(:path))}")
6060
end
6161

6262
# If the resource has a umask, then run the block with that umask; otherwise,

lib/puppet/provider/vcsrepo/cvs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ def update_owner
140140

141141
def runcvs(*args)
142142
if @resource.value(:cvs_rsh)
143-
Puppet.debug 'Using CVS_RSH = ' + @resource.value(:cvs_rsh)
143+
Puppet.debug "Using CVS_RSH = #{@resource.value(:cvs_rsh)}"
144144
e = { CVS_RSH: @resource.value(:cvs_rsh) }
145145
else
146146
e = {}
147147
end
148148

149149
if @resource.value(:user) && @resource.value(:user) != Facter['id'].value
150-
Puppet.debug 'Running as user ' + @resource.value(:user)
150+
Puppet.debug "Running as user #{@resource.value(:user)}"
151151
Puppet::Util::Execution.execute([:cvs, *args], uid: @resource.value(:user), custom_environment: e, combine: true, failonfail: true)
152152
else
153153
Puppet::Util::Execution.execute([:cvs, *args], custom_environment: e, combine: true, failonfail: true)

lib/puppet/provider/vcsrepo/dummy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def working_copy_exists?
1212
providers = begin
13-
@resource.class.providers.map { |x| x.to_s }.sort.reject { |x| x == 'dummy' }.join(', ')
13+
@resource.class.providers.map(&:to_s).sort.reject { |x| x == 'dummy' }.join(', ')
1414
rescue StandardError
1515
'none'
1616
end

lib/puppet/provider/vcsrepo/git.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def tag_revision?(revision = @resource.value(:revision))
471471

472472
# @!visibility private
473473
def branches
474-
at_path { git_with_identity('branch', '--no-color', '-a') }.tr('*', ' ').split(%r{\n}).map { |line| line.strip }
474+
at_path { git_with_identity('branch', '--no-color', '-a') }.tr('*', ' ').split(%r{\n}).map(&:strip)
475475
end
476476

477477
# git < 2.4 returns 'detached from'
@@ -486,7 +486,7 @@ def on_branch?
486486

487487
# @!visibility private
488488
def tags
489-
at_path { git_with_identity('tag', '-l') }.split(%r{\n}).map { |line| line.strip }
489+
at_path { git_with_identity('tag', '-l') }.split(%r{\n}).map(&:strip)
490490
end
491491

492492
# @!visibility private
@@ -595,8 +595,8 @@ def safe_directories
595595
begin
596596
d = git_with_identity(*args) || ''
597597
d.split('\n')
598-
.reject { |v| v.empty? }
599-
.map { |v| v.chomp }
598+
.reject(&:empty?)
599+
.map(&:chomp)
600600
rescue Puppet::ExecutionFailure
601601
[]
602602
end

lib/puppet/provider/vcsrepo/p4.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def working_copy_exists?
2828

2929
# Check if workspace is setup
3030
args = ['where']
31-
args.push(@resource.value(:path) + '/...')
31+
args.push("#{@resource.value(:path)}/...")
3232
hash = p4(args, raise: false)
3333

3434
(hash['code'] != 'error')
@@ -88,7 +88,7 @@ def revision=(desired)
8888

8989
def source
9090
args = ['where']
91-
args.push(@resource.value(:path) + '/...')
91+
args.push("#{@resource.value(:path)}/...")
9292
hash = p4(args, raise: false)
9393

9494
hash['depotFile']
@@ -126,7 +126,7 @@ def client_name
126126
# default (generated) client name
127127
path = @resource.value(:path)
128128
host = Facter.value('hostname')
129-
default = 'puppet-' + Digest::MD5.hexdigest(path + host)
129+
default = "puppet-#{Digest::MD5.hexdigest(path + host)}"
130130

131131
# check config for client name
132132
set_client = nil
@@ -159,11 +159,11 @@ def create_client(client)
159159
if source
160160
parts = source.split(%r{/})
161161
if parts && parts.length >= 4
162-
source = '//' + parts[2] + '/' + parts[3]
162+
source = "//#{parts[2]}/#{parts[3]}"
163163
streams = p4(['streams', source], raise: false)
164164
if streams['code'] == 'stat'
165165
hash['Stream'] = streams['Stream']
166-
notice 'Streams' + streams['Stream'].inspect
166+
notice "Streams#{streams['Stream'].inspect}"
167167
end
168168
end
169169
end
@@ -235,7 +235,7 @@ def p4(args, options = {})
235235
Open3.popen3(config, cmd_str) do |i, o, e, t|
236236
# Send input stream if provided
237237
if opts[:input]
238-
Puppet.debug "input:\n" + opts[:input]
238+
Puppet.debug "input:\n#{opts[:input]}"
239239
i.write opts[:input]
240240
i.close
241241
end

spec/unit/puppet/provider/vcsrepo/git_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def branch_a_list(include_branch = nil?)
77
<<BRANCHES
88
end
99
#{'* main' unless include_branch.nil?}
10-
#{'* ' + include_branch if include_branch}
10+
#{"* #{include_branch}" if include_branch}
1111
remote/origin/main
1212
remote/origin/foo
1313

spec/unit/puppet/provider/vcsrepo/p4_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
expect(provider).to receive(:p4).with(['client', '-o', 'client_ws1']).and_return({})
3232
expect(provider).to receive(:p4).with(['client', '-i'], spec)
33-
expect(provider).to receive(:p4).with(['sync', resource.value(:source) + '@' + resource.value(:revision)])
33+
expect(provider).to receive(:p4).with(['sync', "#{resource.value(:source)}@#{resource.value(:revision)}"])
3434
provider.create
3535
end
3636
end
@@ -53,7 +53,7 @@
5353

5454
path = resource.value(:path)
5555
host = Facter.value('hostname')
56-
default = 'puppet-' + Digest::MD5.hexdigest(path + host)
56+
default = "puppet-#{Digest::MD5.hexdigest(path + host)}"
5757

5858
expect(provider).to receive(:p4).with(['client', '-o', default]).and_return({})
5959
expect(provider).to receive(:p4).with(['client', '-i'], spec)
@@ -75,15 +75,15 @@
7575
describe 'checking existence' do
7676
it 'checks for the directory' do
7777
expect(provider).to receive(:p4).with(['info'], marshal: false).and_return({})
78-
expect(provider).to receive(:p4).with(['where', resource.value(:path) + '/...'], raise: false).and_return({})
78+
expect(provider).to receive(:p4).with(['where', "#{resource.value(:path)}/..."], raise: false).and_return({})
7979
provider.exists?
8080
end
8181
end
8282

8383
describe 'checking the source property' do
8484
it "runs 'p4 where'" do
8585
resource[:source] = '//public/something'
86-
expect(provider).to receive(:p4).with(['where', resource.value(:path) + '/...'],
86+
expect(provider).to receive(:p4).with(['where', "#{resource.value(:path)}/..."],
8787
raise: false).and_return('depotFile' => '//public/something')
8888
expect(provider.source).to eq(resource.value(:source))
8989
end

0 commit comments

Comments
 (0)