From 28229018eb5dc748fa271004feaeadb96f8f4622 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Fri, 28 Apr 2023 08:40:00 -0700 Subject: [PATCH] Enable gocritic during linting Enabled gocritic's evalOrder to catch dependencies on undefined behavior on return statements. Updated to latest version of golangci-lint. Fixed issue in azblob flagged by latest linter. --- eng/.golangci.yml | 10 ++++++++++ eng/pipelines/templates/variables/globals.yml | 2 +- sdk/storage/azblob/blockblob/mmf_windows.go | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/eng/.golangci.yml b/eng/.golangci.yml index e4e98907a911..c02d708f5a68 100644 --- a/eng/.golangci.yml +++ b/eng/.golangci.yml @@ -3,3 +3,13 @@ run: # default is true. Enables skipping of directories: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs-use-default: true + timeout: 10m + +linters: + enable: + - gocritic + +linters-settings: + gocritic: + enabled-checks: + - evalOrder diff --git a/eng/pipelines/templates/variables/globals.yml b/eng/pipelines/templates/variables/globals.yml index 071313330e97..98f4404689df 100644 --- a/eng/pipelines/templates/variables/globals.yml +++ b/eng/pipelines/templates/variables/globals.yml @@ -1,5 +1,5 @@ variables: - GoLintCLIVersion: 'v1.51.1' + GoLintCLIVersion: 'v1.52.2' Package.EnableSBOMSigning: true # Enable go native component governance detection # https://docs.opensource.microsoft.com/tools/cg/index.html diff --git a/sdk/storage/azblob/blockblob/mmf_windows.go b/sdk/storage/azblob/blockblob/mmf_windows.go index 2acef3a72f17..3f966d65b887 100644 --- a/sdk/storage/azblob/blockblob/mmf_windows.go +++ b/sdk/storage/azblob/blockblob/mmf_windows.go @@ -26,7 +26,9 @@ func newMMB(size int64) (mmb, error) { if err != nil { return nil, os.NewSyscallError("CreateFileMapping", err) } - defer syscall.CloseHandle(hMMF) + defer func() { + _ = syscall.CloseHandle(hMMF) + }() addr, err := syscall.MapViewOfFile(hMMF, access, 0, 0, uintptr(size)) if err != nil {