Skip to content
Open
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
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ version: "2"
linters:
enable:
- errorlint
- gocritic
- modernize
- revive
- unconvert
- unparam
exclusions:
Expand All @@ -11,6 +14,28 @@ linters:
- comments
- std-error-handling
settings:
gocritic:
disabled-checks:
- appendAssign
- builtinShadow
- deferInLoop
- hugeParam
- unnamedResult
- whyNoLint
enable-all: true
revive:
enable-all-rules: false
enable-default-rules: true
max-open-files: 2048
rules:
- name: dot-imports
disabled: true
- name: package-comments
disabled: true
- name: redefines-builtin-id
disabled: true
- name: var-naming
disabled: true
staticcheck:
# Enable all options, with some exceptions.
# For defaults, see https://golangci-lint.run/usage/linters/#staticcheck
Expand All @@ -24,3 +49,7 @@ formatters:
- gofumpt
exclusions:
generated: disable

issues:
max-issues-per-linter: 0
max-same-issues: 0
7 changes: 4 additions & 3 deletions capability/capability_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ func mkString(c Capabilities, max CapType) (ret string) {
ret = "{"
for i := CapType(1); i <= max; i <<= 1 {
ret += " " + i.String() + "=\""
if c.Empty(i) {
switch {
case c.Empty(i):
ret += "empty"
} else if c.Full(i) {
case c.Full(i):
ret += "full"
} else {
default:
ret += c.StringCap(i)
}
ret += "\""
Expand Down
2 changes: 1 addition & 1 deletion capability/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestNewPid2Load(t *testing.T) {
// Assuming that at least bounding set is not empty.
bset := c.StringCap(BOUNDING)
t.Logf("Bounding set: %s", bset)
if len(bset) == 0 {
if bset == "" {
t.Fatal("loaded bounding set: want non-empty, got empty")
}
}
Expand Down
6 changes: 3 additions & 3 deletions devices/device_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDeviceFromPathLstatFailure(t *testing.T) {
testError := errors.New("test error")

// Override unix.Lstat to inject error.
unixLstat = func(path string, stat *unix.Stat_t) error {
unixLstat = func(_ string, _ *unix.Stat_t) error {
return testError
}
defer cleanupTest()
Expand All @@ -57,7 +57,7 @@ func TestHostDevicesIoutilReadDirFailure(t *testing.T) {
testError := errors.New("test error")

// Override os.ReadDir to inject error.
osReadDir = func(dirname string) ([]fs.DirEntry, error) {
osReadDir = func(_ string) ([]fs.DirEntry, error) {
return nil, testError
}
defer cleanupTest()
Expand All @@ -73,7 +73,7 @@ func TestHostDevicesIoutilReadDirDeepFailure(t *testing.T) {
called := false

// Override os.ReadDir to inject error after the first call.
osReadDir = func(dirname string) ([]fs.DirEntry, error) {
osReadDir = func(_ string) ([]fs.DirEntry, error) {
if called {
return nil, testError
}
Expand Down
2 changes: 1 addition & 1 deletion mount/mounter_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func ensureUnmount(t *testing.T, mnt string) {
}

// validateMount checks that mnt has the given options
func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
func validateMount(t *testing.T, mnt, opts, optional, vfs string) {
info, err := mountinfo.GetMounts(nil)
if err != nil {
t.Fatal(err)
Expand Down
8 changes: 3 additions & 5 deletions mount/sharedsubtree_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ func TestSubtreeUnbindable(t *testing.T) {
} else if err == nil {
t.Fatalf("%q should not have been bindable", sourceDir)
}
defer func() {
if err := Unmount(targetDir); err != nil {
t.Fatal(err)
}
}()
if err := Unmount(targetDir); err != nil {
t.Fatal(err)
}
}
6 changes: 2 additions & 4 deletions mountinfo/mounted_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var testMounts = []testMount{
{
desc: "non-existent path",
isNotExist: true,
prepare: func(t *testing.T) string {
prepare: func(_ *testing.T) string {
return "/non/existent/path"
},
},
Expand Down Expand Up @@ -385,9 +385,7 @@ func TestMountedBy(t *testing.T) {
t.Errorf("%s: expected false on error", name)
}
} else if mounted != tc.isMount {
if tc.isBind && strings.HasSuffix(name, "mountedByStat") {
// mountedByStat can not detect bind mounts.
} else {
if !tc.isBind || !strings.HasSuffix(name, "mountedByStat") {
t.Errorf("%s: expected %v, got %v", name, tc.isMount, mounted)
}
}
Comment thread
mmorel-35 marked this conversation as resolved.
Expand Down
2 changes: 1 addition & 1 deletion reexec/reexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestDispatch(t *testing.T) {
}{
{
name: "not-registered",
ctx: func(t *testing.T) context.Context {
ctx: func(_ *testing.T) context.Context {
return context.Background()
},
check: func(t *testing.T, ok bool, err error) {
Expand Down
4 changes: 2 additions & 2 deletions signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func ParseSignal(rawSignal string) (syscall.Signal, error) {
}
return syscall.Signal(s), nil
}
signal, ok := SignalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
sig, ok := SignalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
if !ok {
return -1, fmt.Errorf("invalid signal: %s", rawSignal)
}
return signal, nil
return sig, nil
}

// ValidSignalForPlatform returns true if a signal is valid on the platform
Expand Down
8 changes: 4 additions & 4 deletions user/idtools_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ func mkdirAs(path string, mode os.FileMode, uid, gid int, mkAll, onlyNew bool) e
paths = append(paths, dirPath)
}
}
if err = os.MkdirAll(path, mode); err != nil {
if err := os.MkdirAll(path, mode); err != nil {
return err
}
} else if err = os.Mkdir(path, mode); err != nil {
} else if err := os.Mkdir(path, mode); err != nil {
return err
}
// even if it existed, we will chown the requested path + any subpaths that
// didn't exist when we called MkdirAll
for _, pathComponent := range paths {
if err = setPermissions(pathComponent, mode, uid, gid, nil); err != nil {
if err := setPermissions(pathComponent, mode, uid, gid, nil); err != nil {
return err
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func lookupSubRangesFile(path string, usr User) ([]IDMap, error) {
ParentID: idrange.SubID,
Count: idrange.Count,
})
containerID = containerID + idrange.Count
containerID += idrange.Count
}
return idMap, nil
}