Skip to content

Commit

Permalink
Update golangci-lint config and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed Jun 13, 2023
1 parent 3acc108 commit 90a74c4
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 38 deletions.
42 changes: 37 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,55 @@

linters:
enable:
- deadcode
- errcheck
- goimports
# - revive
- revive
- ineffassign
- structcheck
- varcheck
- govet
- unconvert
- staticcheck
- gosimple
- stylecheck
- unused
- misspell
#- prealloc
#- maligned
disable-all: true

issues:
# Enable some lints excluded by default
exclude-use-default: false

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-per-linter: 0
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

exclude-rules:

- linters:
- staticcheck
text: 'SA1019: "github.com/rclone/rclone/cmd/serve/httplib" is deprecated'

run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m

linters-settings:
revive:
rules:
- name: unreachable-code
disabled: true
- name: unused-parameter
disabled: true
- name: empty-block
disabled: true
- name: redefines-builtin-id
disabled: true
- name: superfluous-else
disabled: true
stylecheck:
# Only enable the checks performed by the staticcheck stand-alone tool,
# as documented here: https://staticcheck.io/docs/configuration/options/#checks
checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
6 changes: 4 additions & 2 deletions largeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
)

// NotLargeObject is returned if an operation is performed on an object which isn't large.
var NotLargeObject = errors.New("Not a large object")
//
//nolint:stylecheck
var NotLargeObject = errors.New("not a large object")

// readAfterWriteTimeout defines the time we wait before an object appears after having been uploaded
var readAfterWriteTimeout = 15 * time.Second
Expand Down Expand Up @@ -309,7 +311,7 @@ func withLORetry(expectedSize int64, fn func() (Headers, int64, error)) (err err
select {
case <-endTimer.C:
waitTimer.Stop()
err = fmt.Errorf("Timeout expired while waiting for object to have size == %d, got: %d", expectedSize, sz)
err = fmt.Errorf("timeout expired while waiting for object to have size == %d, got: %d", expectedSize, sz)
return
case <-waitTimer.C:
waitingTime *= 2
Expand Down
2 changes: 1 addition & 1 deletion rs/rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *RsConnection) manage(ctx context.Context, p swift.RequestOpts) (resp *h
c.cdnUrl = c.Auth.CdnUrl()
}
if c.cdnUrl == "" {
return "", errors.New("The X-CDN-Management-Url does not exist on the authenticated platform")
return "", errors.New("the X-CDN-Management-Url does not exist on the authenticated platform")
}
return c.cdnUrl, nil
}
Expand Down
3 changes: 3 additions & 0 deletions slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type StaticLargeObjectCreateFile struct {
largeObjectCreateFile
}

// SLONotSupported is returned as an error when Static Large Objects are not supported.
//
//nolint:stylecheck
var SLONotSupported = errors.New("SLO not supported")

