Skip to content

Commit

Permalink
Merge pull request #24 from tri-adam/gofumpt
Browse files Browse the repository at this point in the history
Improve Documentation and Formatting
  • Loading branch information
tri-adam authored Jun 16, 2021
2 parents 920740b + e11ace5 commit 2206ae4
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 52 deletions.
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ linters:
- gocritic
- godot
- godox
- gofmt
- gofumpt
- goimports
- gomodguard
- goprintffuncname
Expand All @@ -37,7 +37,5 @@ linters:
- whitespace

linters-settings:
gofmt:
simplify: true
misspell:
locale: US
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool":"golangci-lint",
"go.lintFlags": [
"--fast"
]
}
27 changes: 9 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 13 additions & 11 deletions cmd/siftool/modif.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/integrity/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/integrity/verify_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
@@ -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 <yhcote@gmail.com> All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sif/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sif/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sif/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 5 additions & 10 deletions pkg/sif/sif.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/siftool/siftool.go
Original file line number Diff line number Diff line change
@@ -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 <yhcote@gmail.com> All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2206ae4

Please sign in to comment.