Skip to content

Commit

Permalink
lib: refactor to use return instead of return nil
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Li <philip.li@intel.com>
  • Loading branch information
rli9 committed Jun 18, 2024
1 parent 51da3e0 commit bf2458d
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/array_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mean
end

def median(already_sorted: false)
return nil if empty?
return if empty?

sort! unless already_sorted
m_pos = size / 2
Expand Down
2 changes: 1 addition & 1 deletion lib/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def cache_fetch_hash(cache_store, cache_key, obj, method_name, *args)
end

value = obj.send("#{method_name}_without_cache", *args)
return nil if value.nil? && !cache_options[method_name][:cache_nil]
return if value.nil? && !cache_options[method_name][:cache_nil]

cache_store[cache_key] = OpenStruct.new(value: value, timestamp: Time.now)
cache_store[cache_key].value
Expand Down
2 changes: 1 addition & 1 deletion lib/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def initialize(params = nil)
# Convert string to hash:
# "commit/1,2,3" => { commit => [1, 2, 3] }
def convert_exclude_result_roots
return nil if @exclude_result_roots.to_s.empty?
return if @exclude_result_roots.to_s.empty?

arr = @exclude_result_roots.split('/')
return { arr[0] => arr[1].split(',').delete_if(&:empty?) } if arr.size == 2 && sha1_40?(arr[0]) && arr[1] =~ /[0-9,]+/
Expand Down
2 changes: 1 addition & 1 deletion lib/git_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def open(options = {})

working_dir = options[:working_dir] || "#{GIT_ROOT_DIR}/#{options[:project]}"

return nil if options[:may_not_exist] && !Dir.exist?(working_dir)
return if options[:may_not_exist] && !Dir.exist?(working_dir)

Git.orig_open(working_dir, options)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/git_ext/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def prev_official_release_tag
# v3.12 => v3.13
def next_official_release_tag
tag = release_tag
return nil unless tag
return unless tag

order = @base.release_tag_order(tag)
return nil unless order
return unless order

@base.release_tags_with_order.reverse_each do |tag, o|
next if o <= order
Expand All @@ -130,7 +130,7 @@ def next_official_release_tag

def next_release_tag
tag = release_tag
return nil unless tag
return unless tag

order = @base.release_tag_order(tag)
@base.release_tags_with_order.reverse_each do |tag, o|
Expand Down
4 changes: 2 additions & 2 deletions lib/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def include_files
end

def load_one_defaults(file, job)
return nil unless File.exist? file
return unless File.exist? file

context_hash = deepcopy(@defaults)
revise_hash(context_hash, job, overwrite_top_keys: true)
Expand Down Expand Up @@ -704,7 +704,7 @@ def expand_params(run_scripts: true)
raise
rescue KeyError => e # no conclusion due to lack of information
log_error "#{file}: #{e.message} hash: #{hash}"
return nil
return
end
true
end
Expand Down
4 changes: 2 additions & 2 deletions lib/lkp_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def commit_tag(commit)
end

def linus_release_tag(commit)
return nil unless linus_commit?(commit)
return unless linus_commit?(commit)

tag = commit_tag(commit)
case tag
Expand Down Expand Up @@ -126,7 +126,7 @@ def __last_linus_release_tag(commit)
else
log_warn "Not a kernel tree? check #{GIT_WORK_TREE}"
log_warn caller.join "\n"
return nil
return
end

tag += "-rc#{rc}" if rc && rc.positive?
Expand Down
2 changes: 1 addition & 1 deletion lib/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def load_matrix_file(matrix_file)
begin
matrix = load_json(matrix_file) if File.exist? matrix_file
rescue StandardError
return nil
return
end
matrix
end
Expand Down
6 changes: 3 additions & 3 deletions lib/nresult_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def result_roots_with_stat(stat)

def kpi_avg_stddev
cm = complete_matrix
return nil if matrix_cols(cm) < 3
return if matrix_cols(cm) < 3

avg_stddev = {}
cm.each do |k, v|
Expand Down Expand Up @@ -491,14 +491,14 @@ def save(_rt)
def load(axes)
dir, file = ResultStddev.path axes
path = File.join dir, file
return nil unless File.exist? path
return unless File.exist? path

load_json path
end

