Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint #2010

Merged
merged 53 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1eaf754
Print out lint results
gapra-msft Jan 3, 2023
19062e5
Fixed errcheck errors
gapra-msft Jan 4, 2023
8aaee4a
Fixed some gosimple errors
gapra-msft Jan 4, 2023
3ddf75f
Add Golang CI Lint Action
gapra-msft Jan 4, 2023
34838ab
Fix CI yml file
gapra-msft Jan 4, 2023
9ff0610
Fixed ineffassign errors
gapra-msft Jan 4, 2023
9f61cad
Fixed some staticcheck errors
gapra-msft Jan 4, 2023
4ced119
Fixed errcheck issues
gapra-msft Jan 4, 2023
7b89b52
Fixed some gosimple
gapra-msft Jan 4, 2023
486c0be
errcheck fixes
gapra-msft Jan 4, 2023
329f984
Fixed few more issues
gapra-msft Jan 4, 2023
d2acc2a
skip files correction
gapra-msft Jan 4, 2023
7bc2737
Fixed a few more errors
gapra-msft Jan 4, 2023
f544f20
Fixed rest of printf println issues
gapra-msft Jan 4, 2023
f857e3e
Fix all ioutil issues
gapra-msft Jan 4, 2023
c1ed142
import io
gapra-msft Jan 4, 2023
0eeb95c
Allow nolint
gapra-msft Jan 5, 2023
42434b7
Marked or removed unused code
gapra-msft Jan 5, 2023
58d1bb5
Fixed some unused errors
gapra-msft Jan 5, 2023
46c107d
Fixed a few more unused errors
gapra-msft Jan 5, 2023
dc57b31
Undo generated file changes
gapra-msft Jan 5, 2023
3d57e91
resolved more unused
gapra-msft Jan 5, 2023
54b0def
exclude S1008
gapra-msft Jan 5, 2023
2ffb093
resolved all lint issues
gapra-msft Jan 5, 2023
fc9dc20
Fix static check
gapra-msft Jan 5, 2023
30b38c2
resolve last couple checks
gapra-msft Jan 5, 2023
2e1f3cd
remove workflow
gapra-msft Jan 5, 2023
34d523b
Merge branch 'dev' into gapra/golint
gapra-msft Jan 6, 2023
ca2ea3d
Added github file
gapra-msft Jan 6, 2023
35ba21d
v2
gapra-msft Jan 6, 2023
e75eaaa
ubuntu latest
gapra-msft Jan 6, 2023
d99b38a
deadcode
gapra-msft Jan 6, 2023
25cd90f
Added deadcode
gapra-msft Jan 6, 2023
a410848
Varcheck
gapra-msft Jan 6, 2023
af442a6
Added windows and macos
gapra-msft Jan 6, 2023
97d8ef8
increase timeout
gapra-msft Jan 6, 2023
51cdbd0
windows lint
gapra-msft Jan 6, 2023
15a5997
more windows errors
gapra-msft Jan 6, 2023
375e141
ineffassign
gapra-msft Jan 6, 2023
398e1c4
replace the ci job with github action
gapra-msft Jan 6, 2023
944a992
remove todo
gapra-msft Jan 9, 2023
e6814ba
Merge branch 'dev' into gapra/golint
gapra-msft Feb 1, 2023
67e42ff
Update the linting
gapra-msft Feb 7, 2023
7bb68ec
more lint fix
gapra-msft Feb 8, 2023
38030f1
Addressed some review comments
gapra-msft Feb 8, 2023
711c7c7
Merge branch 'dev' into gapra/golint
gapra-msft Feb 21, 2023
6391c3a
clean up nolint in e2etest
gapra-msft Feb 21, 2023
1f5e002
add another lint flag
gapra-msft Feb 21, 2023
c79479e
Add log for seek on error in azbfs
gapra-msft Feb 21, 2023
6b93690
Brought back isObjectAce
gapra-msft Feb 27, 2023
2435b8f
add unused label
gapra-msft Feb 27, 2023
90aeba6
fixed nolint tag
gapra-msft Feb 27, 2023
ac396cd
added unused
gapra-msft Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: golangci-lint
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
strategy:
matrix:
go: [1.17]
os: [ubuntu-latest, windows-latest, macos-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.46
# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --tests=false --max-issues-per-linter=0 --skip-files=azbfs/zz_generated_* --skip-dirs=e2etest --exclude=S1008 --max-same-issues=0 --timeout 5m0s

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
13 changes: 4 additions & 9 deletions azbfs/zc_credential_anonymous.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ type Credential interface {
credentialMarker()
}

type credentialFunc pipeline.FactoryFunc

func (f credentialFunc) New(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.Policy {
return f(next, po)
}

// credentialMarker is a package-internal method that exists just to satisfy the Credential interface.
func (credentialFunc) credentialMarker() {}

//////////////////////////////

// NewAnonymousCredential creates an anonymous credential for use with HTTP(S) requests that read public resource
Expand All @@ -36,11 +27,15 @@ type anonymousCredentialPolicyFactory struct {
}

// New creates a credential policy object.
//nolint:unused
func (f *anonymousCredentialPolicyFactory) New(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.Policy {
// Note: We are not deleting this "unused" code since this is a publicly exported function, we do not want to break
gapra-msft marked this conversation as resolved.
Show resolved Hide resolved
// anyone that has a dependency on the azbfs library (like blobfuse).
return &anonymousCredentialPolicy{next: next}
}

// credentialMarker is a package-internal method that exists just to satisfy the Credential interface.
//nolint:unused
func (*anonymousCredentialPolicyFactory) credentialMarker() {}

// anonymousCredentialPolicy is the credential's policy object.
Expand Down
34 changes: 14 additions & 20 deletions azbfs/zc_credential_shared_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,19 @@ func (f *SharedKeyCredential) New(next pipeline.Policy, po *pipeline.PolicyOptio
// credentialMarker is a package-internal method that exists just to satisfy the Credential interface.
func (*SharedKeyCredential) credentialMarker() {}

// Constants ensuring that header names are correctly spelled and consistently cased.
const (
headerAuthorization = "Authorization"
headerCacheControl = "Cache-Control"
headerContentEncoding = "Content-Encoding"
headerContentDisposition = "Content-Disposition"
headerContentLanguage = "Content-Language"
headerContentLength = "Content-Length"
headerContentMD5 = "Content-MD5"
headerContentType = "Content-Type"
headerDate = "Date"
headerIfMatch = "If-Match"
headerIfModifiedSince = "If-Modified-Since"
headerIfNoneMatch = "If-None-Match"
headerIfUnmodifiedSince = "If-Unmodified-Since"
headerRange = "Range"
headerUserAgent = "User-Agent"
headerXmsDate = "x-ms-date"
headerXmsVersion = "x-ms-version"
headerAuthorization = "Authorization"
headerContentEncoding = "Content-Encoding"
headerContentLanguage = "Content-Language"
headerContentLength = "Content-Length"
headerContentMD5 = "Content-MD5"
headerContentType = "Content-Type"
headerIfMatch = "If-Match"
headerIfModifiedSince = "If-Modified-Since"
headerIfNoneMatch = "If-None-Match"
headerIfUnmodifiedSince = "If-Unmodified-Since"
headerRange = "Range"
headerXmsDate = "x-ms-date"
)

// ComputeHMACSHA256 generates a hash signature for an HTTP request or for a SAS.
Expand Down Expand Up @@ -143,7 +137,7 @@ func buildCanonicalizedHeader(headers http.Header) string {
ch.WriteRune(':')
ch.WriteString(strings.Join(cm[key], ","))
}
return string(ch.Bytes())
return ch.String()
}

func (f *SharedKeyCredential) buildCanonicalizedResource(u *url.URL) string {
Expand Down Expand Up @@ -190,5 +184,5 @@ func (f *SharedKeyCredential) buildCanonicalizedResource(u *url.URL) string {
cr.WriteString("\n" + paramName + ":" + strings.Join(paramValues, ","))
}
}
return string(cr.Bytes())
return cr.String()
}
27 changes: 0 additions & 27 deletions azbfs/zc_mmf_unix.go

This file was deleted.

39 changes: 0 additions & 39 deletions azbfs/zc_mmf_windows.go

This file was deleted.

4 changes: 2 additions & 2 deletions azbfs/zc_policy_request_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func NewRequestLogPolicyFactory_Deprecated(o RequestLogOptions) pipeline.Factory
sc := response.Response().StatusCode
if ((sc >= 400 && sc <= 499) && sc != http.StatusNotFound && sc != http.StatusConflict && sc != http.StatusPreconditionFailed && sc != http.StatusRequestedRangeNotSatisfiable) || (sc >= 500 && sc <= 599) {
logLevel, forceLog = pipeline.LogError, !o.SyslogDisabled // Promote to Error any 4xx (except those listed is an error) or any 5xx
} else {
// For other status codes, we leave the level as is.
}
// For other status codes, we leave the level as is.

} else { // This error did not get an HTTP response from the service; upgrade the severity to Error
logLevel, forceLog = pipeline.LogError, !o.SyslogDisabled
}
Expand Down
9 changes: 4 additions & 5 deletions azbfs/zc_policy_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package azbfs
import (
"context"
"io"
"io/ioutil"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -134,7 +133,7 @@ func (o RetryOptions) calcDelay(try int32) time.Duration { // try is >=1; never
// Note: forked from the standard package url.go
// The content is exactly the same but the spaces are encoded as %20 instead of +
// TODO: remove after the service fix
// Encode encodes the values into ``URL encoded'' form
// Encode encodes the values into URL encoded form
// ("bar=baz&foo=quux") sorted by key.
func alternativeEncode(v url.Values) string {
if v == nil {
Expand Down Expand Up @@ -217,7 +216,7 @@ func NewRetryPolicyFactory(o RetryOptions) pipeline.Factory {
// Set the server-side timeout query parameter "timeout=[seconds]"
timeout := int32(o.TryTimeout.Seconds()) // Max seconds per try
if deadline, ok := ctx.Deadline(); ok { // If user's ctx has a deadline, make the timeout the smaller of the two
t := int32(deadline.Sub(time.Now()).Seconds()) // Duration from now until user's ctx reaches its deadline
t := int32(time.Until(deadline).Seconds()) // Duration from now until user's ctx reaches its deadline
logf("MaxTryTimeout=%d secs, TimeTilDeadline=%d sec\n", timeout, t)
if t < timeout {
timeout = t
Expand Down Expand Up @@ -254,7 +253,7 @@ func NewRetryPolicyFactory(o RetryOptions) pipeline.Factory {
action = "Retry: Secondary URL returned 404"
case err != nil:
// NOTE: Protocol Responder returns non-nil if REST API returns invalid status code for the invoked operation
if netErr, ok := err.(net.Error); ok && (netErr.Temporary() || netErr.Timeout()) {
if netErr, ok := err.(net.Error); ok && (netErr.Temporary() || netErr.Timeout()) { //nolint:staticcheck
action = "Retry: net.Error and Temporary() or Timeout()"
} else if err == io.ErrUnexpectedEOF {
// Some of our methods under the zz_ files do use io.Copy and other related methods that can throw an unexpectedEOF.
Expand Down Expand Up @@ -284,7 +283,7 @@ func NewRetryPolicyFactory(o RetryOptions) pipeline.Factory {
}
if response != nil && response.Response() != nil {
// If we're going to retry and we got a previous response, then flush its body to avoid leaking its TCP connection
io.Copy(ioutil.Discard, response.Response().Body)
_, _ = io.Copy(io.Discard, response.Response().Body)
gapra-msft marked this conversation as resolved.
Show resolved Hide resolved
response.Response().Body.Close()
}
// If retrying, cancel the current per-try timeout context
Expand Down
4 changes: 2 additions & 2 deletions azbfs/zc_sas_query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func newSASQueryParameters(values url.Values, deleteSASParametersFromValues bool
case "st":
p.startTime, p.stTimeFormat, _ = parseSASTimeString(val)
case "se":
p.expiryTime, p.stTimeFormat, _ = parseSASTimeString(val)
p.expiryTime, p.seTimeFormat, _ = parseSASTimeString(val)
case "sip":
dashIndex := strings.Index(val, "-")
if dashIndex == -1 {
Expand Down Expand Up @@ -255,7 +255,7 @@ func (p *SASQueryParameters) addToValues(v url.Values) url.Values {
v.Add("st", formatSASTime(&p.startTime, p.stTimeFormat))
}
if !p.expiryTime.IsZero() {
v.Add("se", formatSASTime(&p.expiryTime, p.stTimeFormat))
v.Add("se", formatSASTime(&p.expiryTime, p.seTimeFormat))
}
if len(p.ipRange.Start) > 0 {
v.Add("sip", p.ipRange.String())
Expand Down
5 changes: 4 additions & 1 deletion azbfs/zc_util_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func validateSeekableStreamAt0AndGetCount(body io.ReadSeeker) int64 {
if err != nil {
panic("failed to seek stream")
}
body.Seek(0, io.SeekStart)
_, err = body.Seek(0, io.SeekStart)
if err != nil {
logf("error seeking stream (%s)", err.Error())
}
return count
}

Expand Down
48 changes: 1 addition & 47 deletions azbfs/zc_uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package azbfs
import (
"crypto/rand"
"fmt"
"strconv"
)

// The UUID reserved variants.
const (
reservedNCS byte = 0x80
reservedRFC4122 byte = 0x40
reservedMicrosoft byte = 0x20
reservedFuture byte = 0x00
reservedRFC4122 byte = 0x40
)

// A UUID representation compliant with specification in RFC 4122 document.
Expand All @@ -36,45 +32,3 @@ func newUUID() (u uuid) {
func (u uuid) String() string {
return fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:])
}

// ParseUUID parses a string formatted as "003020100-0504-0706-0809-0a0b0c0d0e0f"
// or "{03020100-0504-0706-0809-0a0b0c0d0e0f}" into a UUID.
func parseUUID(uuidStr string) uuid {
char := func(hexString string) byte {
i, _ := strconv.ParseUint(hexString, 16, 8)
return byte(i)
}
if uuidStr[0] == '{' {
uuidStr = uuidStr[1:] // Skip over the '{'
}
// 03020100 - 05 04 - 07 06 - 08 09 - 0a 0b 0c 0d 0e 0f
// 1 11 1 11 11 1 12 22 2 22 22 22 33 33 33
// 01234567 8 90 12 3 45 67 8 90 12 3 45 67 89 01 23 45
uuidVal := uuid{
char(uuidStr[0:2]),
char(uuidStr[2:4]),
char(uuidStr[4:6]),
char(uuidStr[6:8]),

char(uuidStr[9:11]),
char(uuidStr[11:13]),

char(uuidStr[14:16]),
char(uuidStr[16:18]),

char(uuidStr[19:21]),
char(uuidStr[21:23]),

char(uuidStr[24:26]),
char(uuidStr[26:28]),
char(uuidStr[28:30]),
char(uuidStr[30:32]),
char(uuidStr[32:34]),
char(uuidStr[34:36]),
}
return uuidVal
}

func (u uuid) bytes() []byte {
return u[:]
}
11 changes: 5 additions & 6 deletions azbfs/zt_url_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"net/url"
//"strings"

"io/ioutil"
"net/http"

"github.com/Azure/azure-storage-azcopy/v10/azbfs"
Expand Down Expand Up @@ -213,7 +212,7 @@ func (s *FileURLSuite) TestFileGetProperties(c *chk.C) {
// c.Assert(resp.ContentType(), chk.Equals, "application/octet-stream")
// c.Assert(resp.Status(), chk.Not(chk.Equals), "")
//
// download, err := ioutil.ReadAll(resp.Response().Body)
// download, err := io.ReadAll(resp.Response().Body)
// c.Assert(err, chk.IsNil)
// c.Assert(download, chk.DeepEquals, contentD[:1024])
//}
Expand Down Expand Up @@ -250,14 +249,14 @@ func (s *FileURLSuite) TestUnexpectedEOFRecovery(c *chk.C) {
// Verify that we can inject errors first.
reader := dResp.Body(azbfs.InjectErrorInRetryReaderOptions(errors.New("unrecoverable error")))

_, err = ioutil.ReadAll(reader)
_, err = io.ReadAll(reader)
c.Assert(err, chk.NotNil)
c.Assert(err.Error(), chk.Equals, "unrecoverable error")

// Then inject the retryable error.
reader = dResp.Body(azbfs.InjectErrorInRetryReaderOptions(io.ErrUnexpectedEOF))

buf, err := ioutil.ReadAll(reader)
buf, err := io.ReadAll(reader)
c.Assert(err, chk.IsNil)
c.Assert(buf, chk.DeepEquals, contentD)
}
Expand Down Expand Up @@ -309,7 +308,7 @@ func (s *FileURLSuite) TestUploadDownloadRoundTrip(c *chk.C) {
c.Assert(resp.Status(), chk.Not(chk.Equals), "")

// Verify the partial data
download, err := ioutil.ReadAll(resp.Response().Body)
download, err := io.ReadAll(resp.Response().Body)
c.Assert(err, chk.IsNil)
c.Assert(download, chk.DeepEquals, contentD1[:1024])

Expand All @@ -325,7 +324,7 @@ func (s *FileURLSuite) TestUploadDownloadRoundTrip(c *chk.C) {
c.Assert(resp.Version(), chk.Not(chk.Equals), "")

// Verify the entire content
download, err = ioutil.ReadAll(resp.Response().Body)
download, err = io.ReadAll(resp.Response().Body)
c.Assert(err, chk.IsNil)
c.Assert(download[:2048], chk.DeepEquals, contentD1[:])
c.Assert(download[2048:], chk.DeepEquals, contentD2[:])
Expand Down