From a06721054892ec049dcf946a6a49183263293a99 Mon Sep 17 00:00:00 2001 From: Rick Calixte <10281587+rcalixte@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:33:51 -0500 Subject: [PATCH] genbindings: Lint cleanup --- cmd/genbindings/clang2il.go | 5 +---- cmd/genbindings/config-libraries.go | 17 +++-------------- cmd/genbindings/emitgo.go | 2 +- cmd/genbindings/intermediate.go | 7 +------ cmd/genbindings/main.go | 15 +++++++-------- 5 files changed, 13 insertions(+), 33 deletions(-) diff --git a/cmd/genbindings/clang2il.go b/cmd/genbindings/clang2il.go index 77a0f34e..06fc13b1 100644 --- a/cmd/genbindings/clang2il.go +++ b/cmd/genbindings/clang2il.go @@ -890,10 +890,7 @@ func parseSingleTypeString(p string) CppParameter { } } insert.ParameterType = strings.TrimSpace(insert.ParameterType) - - if strings.HasPrefix(insert.ParameterType, `::`) { - insert.ParameterType = insert.ParameterType[2:] - } + insert.ParameterType = strings.TrimPrefix(insert.ParameterType, "::") return insert } diff --git a/cmd/genbindings/config-libraries.go b/cmd/genbindings/config-libraries.go index e10e050b..64f0b9fc 100644 --- a/cmd/genbindings/config-libraries.go +++ b/cmd/genbindings/config-libraries.go @@ -42,11 +42,7 @@ func ProcessLibraries(clangBin, outDir, extraLibsDir string) { func(fullpath string) bool { // Only include the same json, xml, cbor files excluded above fname := filepath.Base(fullpath) - if strings.HasPrefix(fname, "qcbor") { - return true - } - - return false + return strings.HasPrefix(fname, "qcbor") }, clangBin, pkgConfigCflags("Qt5Core"), @@ -156,11 +152,7 @@ func ProcessLibraries(clangBin, outDir, extraLibsDir string) { func(fullpath string) bool { // Only include the same json, xml, cbor files excluded above fname := filepath.Base(fullpath) - if strings.HasPrefix(fname, "qcbor") { - return true - } - - return false + return strings.HasPrefix(fname, "qcbor") }, clangBin, pkgConfigCflags("Qt6Core"), @@ -189,10 +181,7 @@ func ProcessLibraries(clangBin, outDir, extraLibsDir string) { }, func(fullpath string) bool { fname := filepath.Base(fullpath) - if fname == "qtnetwork-config.h" { - return false - } - return true + return fname != "qtnetwork-config.h" }, clangBin, "--std=c++17 "+pkgConfigCflags("Qt6Network"), diff --git a/cmd/genbindings/emitgo.go b/cmd/genbindings/emitgo.go index 7cc8c8cc..12f505a3 100644 --- a/cmd/genbindings/emitgo.go +++ b/cmd/genbindings/emitgo.go @@ -839,7 +839,7 @@ import "C" // Fixup imports if len(gfs.imports) > 0 { allImports := make([]string, 0, len(gfs.imports)) - for k, _ := range gfs.imports { + for k := range gfs.imports { if k == "libmiqt" { allImports = append(allImports, `"`+BaseModule+`/libmiqt"`) } else { diff --git a/cmd/genbindings/intermediate.go b/cmd/genbindings/intermediate.go index cfc5aee9..102d29c8 100644 --- a/cmd/genbindings/intermediate.go +++ b/cmd/genbindings/intermediate.go @@ -307,13 +307,8 @@ func (nm CppMethod) IsReceiverMethod() bool { } func (nm CppMethod) SafeMethodName() string { - - tmp := nm.MethodName - // Strip redundant Qt prefix, we know these are all Qt functions - if strings.HasPrefix(tmp, "qt_") { - tmp = tmp[3:] - } + tmp := strings.TrimPrefix(nm.MethodName, "qt_") // Operator-overload methods have names not representable in binding // languages. Replace more specific cases first diff --git a/cmd/genbindings/main.go b/cmd/genbindings/main.go index 971adfc0..7cb04d84 100644 --- a/cmd/genbindings/main.go +++ b/cmd/genbindings/main.go @@ -5,7 +5,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -133,7 +132,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b cacheFile := cacheFilePath(inputHeader) - astJson, err := ioutil.ReadFile(cacheFile) + astJson, err := os.ReadFile(cacheFile) if err != nil { panic("Expected cache to be created for " + inputHeader + ", but got error " + err.Error()) } @@ -197,7 +196,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b panic(err) } - err = ioutil.WriteFile(cacheFilePath(parsed.Filename)+".ours.json", jb, 0644) + err = os.WriteFile(cacheFilePath(parsed.Filename)+".ours.json", jb, 0644) if err != nil { panic(err) } @@ -236,7 +235,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b panic(err) } - err = ioutil.WriteFile(outputName+".go", []byte(goSrc), 0644) + err = os.WriteFile(outputName+".go", []byte(goSrc), 0644) if err != nil { panic(err) } @@ -246,7 +245,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b panic(err) } - err = ioutil.WriteFile(outputName+".cpp", []byte(bindingCppSrc), 0644) + err = os.WriteFile(outputName+".cpp", []byte(bindingCppSrc), 0644) if err != nil { panic(err) } @@ -256,7 +255,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b panic(err) } - err = ioutil.WriteFile(outputName+".h", []byte(bindingHSrc), 0644) + err = os.WriteFile(outputName+".h", []byte(bindingHSrc), 0644) if err != nil { panic(err) } @@ -270,7 +269,7 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b func generateClangCaches(includeFiles []string, clangBin string, cflags []string, matcher ClangMatcher) { - var clangChan = make(chan string, 0) + var clangChan = make(chan string) var clangWg sync.WaitGroup ctx := context.Background() @@ -298,7 +297,7 @@ func generateClangCaches(includeFiles []string, clangBin string, cflags []string panic(err) } - err = ioutil.WriteFile(cacheFilePath(inputHeader), jb, 0644) + err = os.WriteFile(cacheFilePath(inputHeader), jb, 0644) if err != nil { panic(err) }