[PATCH compass-ci] jobfile_operate.cr: simplify if block

[why] Somewhere there is only one line of code in if block, simply them with format "$cmd if $condition" Signed-off-by: Xu Xijian <hdxuxijian@163.com> --- src/scheduler/jobfile_operate.cr | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/scheduler/jobfile_operate.cr b/src/scheduler/jobfile_operate.cr index 68818ed..80cbcf7 100644 --- a/src/scheduler/jobfile_operate.cr +++ b/src/scheduler/jobfile_operate.cr @@ -57,9 +57,7 @@ module Jobfile::Operate def self.parse_one(script_lines, key, val) if valid_shell_variable?(key) - if val.as_h? - return false - end + return false if val.as_h? value = if val.as_a? shell_escape(val.as_a) @@ -133,9 +131,7 @@ module Jobfile::Operate end # if the create job cpio failed, what to do? - if idd.match(/ERROR/) - puts idd - end + puts idd if idd.match(/ERROR/) # create result dir and copy job.sh, job.yaml and job.cgz to result dir src_dir = File.dirname(temp_yaml) dst_dir = File.join("/srv", job_content["result_root"].to_s) @@ -204,9 +200,7 @@ module Jobfile::Operate def self.auto_submit_job(job_file, override_parameter, other_parameters = nil) cmd = "#{ENV["LKP_SRC"]}/sbin/submit " - if other_parameters - cmd += other_parameters.join(" ") - end + cmd += other_parameters.join(" ") if other_parameters cmd += " -s '#{override_parameter}' #{job_file}" puts `#{cmd}` end -- 2.23.0

On Fri, Nov 06, 2020 at 11:07:36AM +0800, Xu Xijian wrote:
[why] Somewhere there is only one line of code in if block, simply them with format "$cmd if $condition"
Signed-off-by: Xu Xijian <hdxuxijian@163.com> --- src/scheduler/jobfile_operate.cr | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/scheduler/jobfile_operate.cr b/src/scheduler/jobfile_operate.cr index 68818ed..80cbcf7 100644 --- a/src/scheduler/jobfile_operate.cr +++ b/src/scheduler/jobfile_operate.cr @@ -57,9 +57,7 @@ module Jobfile::Operate
def self.parse_one(script_lines, key, val) if valid_shell_variable?(key) - if val.as_h? - return false - end + return false if val.as_h?
value = if val.as_a? shell_escape(val.as_a) @@ -133,9 +131,7 @@ module Jobfile::Operate end
please avoid multilayer nesting of "if", the early exit "if" condition. Thanks, Liushaofei
# if the create job cpio failed, what to do? - if idd.match(/ERROR/) - puts idd - end + puts idd if idd.match(/ERROR/) # create result dir and copy job.sh, job.yaml and job.cgz to result dir src_dir = File.dirname(temp_yaml) dst_dir = File.join("/srv", job_content["result_root"].to_s) @@ -204,9 +200,7 @@ module Jobfile::Operate
def self.auto_submit_job(job_file, override_parameter, other_parameters = nil) cmd = "#{ENV["LKP_SRC"]}/sbin/submit " - if other_parameters - cmd += other_parameters.join(" ") - end + cmd += other_parameters.join(" ") if other_parameters cmd += " -s '#{override_parameter}' #{job_file}" puts `#{cmd}` end -- 2.23.0

On Fri, Nov 06, 2020 at 01:52:40PM +0800, Liu Shaofei wrote:
On Fri, Nov 06, 2020 at 11:07:36AM +0800, Xu Xijian wrote:
[why] Somewhere there is only one line of code in if block, simply them with format "$cmd if $condition"
Signed-off-by: Xu Xijian <hdxuxijian@163.com> --- src/scheduler/jobfile_operate.cr | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/scheduler/jobfile_operate.cr b/src/scheduler/jobfile_operate.cr index 68818ed..80cbcf7 100644 --- a/src/scheduler/jobfile_operate.cr +++ b/src/scheduler/jobfile_operate.cr @@ -57,9 +57,7 @@ module Jobfile::Operate
def self.parse_one(script_lines, key, val) if valid_shell_variable?(key) - if val.as_h? - return false - end + return false if val.as_h?
value = if val.as_a? shell_escape(val.as_a) @@ -133,9 +131,7 @@ module Jobfile::Operate end
please avoid multilayer nesting of "if", the early exit "if" condition. Thanks, Liushaofei
Good, but it's the matter of the context code, I'll fix it in another patch. Thanks, Xijian
participants (2)
-
Liu Shaofei
-
Xu Xijian