Skip to content

Commit

Permalink
all: apply lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Sep 28, 2021
1 parent 523ebcd commit 2811be8
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 62 deletions.
19 changes: 9 additions & 10 deletions fwk/cmd/fwk-new-comp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
)
Expand All @@ -22,11 +23,9 @@ type Component struct {
Type string
}

func printf(format string, args ...interface{}) (int, error) {
return fmt.Fprintf(os.Stderr, format, args...)
}

func main() {
log.SetFlags(0)
log.SetPrefix("fwk-new-comp: ")

flag.Usage = func() {
fmt.Fprintf(os.Stderr, `Usage: %[1]s [options] <component-name>
Expand All @@ -50,7 +49,7 @@ options:

func run() int {
if *g_type != "svc" && *g_type != "task" {
printf("**error** invalid component type [%s]\n", *g_type)
log.Printf("**error** invalid component type [%s]\n", *g_type)
flag.Usage()
return 1
}
Expand All @@ -59,13 +58,13 @@ func run() int {
// take directory name
wd, err := os.Getwd()
if err != nil {
printf("**error** could not get directory name: %v\n", err)
log.Printf("**error** could not get directory name: %v\n", err)
return 1
}
*g_pkg = filepath.Base(wd)

if *g_pkg == "" || *g_pkg == "." {
printf(
log.Printf(
"**error** invalid package name %q. please specify via the '-p' flag.",
*g_pkg,
)
Expand All @@ -75,7 +74,7 @@ func run() int {

args := flag.Args()
if len(args) <= 0 {
printf("**error** you need to give a component name\n")
log.Printf("**error** you need to give a component name\n")
flag.Usage()
return 1
}
Expand All @@ -93,13 +92,13 @@ func run() int {
case "task":
err = gen_task(c)
default:
printf("**error** invalid component type [%s]\n", *g_type)
log.Printf("**error** invalid component type [%s]\n", *g_type)
flag.Usage()
return 1
}

if err != nil {
printf("**error** generating %q: %v\n", c.Name, err)
log.Printf("**error** generating %q: %v\n", c.Name, err)
return 1
}

Expand Down
4 changes: 1 addition & 3 deletions fwk/hbooksvc/hsvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ func (tsk *testhsvc) StartTask(ctx fwk.Context) error {
if !strings.HasPrefix(tsk.stream, "/") {
tsk.stream = "/" + tsk.stream
}
if strings.HasSuffix(tsk.stream, "/") {
tsk.stream = tsk.stream[:len(tsk.stream)-1]
}
tsk.stream = strings.TrimSuffix(tsk.stream, "/")

tsk.h1d, err = tsk.hsvc.BookH1D(tsk.stream+"/h1d-"+tsk.Name(), 100, -10, 10)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions groot/rdict/gen_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ func (g *genGoType) typename(se rbytes.StreamerElement) string {
return t.Name()

case *StreamerLoop:
if strings.HasSuffix(tname, "*") {
tname = tname[:len(tname)-1]
}
tname = strings.TrimSuffix(tname, "*")
return "[]" + g.cxx2go(tname, qualNone)

case *StreamerObject:
Expand Down
8 changes: 2 additions & 6 deletions groot/rdict/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,11 @@ func typeFromDescr(typ reflect.Type, typename string, alen int, dims []int32) re

if alen < 0 {
// slice. drop one '*' from typename.
if strings.HasSuffix(typename, "*") {
typename = typename[:len(typename)-1]
}
typename = strings.TrimSuffix(typename, "*")
}
if typename == "char*" {
// slice. drop one '*' from typename.
if strings.HasSuffix(typename, "*") {
typename = typename[:len(typename)-1]
}
typename = strings.TrimSuffix(typename, "*")
}

// handle T***
Expand Down
23 changes: 19 additions & 4 deletions hbook/ntup/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ func ExampleNtuple_scanH2D() {
if err != nil {
log.Fatal(err)
}
defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

h, err := nt.ScanH2D("v1, v2", nil)

if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -78,7 +82,13 @@ func ExampleNtuple_scan() {
if err != nil {
log.Fatal(err)
}
defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

var (
v1min = +math.MaxFloat64
v1max = -math.MaxFloat64
Expand Down Expand Up @@ -119,7 +129,12 @@ func ExampleNtuple_scanH1D() {
if err != nil {
log.Fatal(err)
}
defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

h, err := nt.ScanH1D("v1", nil)
if err != nil {
Expand Down
48 changes: 36 additions & 12 deletions hbook/ntup/ntcsv/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ func ExampleOpen() {
if err != nil {
log.Fatal(err)
}

defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan("v1, v2, v3", func(i int64, f float64, s string) error {
fmt.Printf("%d %f %q\n", i, f, s)
Expand Down Expand Up @@ -60,8 +64,12 @@ func ExampleOpen_fromRemote() {
if err != nil {
log.Fatal(err)
}

defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan("v1, v2, v3", func(i int64, f float64, s string) error {
fmt.Printf("%d %f %q\n", i, f, s)
Expand Down Expand Up @@ -95,8 +103,12 @@ func ExampleOpen_withDefaultVarNames() {
if err != nil {
log.Fatal(err)
}

defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan("var1, var2, var3", func(i int64, f float64, s string) error {
fmt.Printf("%d %f %q\n", i, f, s)
Expand Down Expand Up @@ -133,8 +145,12 @@ func ExampleOpen_withHeader() {
if err != nil {
log.Fatal(err)
}

defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan("v1, v2, v3", func(i int64, f float64, s string) error {
fmt.Printf("%d %f %q\n", i, f, s)
Expand Down Expand Up @@ -170,8 +186,12 @@ func ExampleOpen_withHeaderAndImplicitColumns() {
if err != nil {
log.Fatal(err)
}

defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan("i, f, str", func(i int64, f float64, s string) error {
fmt.Printf("%d %f %q\n", i, f, s)
Expand Down Expand Up @@ -208,8 +228,12 @@ func ExampleOpen_withHeaderAndExlicitColumns() {
if err != nil {
log.Fatal(err)
}

defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan("v1, v2, v3", func(i int64, f float64, s string) error {
fmt.Printf("%d %f %q\n", i, f, s)
Expand Down
7 changes: 6 additions & 1 deletion hbook/ntup/ntcsv/ntcsv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ func testCSV(t *testing.T, name, query string, opts ...ntcsv.Option) {
if err != nil {
t.Fatalf("%s: error opening n-tuple: %v", name, err)
}
defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
t.Fatal(err)
}
}()

type dataType struct {
i int64
Expand Down
7 changes: 6 additions & 1 deletion hbook/ntup/ntroot/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ func ExampleOpen() {
if err != nil {
log.Fatalf("could not open n-tuple: %+v", err)
}
defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
log.Fatal(err)
}
}()

err = nt.Scan(
"(one, two, three)",
Expand Down
2 changes: 1 addition & 1 deletion hbook/ntup/ntroot/ntroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestOpen(t *testing.T) {
t.Run(tc.name+":"+tc.tree, func(t *testing.T) {
nt, err := ntroot.Open(tc.name, tc.tree)
if err == nil {
nt.DB().Close()
_ = nt.DB().Close()
}

switch {
Expand Down
7 changes: 6 additions & 1 deletion hbook/ntup/ntuple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,12 @@ func TestCreateInvalid(t *testing.T) {
t.Fatalf("got=%v. want=%v", err, tc.err)
}
if nt != nil {
defer nt.DB().Close()
defer func() {
err = nt.DB().Close()
if err != nil {
t.Fatal(err)
}
}()
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion hepmc/hepmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ type Weights struct {
}

// Add adds a new weight with name n and value v.
func (w Weights) Add(n string, v float64) error {
func (w *Weights) Add(n string, v float64) error {
_, ok := w.Map[n]
if ok {
return fmt.Errorf("hepmc.Weights.Add: name [%s] already in container", n)
Expand Down
17 changes: 8 additions & 9 deletions slha/example/go-slha-basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ package main
import (
"flag"
"fmt"
"log"
"os"

"go-hep.org/x/hep/slha"
)

func handle(err error) {
if err != nil {
printf("**error: %v\n", err)
panic(err)
log.Panicf("**error: %+v\n", err)
}
}

func printf(format string, args ...interface{}) (int, error) {
return fmt.Fprintf(os.Stderr, format, args...)
}

func main() {
log.SetFlags(0)
log.SetPrefix("slha: ")

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, " $ %s <path-to-SLHA-file>\n", os.Args[0])
Expand All @@ -32,7 +31,7 @@ func main() {

flag.Parse()
if flag.NArg() <= 0 {
printf("**error** need an input file name\n")
log.Printf("**error** need an input file name\n")
flag.Usage()
os.Exit(1)
}
Expand All @@ -41,14 +40,14 @@ func main() {

f, err := os.Open(fname)
if err != nil {
printf("could not open file [%s]: %v\n", fname, err)
log.Printf("could not open file [%s]: %v\n", fname, err)
os.Exit(1)
}
defer f.Close()

data, err := slha.Decode(f)
if err != nil {
printf("could not decode file [%s]: %v\n", fname, err)
log.Printf("could not decode file [%s]: %v\n", fname, err)
os.Exit(1)
}

Expand Down

0 comments on commit 2811be8

Please sign in to comment.