From b4ff26a7d0826da90ee34fb8036cc727eaa85d16 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 27 Oct 2024 12:06:17 -0400 Subject: [PATCH] Static-check fixes from @lespea #1657, batch 6/n (#1708) * Static-check fixes from @lespea #1657, batch 2/n * Static-check fixes from @lespea #1657, batch 3/n * Static-check fixes from @lespea #1657, batch 4/n * Static-check fixes from @lespea #1657, batch 5/n * Static-check fixes from @lespea #1657, batch 6/n --- pkg/climain/mlrcli_parse.go | 2 +- pkg/dsl/ast_print.go | 2 +- pkg/dsl/cst/root.go | 2 +- pkg/dsl/cst/validate.go | 2 +- pkg/lib/regex.go | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/climain/mlrcli_parse.go b/pkg/climain/mlrcli_parse.go index f582cd51c..939f10e36 100644 --- a/pkg/climain/mlrcli_parse.go +++ b/pkg/climain/mlrcli_parse.go @@ -394,7 +394,7 @@ func parseCommandLinePassTwo( options.FileNames = nil } - if options.DoInPlace && (options.FileNames == nil || len(options.FileNames) == 0) { + if options.DoInPlace && len(options.FileNames) == 0 { fmt.Fprintf(os.Stderr, "%s: -I option (in-place operation) requires input files.\n", "mlr") os.Exit(1) } diff --git a/pkg/dsl/ast_print.go b/pkg/dsl/ast_print.go index 4210e5b17..c735ef84c 100644 --- a/pkg/dsl/ast_print.go +++ b/pkg/dsl/ast_print.go @@ -157,7 +157,7 @@ func (node *ASTNode) printParexOneLineAux() { // IsLeaf determines if an AST node is a leaf node. func (node *ASTNode) IsLeaf() bool { - return node.Children == nil || len(node.Children) == 0 + return len(node.Children) == 0 } // ChildrenAreAllLeaves determines if an AST node's children are all leaf nodes. diff --git a/pkg/dsl/cst/root.go b/pkg/dsl/cst/root.go index a5b2f4848..a1c5b0b99 100644 --- a/pkg/dsl/cst/root.go +++ b/pkg/dsl/cst/root.go @@ -251,7 +251,7 @@ func (root *RootNode) regexProtectPrePass(ast *dsl.AST) { func (root *RootNode) regexProtectPrePassAux(astNode *dsl.ASTNode) { - if astNode.Children == nil || len(astNode.Children) == 0 { + if len(astNode.Children) == 0 { return } diff --git a/pkg/dsl/cst/validate.go b/pkg/dsl/cst/validate.go index 39db06fdc..8783c6003 100644 --- a/pkg/dsl/cst/validate.go +++ b/pkg/dsl/cst/validate.go @@ -29,7 +29,7 @@ func ValidateAST( // They can do mlr put '': there are simply zero statements. // But filter '' is an error. - if ast.RootNode.Children == nil || len(ast.RootNode.Children) == 0 { + if len(ast.RootNode.Children) == 0 { if dslInstanceType == DSLInstanceTypeFilter { return fmt.Errorf("mlr: filter statement must not be empty") } diff --git a/pkg/lib/regex.go b/pkg/lib/regex.go index d8d551167..b810a4b01 100644 --- a/pkg/lib/regex.go +++ b/pkg/lib/regex.go @@ -203,7 +203,7 @@ func regexCompiledSubOrGsub( breakOnFirst bool, ) string { matrix := regex.FindAllStringSubmatchIndex(input, -1) - if matrix == nil || len(matrix) == 0 { + if len(matrix) == 0 { return input } @@ -321,7 +321,7 @@ func RegexCompiledMatchWithMapResults( ends := make([]int, 0, 10) matrix := regex.FindAllStringSubmatchIndex(input, -1) - if matrix == nil || len(matrix) == 0 { + if len(matrix) == 0 { return false, captures, starts, ends } @@ -407,7 +407,7 @@ func RegexCompiledMatchWithCaptures( regex *regexp.Regexp, ) (bool, []string) { matrix := regex.FindAllStringSubmatchIndex(input, -1) - if matrix == nil || len(matrix) == 0 { + if len(matrix) == 0 { // Set all captures to "" return false, make([]string, 10) }