type swiftSegment struct {
Expand Down
14 changes: 7 additions & 7 deletions swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func setFromEnv(param interface{}, name string) (err error) {
*result, err = strconv.Atoi(val)
}
case *bool:
if *result == false {
if !*result {
*result, err = strconv.ParseBool(val)
}
case *time.Duration:
Expand Down Expand Up @@ -609,7 +609,7 @@ func (c *Connection) authenticated() bool {
if c.Expires.IsZero() {
return true
}
timeUntilExpiry := c.Expires.Sub(time.Now())
timeUntilExpiry := time.Until(c.Expires)
return timeUntilExpiry >= 60*time.Second
}

Expand Down Expand Up @@ -655,7 +655,7 @@ func (c *Connection) QueryInfo(ctx context.Context) (infos SwiftInfo, err error)
if err == nil {
if resp.StatusCode != http.StatusOK {
drainAndClose(resp.Body, nil)
return nil, fmt.Errorf("Invalid status code for info request: %d", resp.StatusCode)
return nil, fmt.Errorf("invalid status code for info request: %d", resp.StatusCode)
}
err = readJson(resp, &infos)
if err == nil {
Expand Down Expand Up @@ -760,7 +760,7 @@ func (c *Connection) Call(ctx context.Context, targetUrl string, p RequestOpts)
if k == "Content-Length" {
req.ContentLength, err = strconv.ParseInt(v, 10, 64)
if err != nil {
err = fmt.Errorf("Invalid %q header %q: %v", k, v, err)
err = fmt.Errorf("invalid %q header %q: %v", k, v, err)
return
}
} else {
Expand Down Expand Up @@ -1141,7 +1141,7 @@ func (c *Connection) Objects(ctx context.Context, container string, opts *Object

// objectsAllOpts makes a copy of opts if set or makes a new one and
// overrides Limit and Marker
// Marker is not overriden if KeepMarker is set
// Marker is not overridden if KeepMarker is set
func objectsAllOpts(opts *ObjectsOpts, Limit int) *ObjectsOpts {
var newOpts ObjectsOpts
if opts != nil {
Expand Down Expand Up @@ -1443,7 +1443,7 @@ func (file *ObjectCreateFile) Headers() (Headers, error) {
select {
case <-file.done:
default:
return nil, fmt.Errorf("Cannot get metadata, object upload failed or has not yet completed.")
return nil, fmt.Errorf("cannot get metadata, object upload failed or has not yet completed")
}
return file.headers, nil
}
Expand Down Expand Up @@ -1910,7 +1910,7 @@ func (c *Connection) ObjectTempUrl(container string, objectName string, secretKe

// parseResponseStatus parses string like "200 OK" and returns Error.
//
// For status codes beween 200 and 299, this returns nil.
// For status codes between 200 and 299, this returns nil.
func parseResponseStatus(resp string, errorMap errorMap) error {
code := 0
reason := resp
Expand Down
8 changes: 4 additions & 4 deletions swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ func TestObjectUpdate(t *testing.T) {
}

func checkTime(t *testing.T, when time.Time, low, high int) {
dt := time.Now().Sub(when)
dt := time.Since(when)
if dt < time.Duration(low)*time.Second || dt > time.Duration(high)*time.Second {
t.Errorf("Time is wrong: dt=%q, when=%q", dt, when)
}
Expand Down Expand Up @@ -2471,7 +2471,7 @@ func TestDLOCreateMissingSegmentsInList(t *testing.T) {

listURL := "/v1/AUTH_" + swifttest.TEST_ACCOUNT + "/" + SEGMENTS_CONTAINER
srv.SetOverride(listURL, func(w http.ResponseWriter, r *http.Request, recorder *httptest.ResponseRecorder) {
for k, v := range recorder.HeaderMap {
for k, v := range recorder.Result().Header {
w.Header().Set(k, v[0])
}
w.WriteHeader(recorder.Code)
Expand Down Expand Up @@ -2543,7 +2543,7 @@ func TestDLOCreateIncorrectSize(t *testing.T) {
headCount := 0
expectedHeadCount := 5
srv.SetOverride(listURL, func(w http.ResponseWriter, r *http.Request, recorder *httptest.ResponseRecorder) {
for k, v := range recorder.HeaderMap {
for k, v := range recorder.Result().Header {
w.Header().Set(k, v[0])
}
if r.Method == "HEAD" {
Expand Down Expand Up @@ -3172,7 +3172,7 @@ func testSegmentation(t *testing.T, c *swift.Connection, createObj func() swift.
t.Error(err)
}
if i < len(tCase.seeks)-1 {
_, err = out.Seek(int64(tCase.seeks[i]), os.SEEK_CUR)
_, err = out.Seek(int64(tCase.seeks[i]), io.SeekCurrent)
if err != nil {
t.Error(err)
}
Expand Down
19 changes: 4 additions & 15 deletions swifttest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,6 @@ func (r containerResource) put(a *action) interface{} {
header, err := reader.Next()
if err == io.EOF {
break
} else if err != nil {
//return location, err
}
if header == nil {
continue
Expand Down Expand Up @@ -733,7 +731,7 @@ func (objr objectResource) put(a *action) interface{} {
fatalf(400, "TODO", "read error")
}
gotHash := sum.Sum(nil)
if expectHash != nil && bytes.Compare(gotHash, expectHash) != 0 {
if expectHash != nil && !bytes.Equal(gotHash, expectHash) {
fatalf(422, "Bad ETag", "The ETag you specified did not match what we received")
}
if a.req.ContentLength >= 0 && int64(len(data)) != a.req.ContentLength {
Expand Down Expand Up @@ -876,7 +874,7 @@ func (objr objectResource) copy(a *action) interface{} {
fatalf(400, "Bad Request", "Destination must point to a valid object path")
}

if objr2.container.name != objr2.container.name && obj2.name != obj.name {
if objr2.container.name != objr.container.name && obj2.name != obj.name {
obj2.Lock()
defer obj2.Unlock()
}
Expand Down Expand Up @@ -1083,7 +1081,7 @@ var pathRegexp = regexp.MustCompile("/v1/AUTH_([a-zA-Z0-9]+)(/([^/]+)(/(.*))?)?"
func (srv *SwiftServer) parseURL(u *url.URL) (account string, container string, object string, err error) {
m := pathRegexp.FindStringSubmatch(u.Path)
if m == nil {
return "", "", "", fmt.Errorf("Couldn't parse the specified URI")
return "", "", "", fmt.Errorf("couldn't parse the specified URI")
}
account = m[1]
container = m[3]
Expand Down Expand Up @@ -1141,9 +1139,6 @@ func (srv *SwiftServer) resourceForURL(u *url.URL) (r resource) {
return objr
}

// nullResource has error stubs for all resource methods.
type nullResource struct{}

func notAllowed() interface{} {
fatalf(400, "MethodNotAllowed", "The specified method is not allowed against this resource")
return nil
Expand All @@ -1154,12 +1149,6 @@ func notAuthorized() interface{} {
return nil
}

func (nullResource) put(a *action) interface{} { return notAllowed() }
func (nullResource) get(a *action) interface{} { return notAllowed() }
func (nullResource) post(a *action) interface{} { return notAllowed() }
func (nullResource) delete(a *action) interface{} { return notAllowed() }
func (nullResource) copy(a *action) interface{} { return notAllowed() }

type rootResource struct{}

func (rootResource) put(a *action) interface{} { return notAllowed() }
Expand Down Expand Up @@ -1301,7 +1290,7 @@ func (r rootResource) delete(a *action) interface{} {
func (rootResource) copy(a *action) interface{} { return notAllowed() }

func NewSwiftServer(address string) (*SwiftServer, error) {
if strings.Index(address, ":") == -1 {
if !strings.Contains(address, ":") {
address += ":0"
}
l, err := net.Listen("tcp", address)
Expand Down
6 changes: 2 additions & 4 deletions watchdog_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ func setupTimer(initialTimeout time.Duration) (timer *time.Timer, fired <-chan b
started := make(chan bool)
go func() {
started <- true
select {
case <-timer.C:
firedChan <- true
}
<-timer.C
firedChan <- true
}()
<-started
return timer, firedChan
Expand Down

0 comments on commit 90a74c4

Please sign in to comment.