Skip to content

Commit 0e978fa

Browse files
committed
Rubocop fixes after enabling new cops
1 parent 4bc8204 commit 0e978fa

30 files changed

+116
-104
lines changed

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ require: rubocop-performance
22

33
AllCops:
44
TargetRubyVersion: 3.0
5+
NewCops: enable
56

67
Layout/LineLength:
78
Max: 99
@@ -14,3 +15,9 @@ Style/RegexpLiteral:
1415

1516
Metrics/ClassLength:
1617
Enabled: false
18+
19+
Lint/MissingSuper:
20+
Enabled: false
21+
22+
Style/OptionalBooleanParameter:
23+
Enabled: false

lib/ohloh_scm/activity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(core)
1212
end
1313

1414
def log_filename
15-
File.join(temp_folder, url.gsub(/\W/, '') + '.log')
15+
File.join(temp_folder, "#{url.gsub(/\W/, '')}.log")
1616
end
1717

1818
def tags; end

lib/ohloh_scm/bzr/activity.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def commits(opts = {})
4545
a = OhlohScm::BzrXmlParser.parse(log)
4646

4747
if after && (i = a.index { |commit| commit.token == after })
48-
a[(i + 1)..-1]
48+
a[(i + 1)..]
4949
else
5050
a
5151
end
@@ -136,24 +136,24 @@ def rev_list_command(opts = {})
136136
# +after+. However, bzr doesn't work that way; it returns
137137
# everything after and INCLUDING +after+. Therefore, consumers
138138
# of this file should check for and reject the duplicate commit.
139-
def safe_open_log_file(opts = {})
139+
def safe_open_log_file(opts = {}, &block)
140140
return '' if opts[:after] && opts[:after] == head_token
141141

142-
open_log_file(opts) { |io| yield io }
142+
open_log_file(opts, &block)
143143
end
144144

145-
def open_log_file(opts = {})
145+
def open_log_file(opts = {}, &block)
146146
cmd = "#{rev_list_command(opts)} -v > #{log_filename}"
147147
run cmd
148-
File.open(log_filename, 'r') { |io| yield io }
148+
File.open(log_filename, 'r', &block)
149149
ensure
150150
File.delete(log_filename) if File.exist?(log_filename)
151151
end
152152

153153
# Ohloh tracks only files, not directories. This function removes directories
154154
# from the commit diffs.
155155
def remove_directories(commit)
156-
commit.diffs.delete_if { |d| d.path[-1..-1] == '/' }
156+
commit.diffs.delete_if { |d| d.path[-1..] == '/' }
157157
commit
158158
end
159159

@@ -164,11 +164,11 @@ def cat(revision, path)
164164
# Bzr doesn't like it when the filename includes a colon
165165
# Also, fix the case where the filename includes a single quote
166166
def escape(path)
167-
path.gsub(/[:]/) { |c| '\\' + c }.gsub("'", "''")
167+
path.gsub(/:/) { |c| "\\#{c}" }.gsub("'", "''")
168168
end
169169

170170
def tag_strings
171-
run("cd '#{url}' && bzr tags").split(/\n/)
171+
run("cd '#{url}' && bzr tags").split("\n")
172172
end
173173

174174
def time_string(rev)

lib/ohloh_scm/bzr/validation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def validate_server_connection
1111
end
1212

