Skip to content

Commit ae3ec60

Browse files
committed
Fix performance issues detected by RuboCop
After installing `rubocop-performance` and running it, it showed some suggestions to improve the overall performance. Signed-off-by: Dominik Gedon <dominik.gedon@suse.com>
1 parent 930a32f commit ae3ec60

7 files changed

Lines changed: 16 additions & 7 deletions

File tree

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
inherit_from: .rubocop_todo.yml
22

33
plugins:
4+
- rubocop-performance
45
- rubocop-rake
56
- rubocop-rspec
67

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ GEM
110110
rubocop-ast (1.49.0)
111111
parser (>= 3.3.7.2)
112112
prism (~> 1.7)
113+
rubocop-performance (1.26.1)
114+
lint_roller (~> 1.1)
115+
rubocop (>= 1.75.0, < 2.0)
116+
rubocop-ast (>= 1.47.1, < 2.0)
113117
rubocop-rake (0.7.1)
114118
lint_roller (~> 1.1)
115119
rubocop (>= 1.72.1)
@@ -154,6 +158,7 @@ DEPENDENCIES
154158
rake (~> 13.3)
155159
rspec (~> 3.13)
156160
rubocop (~> 1.82.1)
161+
rubocop-performance (~> 1.26)
157162
rubocop-rake (~> 0.7.1)
158163
rubocop-rspec (~> 3.9.0)
159164
simplecov (~> 0.22)
@@ -214,6 +219,7 @@ CHECKSUMS
214219
rspec-support (3.13.6) sha256=2e8de3702427eab064c9352fe74488cc12a1bfae887ad8b91cba480ec9f8afb2
215220
rubocop (1.82.1) sha256=09f1a6a654a960eda767aebea33e47603080f8e9c9a3f019bf9b94c9cab5e273
216221
rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
222+
rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834
217223
rubocop-rake (0.7.1) sha256=3797f2b6810c3e9df7376c26d5f44f3475eda59eb1adc38e6f62ecf027cbae4d
218224
rubocop-rspec (3.9.0) sha256=8fa70a3619408237d789aeecfb9beef40576acc855173e60939d63332fdb55e2
219225
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33

lib/tetra/facades/git.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def undo_last_commit
9999
def disable_special_files(path)
100100
Dir.chdir(File.join(@directory, path)) do
101101
Find.find(".") do |file|
102-
next unless file =~ /\.git(ignore)?$/
102+
next unless /\.git(ignore)?$/.match?(file)
103103

104104
FileUtils.mv(file, "#{file}_disabled_by_tetra")
105105
end

lib/tetra/maven_website.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_maven_id_from(result)
4949

5050
# downloads a POM from a search.maven.com search result
5151
def download_pom(group_id, artifact_id, version)
52-
path = "#{group_id.gsub('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.pom"
52+
path = "#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.pom"
5353
log.debug("downloading #{path}...")
5454
get("https://repo1.maven.org/maven2/#{path}", {}).to_s
5555
end

lib/tetra/pom_getter.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def get_pom_from_jar(file)
2121
log.debug("Attempting unpack of #{file} to find a POM")
2222
begin
2323
Zip::File.foreach(file) do |entry|
24-
if entry.name =~ %r{/pom.xml$}
24+
next if entry.name.include?("..") || entry.name.start_with?("/")
25+
26+
if %r{/pom.xml$}.match?(entry.name)
2527
log.info("pom.xml found in #{file}##{entry.name}")
2628
return entry.get_input_stream.read, :found_in_jar
2729
end
@@ -41,8 +43,7 @@ def get_pom_from_sha1(file)
4143
if File.file?(file)
4244
site = MavenWebsite.new
4345
sha1 = Digest::SHA1.hexdigest File.read(file)
44-
results = site.search_by_sha1(sha1).select { |result| result["ec"].include?(".pom") }
45-
result = results.first
46+
result = site.search_by_sha1(sha1).find { |result| result["ec"].include?(".pom") }
4647
unless result.nil?
4748
log.info("pom.xml for #{file} found on search.maven.org for sha1 #{sha1}\
4849
(#{result['g']}:#{result['a']}:#{result['v']})"
@@ -81,7 +82,7 @@ def get_pom_from_heuristic(filename)
8182
their_versions.max
8283
end
8384
)
84-
best_matched_result = results.select { |r| r["v"] == best_matched_version }.first
85+
best_matched_result = results.find { |r| r["v"] == best_matched_version }
8586

8687
group_id, artifact_id, version = site.get_maven_id_from(best_matched_result)
8788
log.warn("pom.xml for #{filename} found on search.maven.org with heuristic search\

lib/tetra/project_initer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def commit_source_archive(file, message)
7575
FileUtils.cp(file, result_path)
7676
@git.commit_file(result_path, "Source archive added")
7777

78-
unarchiver = if file =~ /\.zip$/
78+
unarchiver = if /\.zip$/.match?(file)
7979
Tetra::Unzip.new
8080
else
8181
Tetra::Tar.new

tetra.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
3232
s.add_development_dependency "rake", "~> 13.3"
3333
s.add_development_dependency "rspec", "~> 3.13"
3434
s.add_development_dependency "rubocop", "~> 1.82.1"
35+
s.add_development_dependency "rubocop-performance", "~> 1.26"
3536
s.add_development_dependency "rubocop-rake", "~> 0.7.1"
3637
s.add_development_dependency "rubocop-rspec", "~> 3.9.0"
3738

0 commit comments

Comments
 (0)