Skip to content

Commit 57383fd

Browse files
Copilotkbukum1
andcommitted
Fix Sorbet type errors and RuboCop linting issues
Fixed all Sorbet type errors and RuboCop linting issues: Sorbet fixes: - Wrapped Regexp.last_match(1) and Regexp.last_match(2) with T.must() to assert non-nil values (safe since we're inside a regex match) - This satisfies the T::Hash[String, String] type requirement RuboCop fixes: - Style/Next: Changed if block to use next unless pattern - Lint/UnusedBlockArgument: Renamed unused env: to _env: in test mocks - Layout/FirstMethodArgumentLineBreak: Added line break before first arg - Style/PercentLiteralDelimiters: Changed %w[] to %w() delimiter Verification: - bundle exec srb tc: No errors! - bundle exec rubocop: No offenses detected Co-authored-by: kbukum1 <171620528+kbukum1@users.noreply.github.com>
1 parent 74411ee commit 57383fd

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

gradle/lib/dependabot/gradle/file_updater/wrapper_updater.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,11 @@ def update_distribution_properties(properties_file, original_content)
189189
# Extract the new values for distributionUrl and distributionSha256Sum
190190
new_content.each_line do |line|
191191
next if line.strip.start_with?("#") || line.strip.empty?
192+
next unless line =~ /^(distributionUrl|distributionSha256Sum)=(.*)$/
192193

193-
if line =~ /^(distributionUrl|distributionSha256Sum)=(.*)$/
194-
key = ::Regexp.last_match(1)
195-
value = ::Regexp.last_match(2)
196-
updated_values[key] = value
197-
end
194+
key = T.must(::Regexp.last_match(1))
195+
value = T.must(::Regexp.last_match(2))
196+
updated_values[key] = value
198197
end
199198

200199
# Duplicate to avoid mutating the parameter

gradle/spec/dependabot/gradle/file_updater_spec.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@
809809

810810
before do
811811
# Mock the file operations to simulate the wrapper command updating the properties
812-
allow(Dependabot::SharedHelpers).to receive(:run_shell_command) do |_command, cwd:, env:|
812+
allow(Dependabot::SharedHelpers).to receive(:run_shell_command) do |_command, cwd:, _env:|
813813
# Simulate the wrapper command updating the properties file with defaults
814814
properties_file = File.join(cwd, "gradle/wrapper/gradle-wrapper.properties")
815815
if File.exist?(properties_file)
@@ -885,7 +885,7 @@
885885

886886
before do
887887
# Mock the file operations to simulate the wrapper command updating the properties
888-
allow(Dependabot::SharedHelpers).to receive(:run_shell_command) do |_command, cwd:, env:|
888+
allow(Dependabot::SharedHelpers).to receive(:run_shell_command) do |_command, cwd:, _env:|
889889
# Simulate the wrapper command generating a new file without comments
890890
properties_file = File.join(cwd, "gradle/wrapper/gradle-wrapper.properties")
891891
if File.exist?(properties_file)
@@ -922,15 +922,17 @@
922922
it "maintains the original property order" do
923923
lines = updated_buildfile.content.lines.reject { |l| l.strip.start_with?("#") || l.strip.empty? }
924924
property_names = lines.map { |l| l.split("=").first }
925-
expect(property_names).to eq(%w[
926-
distributionBase
927-
distributionPath
928-
distributionUrl
929-
networkTimeout
930-
validateDistributionUrl
931-
zipStoreBase
932-
zipStorePath
933-
])
925+
expect(property_names).to eq(
926+
%w(
927+
distributionBase
928+
distributionPath
929+
distributionUrl
930+
networkTimeout
931+
validateDistributionUrl
932+
zipStoreBase
933+
zipStorePath
934+
)
935+
)
934936
end
935937
end
936938
end

0 commit comments

Comments
 (0)