diff --git a/.golangci.yml b/.golangci.yml index c3629a5b..43cb3c94 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,7 +13,7 @@ linters: - gocritic - godot - godox - - gofmt + - gofumpt - goimports - gomodguard - goprintffuncname @@ -37,7 +37,5 @@ linters: - whitespace linters-settings: - gofmt: - simplify: true misspell: locale: US diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..4009c66d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "go.lintTool":"golangci-lint", + "go.lintFlags": [ + "--fast" + ] +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 07822bfd..1e0c7284 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,24 +26,15 @@ all your interactions with the project members and users. #### Process -1. Essential bug fix PRs should be sent to both master and release branches. -2. Small bug fix and feature enhancement PRs should be sent to master only. -3. Follow the existing code style precedent, especially for C. For Golang, you - will mostly conform to the style and form enforced by the "go fmt" and - "golint" tools for proper formatting. -4. Ensure any install or build dependencies are removed before doing a build - to test your PR locally. -5. For any new functionality, please write appropriate go tests that will run - as part of the Continuous Integration (Circle CI) system. -6. The project's default copyright and header have been included in any new - source files. -7. Make sure you have implemented a local `make test` and all tests succeed - before submitting the PR. -8. Is the code human understandable? This can be accomplished via a clear code - style as well as documentation and/or comments. -9. The pull request will be reviewed by others, and finally merged when all - requirements are met. -10. Documentation must be provided if necessary (next section) +1. Essential bug fix PRs should be sent to both `master` and release branches (if applicable). +1. Small bug fix and feature enhancement PRs should be sent to `master` only. +1. Follow the existing code style precedent. Use [golangci-lint](https://golangci-lint.run) to ensure your code is properly formatted and free of lint. +1. For any new functionality, please write appropriate tests that will run as part of the continuous integration system ([CircleCI](https://circleci.com/gh/sylabs/workflows/sif)). +1. Ensure the project's default copyright and header have been included in any new source files. +1. Make sure you have run `go test ./...` and all tests succeed before submitting the PR. +1. Is the code human understandable? This can be accomplished via a clear code style as well as documentation and/or comments. +1. The pull request will be reviewed by others, and finally merged when all requirements are met. +1. Documentation must be provided if necessary (next section) #### Documentation diff --git a/cmd/siftool/modif.go b/cmd/siftool/modif.go index ba439a9d..34a3490b 100644 --- a/cmd/siftool/modif.go +++ b/cmd/siftool/modif.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018, Sylabs Inc. All rights reserved. +// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE file distributed with the sources of this project regarding your // rights to use or distribute this software. @@ -14,16 +14,18 @@ import ( "github.com/sylabs/sif/pkg/sif" ) -var datatype = flag.Int64("datatype", -1, "") -var parttype = flag.Int64("parttype", -1, "") -var partfs = flag.Int64("partfs", -1, "") -var partarch = flag.Int64("partarch", -1, "") -var signhash = flag.Int64("signhash", -1, "") -var signentity = flag.String("signentity", "", "") -var groupid = flag.Int64("groupid", sif.DescrUnusedGroup, "") -var link = flag.Int64("link", sif.DescrUnusedLink, "") -var alignment = flag.Int("alignment", 0, "") -var filename = flag.String("filename", "", "") +var ( + datatype = flag.Int64("datatype", -1, "") + parttype = flag.Int64("parttype", -1, "") + partfs = flag.Int64("partfs", -1, "") + partarch = flag.Int64("partarch", -1, "") + signhash = flag.Int64("signhash", -1, "") + signentity = flag.String("signentity", "", "") + groupid = flag.Int64("groupid", sif.DescrUnusedGroup, "") + link = flag.Int64("link", sif.DescrUnusedLink, "") + alignment = flag.Int("alignment", 0, "") + filename = flag.String("filename", "", "") +) func cmdNew(args []string) error { if len(args) != 1 { diff --git a/pkg/integrity/verify.go b/pkg/integrity/verify.go index 83a292b1..2fd9adde 100644 --- a/pkg/integrity/verify.go +++ b/pkg/integrity/verify.go @@ -58,6 +58,7 @@ func (e *SignatureNotValidError) Is(target error) bool { return e.ID == t.ID || t.ID == 0 } +// VerifyResult is the interface that each verification result implements. type VerifyResult interface { // Signature returns the ID of the signature object associated with the result. Signature() uint32 @@ -520,7 +521,7 @@ func OptVerifyCallback(cb VerifyCallback) VerifierOpt { } // getTasks returns verification tasks corresponding to groupIDs and objectIDs. -func getTasks(f *sif.FileImage, cb VerifyCallback, groupIDs []uint32, objectIDs []uint32) ([]verifyTask, error) { +func getTasks(f *sif.FileImage, cb VerifyCallback, groupIDs, objectIDs []uint32) ([]verifyTask, error) { t := make([]verifyTask, 0, len(groupIDs)+len(objectIDs)) for _, groupID := range groupIDs { @@ -548,7 +549,7 @@ func getTasks(f *sif.FileImage, cb VerifyCallback, groupIDs []uint32, objectIDs } // getLegacyTasks returns legacy verification tasks corresponding to groupIDs and objectIDs. -func getLegacyTasks(f *sif.FileImage, cb VerifyCallback, groupIDs []uint32, objectIDs []uint32) ([]verifyTask, error) { +func getLegacyTasks(f *sif.FileImage, cb VerifyCallback, groupIDs, objectIDs []uint32) ([]verifyTask, error) { t := make([]verifyTask, 0, len(groupIDs)+len(objectIDs)) for _, groupID := range groupIDs { diff --git a/pkg/integrity/verify_test.go b/pkg/integrity/verify_test.go index 3dc9e105..9289f559 100644 --- a/pkg/integrity/verify_test.go +++ b/pkg/integrity/verify_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020, Sylabs Inc. All rights reserved. +// Copyright (c) 2020-2021, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file // distributed with the sources of this project regarding your rights to use or distribute this // software. @@ -903,6 +903,7 @@ type mockVerifier struct { func (v mockVerifier) fingerprints() ([][20]byte, error) { return v.fps, v.err } + func (v mockVerifier) verifyWithKeyRing(kr openpgp.KeyRing) error { return v.err } diff --git a/pkg/sif/create.go b/pkg/sif/create.go index e06eef4a..98ec9264 100644 --- a/pkg/sif/create.go +++ b/pkg/sif/create.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved. +// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved. // Copyright (c) 2017, SingularityWare, LLC. All rights reserved. // Copyright (c) 2017, Yannick Cote All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the @@ -237,7 +237,7 @@ func CreateContainer(cinfo CreateInfo) (fimg *FileImage, err error) { fimg.Header.Dataoff = DataStartOffset // Create container file - fimg.Fp, err = os.OpenFile(cinfo.Pathname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + fimg.Fp, err = os.OpenFile(cinfo.Pathname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755) if err != nil { return nil, fmt.Errorf("container file creation failed: %s", err) } diff --git a/pkg/sif/create_test.go b/pkg/sif/create_test.go index 52ee6876..99e2fadb 100644 --- a/pkg/sif/create_test.go +++ b/pkg/sif/create_test.go @@ -382,7 +382,7 @@ func cpFile(fromFile, toFile string) error { } defer s.Close() - d, err := os.OpenFile(toFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777) + d, err := os.OpenFile(toFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o777) if err != nil { return err } diff --git a/pkg/sif/load_test.go b/pkg/sif/load_test.go index cc52385e..1e5860eb 100644 --- a/pkg/sif/load_test.go +++ b/pkg/sif/load_test.go @@ -76,7 +76,7 @@ func (m *mockFileInfo) Size() int64 { } func (m *mockFileInfo) Mode() os.FileMode { - return 0644 + return 0o644 } func (m *mockFileInfo) ModTime() time.Time { diff --git a/pkg/sif/lookup.go b/pkg/sif/lookup.go index d0c8b02c..2cb1ab16 100644 --- a/pkg/sif/lookup.go +++ b/pkg/sif/lookup.go @@ -77,7 +77,7 @@ func (fimg *FileImage) GetHeader() *Header { // GetFromDescrID searches for a descriptor with. func (fimg *FileImage) GetFromDescrID(id uint32) (*Descriptor, int, error) { - var match = -1 + match := -1 for i, v := range fimg.DescrArr { if !v.Used { diff --git a/pkg/sif/sif.go b/pkg/sif/sif.go index 09c05a78..08f8d0ac 100644 --- a/pkg/sif/sif.go +++ b/pkg/sif/sif.go @@ -316,16 +316,13 @@ type Descriptor struct { } // Deffile represents the SIF definition-file data object descriptor. -type Deffile struct { -} +type Deffile struct{} // Labels represents the SIF JSON-labels data object descriptor. -type Labels struct { -} +type Labels struct{} // Envvar represents the SIF envvar data object descriptor. -type Envvar struct { -} +type Envvar struct{} // Partition represents the SIF partition data object descriptor. type Partition struct { @@ -341,12 +338,10 @@ type Signature struct { } // GenericJSON represents the SIF generic JSON meta-data data object descriptor. -type GenericJSON struct { -} +type GenericJSON struct{} // Generic represents the SIF generic data object descriptor. -type Generic struct { -} +type Generic struct{} // CryptoMessage represents the SIF crypto message object descriptor. type CryptoMessage struct { diff --git a/pkg/siftool/siftool.go b/pkg/siftool/siftool.go index 7bc526ff..12d41649 100644 --- a/pkg/siftool/siftool.go +++ b/pkg/siftool/siftool.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2019, Sylabs Inc. All rights reserved. +// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved. // Copyright (c) 2017, SingularityWare, LLC. All rights reserved. // Copyright (c) 2017, Yannick Cote All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the @@ -31,7 +31,7 @@ func Siftool() *cobra.Command { // A set of commands are provided to display elements such as the SIF global // header, the data object descriptors and to dump data objects. It is also // possible to modify a SIF file via this tool via the add/del commands. - var Siftool = &cobra.Command{ + Siftool := &cobra.Command{ Use: "sif", Short: "siftool is a program for Singularity Image Format (SIF) file manipulation", Long: siftoolLong,