1313
def public_url_regex
14-
%r{^(((http|https|bzr)://(\w+@)?[\w\-\.]+(:\d+)?/)|(lp:[\w\-\.\~]))[\w\-\./\~\+]*$}
14+
%r{^(((http|https|bzr)://(\w+@)?[\w\-.]+(:\d+)?/)|(lp:[\w\-.~]))[\w\-./~+]*$}
1515
end
1616
end
1717
end

lib/ohloh_scm/commit.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ class Commit
2424
attr_accessor :author_name, :author_email, :author_date,
2525
:committer_name, :committer_email, :committer_date
2626

27-
attr_accessor :message
28-
29-
attr_accessor :diffs
27+
attr_accessor :message, :diffs
3028

3129
# The token is used to uniquely identify a commit, and can be any type of
3230
# adapter-specific data.
@@ -46,7 +44,7 @@ class Commit
4644
attr_accessor :directories
4745

4846
def initialize(params = {})
49-
params.each { |k, v| send(k.to_s + '=', v) if respond_to?(k.to_s + '=') }
47+
params.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
5048
end
5149
end
5250
end

lib/ohloh_scm/cvs/activity.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Cvs
55
class Activity < OhlohScm::Activity
66
def tags
77
cmd = "cvs -Q -d #{url} rlog -h #{scm.branch_name} | awk -F\"[.:]\" '/^\\t/&&$(NF-1)!=0'"
8-
tag_strings = run(cmd).split(/\n/)
8+
tag_strings = run(cmd).split("\n")
99
tag_strings.map do |tag_string|
1010
tag_name, version = tag_string.split(':')
1111
[tag_name.delete("\t"), version.strip]
@@ -45,7 +45,7 @@ def commits(opts = {})
4545
next unless result[i].token&.match?(re) # We found the match for after
4646
return [] if i == result.size - 1 # There aren't any new commits.
4747

48-
return result[i + 1..-1]
48+
return result[i + 1..]
4949
end
5050

5151
# Something bad is going on: 'after' does not match any timestamp in the rlog.
@@ -72,7 +72,7 @@ def export_tag(dest_dir, tag_name = 'HEAD')
7272
def ensure_host_key
7373
return if protocol != :ext
7474

75-
ensure_key_file = File.dirname(__FILE__) + '/../../../../bin/ensure_key'
75+
ensure_key_file = "#{File.dirname(__FILE__)}/../../../../bin/ensure_key"
7676
cmd = "#{ensure_key_file} '#{host}'"
7777
run_with_err(cmd)
7878
end
@@ -92,12 +92,12 @@ def ensure_host_key
9292
# that predate the requested time.
9393
# That's better than missing revisions completely! Just be sure to check for duplicates.
9494
# rubocop:disable Metrics/AbcSize
95-
def open_log_file(opts = {})
95+
def open_log_file(opts = {}, &block)
9696
ensure_host_key
9797
status.lock?
9898
run "cvsnt -d #{url} rlog #{opt_branch} #{opt_time(opts[:after])} '#{scm.branch_name}'"\
9999
" | #{string_encoder_path} > #{rlog_filename}"
100-
File.open(rlog_filename, 'r') { |file| yield file }
100+
File.open(rlog_filename, 'r', &block)
101101
ensure
102102
File.delete(rlog_filename) if File.exist?(rlog_filename)
103103
end
@@ -113,7 +113,7 @@ def opt_time(after = nil)
113113
end
114114

115115
def rlog_filename
116-
File.join(temp_folder, (url + scm.branch_name.to_s).gsub(/\W/, '') + '.rlog')
116+
File.join(temp_folder, "#{(url + scm.branch_name.to_s).gsub(/\W/, '')}.rlog")
117117
end
118118

119119
# Converts a CVS time string to a Ruby Time object
@@ -128,9 +128,9 @@ def parse_time(token)
128128
# returns the host this adapter is connecting to
129129
def host
130130
@host ||= begin
131-
url =~ /@([^:]*):/
132-
Regexp.last_match(1)
133-
end
131+
url =~ /@([^:]*):/
132+
Regexp.last_match(1)
133+
end
134134
end
135135

136136
# returns the protocol this adapter connects with

lib/ohloh_scm/cvs/scm.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def checkout(rev, local_directory)
99
opt_d = rev.token ? "-D'#{rev.token}Z'" : ''
1010

1111
activity.ensure_host_key
12-
if File.exist?(local_directory + '/CVS/Root')
12+
if File.exist?("#{local_directory}/CVS/Root")
1313
# We already have a local enlistment, so do a quick update.
1414
if !rev.directories.empty?
1515
build_ordered_directory_list(rev.directories).each do |d|
@@ -105,7 +105,7 @@ def trim_directory(dir)
105105
# For example, if url = ':pserver:anonymous:@moodle.cvs.sourceforge.net:/cvsroot/moodle'
106106
# and module = 'contrib', then the directory prefix = '/cvsroot/moodle/contrib/'
107107
# If not remote, just leave the directory name as-is
108-
root ? dir[root.length..-1] : dir
108+
root ? dir[root.length..] : dir
109109
end
110110

111111
def root
@@ -126,7 +126,7 @@ def root
126126
# found in the :pserver: url is assigned to both.
127127
def sync_pserver_username_password
128128
# Do nothing unless pserver connection string is well-formed.
129-
return unless url =~ /:pserver:([\w\-\_]*)(:([\w\-\_]*))?@(.*)$/
129+
return unless url =~ /:pserver:([\w\-_]*)(:([\w\-_]*))?@(.*)$/
130130

131131
pserver_username = Regexp.last_match(1)
132132
pserver_password = Regexp.last_match(3)
@@ -140,7 +140,7 @@ def sync_pserver_username_password
140140

141141
# Based on the URL, take a guess about which forge this code is hosted on.
142142
def guess_forge
143-
return unless url =~ /.*(pserver|ext).*@(([^\.]+\.)?(cvs|dev)\.)?([^:]+):\//i
143+
return unless url =~ /.*(pserver|ext).*@(([^.]+\.)?(cvs|dev)\.)?([^:]+):\//i
144144

145145
Regexp.last_match(5).downcase
146146
end

lib/ohloh_scm/cvs/validation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def branch_name_errors
1919
[:branch_name, "The branch name can't be blank."]
2020
elsif scm.branch_name.length > 200
2121
[:branch_name, 'The branch name must not be longer than 200 characters.']
22-
elsif !scm.branch_name.match?(/^[\w\-\+\.\/\ ]+$/)
22+
elsif !scm.branch_name.match?(/^[\w\-+.\/\ ]+$/)
2323
[:branch_name, "The branch name may contain only letters,
2424
numbers, spaces, and the special characters '_', '-', '+', '/', and '.'"]
2525
end
2626
end
2727

2828
def public_url_regex
29-
/^:(pserver|ext):[\w\-\+\_]*(:[\w\-\+\_]*)?@[\w\-\+\.]+:[0-9]*\/[\w\-\+\.\/]*$/
29+
/^:(pserver|ext):[\w\-+_]*(:[\w\-+_]*)?@[\w\-+.]+:[0-9]*\/[\w\-+.\/]*$/
3030
end
3131

3232
# Returns an array of file and directory names from the remote server.
@@ -56,7 +56,7 @@ def get_filenames(output)
5656
files = []
5757
output.each_line do |s|
5858
s.strip!
59-
s = Regexp.last_match(1) + '/' if s =~ /^D\/(.*)\/\/\/\/$/
59+
s = "#{Regexp.last_match(1)}/" if s =~ /^D\/(.*)\/\/\/\/$/
6060
s = Regexp.last_match(1) if s =~ /^\/(.*)\/.*\/.*\/.*\/$/
6161
next if s == 'CVSROOT/'
6262

lib/ohloh_scm/diff.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Diff
3434
attr_accessor :from_path, :from_revision
3535

3636
def initialize(params = {})
37-
params.each { |k, v| send(k.to_s + '=', v) if respond_to?(k.to_s + '=') }
37+
params.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
3838
end
3939

4040
# eql?() and hash() are implemented so that [].uniq() will work on an array of Diffs.

lib/ohloh_scm/git/activity.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def tags
1010
return [] if no_tags?
1111

1212
flags = "--format='%(creatordate:iso-strict) %(objectname) %(refname)'"
13-
tag_strings = run("cd #{url} && git tag #{flags} | sed 's/refs\\/tags\\///'").split(/\n/)
13+
tag_strings = run("cd #{url} && git tag #{flags} | sed 's/refs\\/tags\\///'").split("\n")
1414
tag_strings.map do |tag_string|
1515
timestamp_string, commit_hash, tag_name = tag_string.split(/\s/)
1616
[tag_name, dereferenced_sha(tag_name) || commit_hash, time_object(timestamp_string)]
@@ -176,22 +176,22 @@ def get_commit_tree(token = 'HEAD')
176176
run("cd #{url} && git cat-file commit #{token} | grep '^tree' | cut -d ' ' -f 2").strip
177177
end
178178

179-
def safe_open_log_file(opts = {})
179+
def safe_open_log_file(opts = {}, &block)
180180
return '' unless status.branch?
181181
return '' if opts[:after] && opts[:after] == head_token
182182

183-
open_log_file(opts) { |io| yield io }
183+
open_log_file(opts, &block)
184184
end
185185

186-
def open_log_file(opts)
186+
def open_log_file(opts, &block)
187187
cmd = if ENV['EXPENSIVE_COMMIT_COUNT'] && commit_count(opts) > ENV['EXPENSIVE_COMMIT_COUNT'].to_i
188188
"#{rev_list_command(opts)} > #{log_filename}"
189189
else
190190
"#{rev_list_command(opts)} | xargs -n 1 #{OhlohScm::GitParser.whatchanged}"\
191191
" | #{string_encoder_path} > #{log_filename}"
192192
end
193193
run(cmd)
194-
File.open(log_filename, 'r') { |io| yield io }
194+
File.open(log_filename, 'r', &block)
195195
ensure
196196
File.delete(log_filename) if File.exist?(log_filename)
197197
end
@@ -218,7 +218,7 @@ def dtag_sha_and_names
218218
def dereferenced_tag_strings
219219
# Pattern: b6e9220c3cabe53a4ed7f32952aeaeb8a822603d refs/tags/v1.0.0^{}
220220
run("cd #{url} && git show-ref --tags -d | grep '\\^{}' | sed 's/\\^{}//'"\
221-
" | sed 's/refs\\/tags\\///'").split(/\n/)
221+
" | sed 's/refs\\/tags\\///'").split("\n")
222222
end
223223

224224
def time_object(timestamp_string)

0 commit comments

Comments
 (0)