Skip to content

Commit 256d860

Browse files
committed
fix: fix Rubocop Metrics/AbcSize offense
Most of this was fixed by excluding tests from this metric. This is fine since I plan on moving tests to RSpec in the near future. The other few instances were fixed by refactoring the methods.
1 parent abfcf94 commit 256d860

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

.rubocop.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ inherit_from: .rubocop_todo.yml
33
inherit_gem:
44
main_branch_shared_rubocop_config: config/rubocop.yml
55

6-
# Don't care about complexity in TestUnit tests
7-
# This should go away when we switch to RSpec
6+
# Don't care about CyclomaticComplexity or AbcSize in TestUnit tests This should go
7+
# away when we switch to RSpec.
88
Metrics/CyclomaticComplexity:
99
Exclude:
1010
- "tests/test_helper.rb"
1111
- "tests/units/**/*"
1212

13+
Metrics/AbcSize:
14+
Exclude:
15+
- "tests/test_helper.rb"
16+
- "tests/units/**/*"
17+
1318
# Don't care so much about length of methods in tests
1419
Metrics/MethodLength:
1520
Exclude:

.rubocop_todo.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 50
10-
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11-
Metrics/AbcSize:
12-
Max: 109
13-
149
# Offense count: 21
1510
# Configuration parameters: CountComments, CountAsOne.
1611
Metrics/ClassLength:

lib/git/command_line.rb

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -278,50 +278,53 @@ def build_git_cmd(args)
278278
#
279279
def process_result(result, normalize, chomp, timeout)
280280
command = result.command
281-
processed_out, processed_err = post_process_all([result.stdout, result.stderr], normalize, chomp)
281+
processed_out, processed_err = post_process_output(result, normalize, chomp)
282+
log_result(result, command, processed_out, processed_err)
283+
command_line_result(command, result, processed_out, processed_err, timeout)
284+
end
285+
286+
def log_result(result, command, processed_out, processed_err)
282287
logger.info { "#{command} exited with status #{result}" }
283288
logger.debug { "stdout:\n#{processed_out.inspect}\nstderr:\n#{processed_err.inspect}" }
289+
end
290+
291+
def command_line_result(command, result, processed_out, processed_err, timeout)
284292
Git::CommandLineResult.new(command, result, processed_out, processed_err).tap do |processed_result|
285293
raise Git::TimeoutError.new(processed_result, timeout) if result.timeout?
294+
286295
raise Git::SignaledError, processed_result if result.signaled?
296+
287297
raise Git::FailedError, processed_result unless result.success?
288298
end
289299
end
290300

291-
# Post-process command output and return an array of the results
292-
#
293-
# @param raw_outputs [Array] the output to post-process
294-
# @param normalize [Boolean] whether to normalize the output of each writer
295-
# @param chomp [Boolean] whether to chomp the output of each writer
301+
# Post-process and return an array of raw output strings
296302
#
297-
# @return [Array<String, nil>] the processed output of each command output object that supports `#string`
303+
# For each raw output string:
298304
#
299-
# @api private
305+
# * If normalize: is true, normalize the encoding by transcoding each line from
306+
# the detected encoding to UTF-8.
307+
# * If chomp: is true chomp the output after normalization.
300308
#
301-
def post_process_all(raw_outputs, normalize, chomp)
302-
raw_outputs.map { |raw_output| post_process(raw_output, normalize, chomp) }
303-
end
304-
305-
# Determine the output to return in the `CommandLineResult`
309+
# Even if no post-processing is done based on the options, the strings returned
310+
# are a copy of the raw output strings. The raw output strings are not modified.
306311
#
307-
# If the writer can return the output by calling `#string` (such as a StringIO),
308-
# then return the result of normalizing the encoding and chomping the output
309-
# as requested.
312+
# @param result [ProcessExecuter::ResultWithCapture] the command's output to post-process
310313
#
311-
# If the writer does not support `#string`, then return nil. The output is
312-
# assumed to be collected by the writer itself such as when the writer
313-
# is a file instead of a StringIO.
314+
# @param normalize [Boolean] whether to normalize the output of each writer
315+
# @param chomp [Boolean] whether to chomp the output of each writer
314316
#
315-
# @param raw_output [#string] the output to post-process
316-
# @return [String, nil]
317+
# @return [Array<String>]
317318
#
318319
# @api private
319320
#
320-
def post_process(raw_output, normalize, chomp)
321-
output = raw_output.dup
322-
output = output.lines.map { |l| Git::EncodingUtils.normalize_encoding(l) }.join if normalize
323-
output.chomp! if chomp
324-
output
321+
def post_process_output(result, normalize, chomp)
322+
[result.stdout, result.stderr].map do |raw_output|
323+
output = raw_output.dup
324+
output = output.lines.map { |l| Git::EncodingUtils.normalize_encoding(l) }.join if normalize
325+
output.chomp! if chomp
326+
output
327+
end
325328
end
326329
end
327330
end

0 commit comments

Comments
 (0)