Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static-check fixes from @lespea #1657, batch 5/n #1707

Merged
merged 4 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/miller-as-library/main3.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func convert_csv_to_json(fileNames []string) error {
case ierr := <-inputErrorChannel:
retval = ierr
break
case _ = <-dataProcessingErrorChannel:
case <-dataProcessingErrorChannel:
retval = errors.New("exiting due to data error") // details already printed
break
case _ = <-doneWritingChannel:
case <-doneWritingChannel:
done = true
break
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/bifs/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@
// a=F | min=a min=a
// a=T | min=b min=b
func min_b_bb(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
if input1.AcquireBoolValue() == false {
if !input1.AcquireBoolValue() {
return input1
} else {
return input2
Expand Down Expand Up @@ -946,8 +946,8 @@
}
// Do the bulk arithmetic on native ints not Mlrvals, to avoid unnecessary allocation.
retval := lib.UTF8Strlen(mlrvals[0].OriginalString())
for i, _ := range mlrvals {
for i := range mlrvals {
clen := lib.UTF8Strlen(mlrvals[i].OriginalString())

Check failure on line 950 in pkg/bifs/arithmetic.go

View workflow job for this annotation

GitHub Actions / Codespell

clen ==> clean, clan
if clen < retval {
retval = clen
}
Expand Down Expand Up @@ -1004,7 +1004,7 @@
// a=F | max=a max=b
// a=T | max=a max=b
func max_b_bb(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
if input2.AcquireBoolValue() == false {
if !input2.AcquireBoolValue() {
return input1
} else {
return input2
Expand Down Expand Up @@ -1116,7 +1116,7 @@
}
// Do the bulk arithmetic on native ints not Mlrvals, to avoid unnecessary allocation.
retval := lib.UTF8Strlen(mlrvals[0].OriginalString())
for i, _ := range mlrvals {
for i := range mlrvals {
clen := lib.UTF8Strlen(mlrvals[i].OriginalString())
if clen > retval {
retval = clen
Expand Down
2 changes: 1 addition & 1 deletion pkg/bifs/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func eq_b_aa(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
for i := range a {
eq := BIF_equals(a[i], b[i])
lib.InternalCodingErrorIf(eq.Type() != mlrval.MT_BOOL)
if eq.AcquireBoolValue() == false {
if !eq.AcquireBoolValue() {
return mlrval.FALSE
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/bifs/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func BIF_strmatchx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
captures_array := make([]*mlrval.Mlrval, len(captures))

if len(captures) > 0 {
for i, _ := range captures {
for i := range captures {
if i == 0 {
results.PutReference("full_capture", mlrval.FromString(captures[i]))
} else {
Expand All @@ -156,7 +156,7 @@ func BIF_strmatchx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
}

starts_array := make([]*mlrval.Mlrval, len(starts))
for i, _ := range starts {
for i := range starts {
if i == 0 {
results.PutReference("full_start", mlrval.FromInt(int64(starts[i])))
} else {
Expand All @@ -165,7 +165,7 @@ func BIF_strmatchx(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
}

ends_array := make([]*mlrval.Mlrval, len(ends))
for i, _ := range ends {
for i := range ends {
if i == 0 {
results.PutReference("full_end", mlrval.FromInt(int64(ends[i])))
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/bifs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func bif_percentiles_impl(

outputs := make([]*mlrval.Mlrval, len(ps))

for i, _ := range ps {
for i := range ps {
p, ok := ps[i].GetNumericToFloatValue()
if !ok {
outputs[i] = type_error_named_argument(funcname, "numeric", "percentile", ps[i])
Expand All @@ -655,7 +655,7 @@ func bif_percentiles_impl(
return mlrval.FromArray(outputs)
} else {
m := mlrval.NewMlrmap()
for i, _ := range ps {
for i := range ps {
sp := ps[i].String()
m.PutCopy(sp, outputs[i])
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/bifs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func float_to_int(input1 *mlrval.Mlrval) *mlrval.Mlrval {
}

func bool_to_int(input1 *mlrval.Mlrval) *mlrval.Mlrval {
if input1.AcquireBoolValue() == true {
if input1.AcquireBoolValue() {
return mlrval.FromInt(1)
} else {
return mlrval.FromInt(0)
Expand Down Expand Up @@ -92,7 +92,7 @@ func float_to_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
}

func bool_to_int_with_base(input1, input2 *mlrval.Mlrval) *mlrval.Mlrval {
if input1.AcquireBoolValue() == true {
if input1.AcquireBoolValue() {
return mlrval.FromInt(1)
} else {
return mlrval.FromInt(0)
Expand Down Expand Up @@ -146,7 +146,7 @@ func int_to_float(input1 *mlrval.Mlrval) *mlrval.Mlrval {
}

func bool_to_float(input1 *mlrval.Mlrval) *mlrval.Mlrval {
if input1.AcquireBoolValue() == true {
if input1.AcquireBoolValue() {
return mlrval.FromFloat(1.0)
} else {
return mlrval.FromFloat(0.0)
Expand Down
2 changes: 1 addition & 1 deletion pkg/climain/mlrcli_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func parseCommandLinePassTwo(
rc := cli.FLAG_TABLE.Parse(args, argc, &argi, options)

// Should have been parsed OK in pass one.
lib.InternalCodingErrorIf(rc != true)
lib.InternalCodingErrorIf(!rc)
// Make sure we consumed the entire flag sequence as parsed by pass one.
lib.InternalCodingErrorIf(argi != argc)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dsl/cst/builtin_function_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ func (manager *BuiltinFunctionManager) getBuiltinFunctionClasses() []string {
classesList := make([]string, 0)
for _, builtinFunctionInfo := range *manager.lookupTable {
class := string(builtinFunctionInfo.class)
if classesSeen[class] == false {
if !classesSeen[class] {
classesList = append(classesList, class)
classesSeen[class] = true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dsl/cst/builtin_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func (node *StandardTernaryOperatorNode) Evaluate(
}

// Short-circuit: defer evaluation unless needed
if boolValue == true {
if boolValue {
return node.b.Evaluate(state)
} else {
return node.c.Evaluate(state)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dsl/cst/cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (node *CondBlockNode) Execute(
)
}

if boolValue == true {
if boolValue {
blockExitPayload, err := node.statementBlockNode.Execute(state)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/dsl/cst/for.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ func (node *TripleForLoopNode) Execute(state *runtime.State) (*BlockExitPayload,
dsl.TokenToLocationInfo(node.continuationExpressionToken),
)
}
if boolValue == false {
if !boolValue {
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dsl/cst/if.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (node *IfChainNode) Execute(state *runtime.State) (*BlockExitPayload, error
dsl.TokenToLocationInfo(ifItem.conditionToken),
)
}
if boolValue == true {
if boolValue {
blockExitPayload, err := ifItem.statementBlockNode.Execute(state)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions pkg/dsl/cst/udf.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ func (root *RootNode) BuildUDF(
"function return value",
returnValueTypeName,
)
if err != nil {
return nil, err
}

lib.InternalCodingErrorIf(parameterListASTNode.Type != dsl.NodeTypeParameterList)
lib.InternalCodingErrorIf(parameterListASTNode.Children == nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/dsl/cst/while.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (node *WhileLoopNode) Execute(state *runtime.State) (*BlockExitPayload, err
dsl.TokenToLocationInfo(node.conditionToken),
)
}
if boolValue != true {
if !boolValue {
break
}
blockExitPayload, err := node.statementBlockNode.Execute(state)
Expand Down Expand Up @@ -161,7 +161,7 @@ func (node *DoWhileLoopNode) Execute(state *runtime.State) (*BlockExitPayload, e
dsl.TokenToLocationInfo(node.conditionToken),
)
}
if boolValue == false {
if !boolValue {
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/input/line_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func channelizedLineReader(
// quickly, as it should.
if i%recordsPerBatch == 0 {
select {
case _ = <-downstreamDoneChannel:
case <-downstreamDoneChannel:
done = true
break
default:
Expand Down
3 changes: 1 addition & 2 deletions pkg/input/pseudo_reader_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (reader *PseudoReaderGen) process(
// avoid goroutine-scheduler thrash.
eof := false
select {
case _ = <-downstreamDoneChannel:
case <-downstreamDoneChannel:
eof = true
break
default:
Expand All @@ -113,7 +113,6 @@ func (reader *PseudoReaderGen) process(

if recordsAndContexts.Len() > 0 {
readerChannel <- recordsAndContexts
recordsAndContexts = list.New()
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/input/record_reader_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func channelizedCSVRecordScanner(
// quickly, as it should.
if i%recordsPerBatch == 0 {
select {
case _ = <-downstreamDoneChannel:
case <-downstreamDoneChannel:
done = true
break
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/input/record_reader_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (reader *RecordReaderJSON) processHandle(
i++
if i%recordsPerBatch == 0 {
select {
case _ = <-downstreamDoneChannel:
case <-downstreamDoneChannel:
eof = true
break
default:
Expand Down
4 changes: 2 additions & 2 deletions pkg/input/record_reader_pprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func getRecordBatchExplicitPprintHeader(
continue
}
fields := make([]string, npad-2)
for i, _ := range paddedFields {
for i := range paddedFields {
if i == 0 || i == npad-1 {
continue
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func getRecordBatchImplicitPprintHeader(
paddedFields := reader.fieldSplitter.Split(line)
npad := len(paddedFields)
fields := make([]string, npad-2)
for i, _ := range paddedFields {
for i := range paddedFields {
if i == 0 || i == npad-1 {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/input/record_reader_xtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func channelizedStanzaScanner(
// quickly, as it should.
if numStanzasSeen%recordsPerBatch == 0 {
select {
case _ = <-downstreamDoneChannel:
case <-downstreamDoneChannel:
done = true
break
default:
Expand Down
6 changes: 6 additions & 0 deletions pkg/lib/halfpipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (

func OpenOutboundHalfPipe(commandString string) (*os.File, error) {
readPipe, writePipe, err := os.Pipe()
if err != nil {
return nil, err
}

var procAttr os.ProcAttr
procAttr.Files = []*os.File{
Expand Down Expand Up @@ -56,6 +59,9 @@ func OpenOutboundHalfPipe(commandString string) (*os.File, error) {

func OpenInboundHalfPipe(commandString string) (*os.File, error) {
readPipe, writePipe, err := os.Pipe()
if err != nil {
return nil, err
}

var procAttr os.ProcAttr
procAttr.Files = []*os.File{
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func BooleanXOR(a, b bool) bool {
}

func BoolToInt(b bool) int64 {
if b == false {
if !b {
return 0
} else {
return 1
Expand Down
Loading
Loading