def load_values(axes)
data = load(axes)
return nil unless data && !data.empty?
return unless data && !data.empty?

data.delete SOURCE_KEY
data.each do |k, vs|
Expand Down
2 changes: 1 addition & 1 deletion lib/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def tbox_group(hostname)
end

def tbox_group?(hostname)
return nil unless hostname.is_a?(String) && !hostname.empty?
return unless hostname.is_a?(String) && !hostname.empty?

Dir[LKP::Path.src('hosts', hostname)][0]
end
Expand Down
16 changes: 8 additions & 8 deletions lib/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def load_base_matrix_for_notag_project(git, rp, axis)
base_matrix_file = "#{rp._result_root}/matrix.json"
unless File.exist? base_matrix_file
log_warn "#{base_matrix_file} doesn't exist."
return nil
return
end
load_release_matrix(base_matrix_file)
end
Expand Down Expand Up @@ -267,21 +267,21 @@ def load_base_matrix(matrix_path, head_matrix, options)
git = $git[project]
rescue StandardError => e
log_error e
return nil
return
end

return load_base_matrix_for_notag_project(git, rp, axis) if git.tag_names.empty?

begin
return nil unless git.commit_exist? commit
return unless git.commit_exist? commit

version = nil
is_exact_match = false
version, is_exact_match = git.gcommit(commit).last_release_tag
log_debug "project: #{project}, version: #{version}, is_exact_match: #{is_exact_match}"
rescue StandardError => e
log_error e
return nil
return
end

# FIXME: remove it later; or move it somewhere in future
Expand All @@ -297,7 +297,7 @@ def load_base_matrix(matrix_path, head_matrix, options)
end
unless version
log_error "Cannot get base RC commit for #{commit}"
return nil
return
end
end

Expand All @@ -316,7 +316,7 @@ def load_base_matrix(matrix_path, head_matrix, options)
# FIXME: rli9 after above change, below situation is not reasonable, keep it for debugging purpose now
unless order
log_error "unknown version #{version} matrix: #{matrix_path} options: #{options}"
return nil
return
end
end

Expand Down Expand Up @@ -523,7 +523,7 @@ def __get_changed_stats(a, b, is_incomplete_run, options)
cols_a = matrix_cols a
cols_b = matrix_cols b

return nil if options['variance'] && (cols_a < 10 || cols_b < 10)
return if options['variance'] && (cols_a < 10 || cols_b < 10)

# Before: matrix = { "will-it-scale.per_process_ops" => [1183733, 1285303, 721524, 858073, 1207794] }
# After: matrix = { "will-it-scale.per_process_ops" => [1183733, 1285303, 721524, 858073, 1207794],
Expand Down Expand Up @@ -744,7 +744,7 @@ def get_changed_stats(matrix_path1, matrix_path2 = nil, options = {})
DEBUG

a, b = load_matrices_to_compare matrix_path1, matrix_path2, options
return nil if a.nil? || b.nil?
return if a.nil? || b.nil?

_get_changed_stats(a, b, options)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def load_yaml_tail(file)

def search_file_in_paths(file, relative_to = nil, search_paths = nil)
if file[0] == '/'
return nil unless File.exist? file
return unless File.exist? file

return file
end
Expand All @@ -83,7 +83,7 @@ def search_file_in_paths(file, relative_to = nil, search_paths = nil)

if file =~ /^\.\.?\//
file = File.join(relative_to, file)
return nil unless File.exist? file
return unless File.exist? file

return file
end
Expand Down Expand Up @@ -215,7 +215,7 @@ def initialize(path)
end

def load_merge_jsons(path)
return nil unless path.index(',')
return unless path.index(',')

files = path.split(',')
files.each do |file|
Expand Down
8 changes: 4 additions & 4 deletions sbin/compare
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ end

def get_valid_average(matrix, key)
samples = matrix[key]
return nil unless samples
return nil if samples.include? 0
return nil if samples.size < matrix_cols(matrix)
return unless samples
return if samples.include? 0
return if samples.size < matrix_cols(matrix)

avg = matrix[key].average
return nil if !$opt_no_hide_noises && matrix[key].standard_deviation > avg / 2
return if !$opt_no_hide_noises && matrix[key].standard_deviation > avg / 2

avg
end
Expand Down

0 comments on commit bf2458d

Please sign in to comment.