Skip to content

Commit 00b3716

Browse files
authored
Merge pull request #594 from atombrella/feature/upgrade_golangci_lint
Update to golangci-lint version 2
2 parents e358b3e + 734d6fe commit 00b3716

17 files changed

Lines changed: 69 additions & 119 deletions

.github/workflows/go-validate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
5050
with:
5151
go-version: ${{ needs.get-go-version.outputs.go-version }}
52-
- uses: golangci/golangci-lint-action@82d40c283aeb1f2b6595839195e95c2d6a49081b # v5.0.0
52+
- uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
5353
with:
54-
version: v1.64.8
54+
version: v2.10.1
5555
only-new-issues: true
5656
check-fmt:
5757
needs:

.golangci.yml

Lines changed: 29 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
11
# Copyright IBM Corp. 2013, 2025
22
# SPDX-License-Identifier: MPL-2.0
33

4-
issues:
5-
# List of regexps of issue texts to exclude, empty list by default.
6-
# But independently from this option we use default exclude patterns,
7-
# it can be disabled by `exclude-use-default: false`. To list all
8-
# excluded by default patterns execute `golangci-lint run --help`
9-
10-
exclude-rules:
11-
# Exclude gosimple bool check
12-
- linters:
13-
- gosimple
14-
text: "S(1002|1008|1021)"
15-
# Exclude failing staticchecks for now
16-
- linters:
17-
- staticcheck
18-
text: "SA(1006|1019|4006|4010|4017|5007|6005|9004):"
19-
# Exclude lll issues for long lines with go:generate
20-
- linters:
21-
- lll
22-
source: "^//go:generate "
23-
24-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
25-
max-issues-per-linter: 0
26-
27-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
28-
max-same-issues: 0
4+
version: "2"
295

306
linters:
31-
disable-all: true
327
enable:
33-
- errcheck
34-
- goimports
35-
- gosimple
8+
- asasalint
9+
- asciicheck
10+
- bidichk
11+
- decorder
12+
- dupword
3613
- govet
3714
- ineffassign
15+
- misspell
16+
- nilerr
17+
- reassign
3818
- staticcheck
3919
- unconvert
4020
- unused
41-
fast: true
21+
settings:
22+
errcheck:
23+
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
24+
# default is false: such cases aren't reported by default.
25+
check-type-assertions: false
26+
27+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
28+
# default is false: such cases aren't reported by default.
29+
check-blank: false
30+
staticcheck:
31+
# SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks
32+
# Example (to disable some checks): [ "all", "-SA1000", "-SA1001"]
33+
# Run `GL_DEBUG=staticcheck golangci-lint run --enable=staticcheck` to see all available checks and enabled by config checks.
34+
checks: ["all", "-SA4006", "-ST1000", "-ST1003", "-ST1005", "-ST1012", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1001", "-QF1004", "-QF1008", "-QF1012"]
4235

4336
# options for analysis running
4437
run:
@@ -54,72 +47,15 @@ run:
5447
# include test files or not, default is true
5548
tests: true
5649

57-
# list of build tags, all linters use it. Default is empty list.
58-
#build-tags:
59-
# - mytag
60-
61-
# which dirs to skip: issues from them won't be reported;
62-
# can use regexp here: generated.*, regexp is applied on full path;
63-
# default value is empty list, but default dirs are skipped independently
64-
# from this option's value (see skip-dirs-use-default).
65-
#skip-dirs:
66-
# - src/external_libs
67-
# - autogenerated_by_my_lib
68-
69-
# default is true. Enables skipping of directories:
70-
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
71-
skip-dirs-use-default: true
72-
7350
# which files to skip: they will be analyzed, but issues from them
7451
# won't be reported. Default value is empty list, but there is
7552
# no need to include all autogenerated files, we confidently recognize
7653
# autogenerated files. If it's not please let us know.
77-
skip-files:
78-
- ".*\\.hcl2spec\\.go$"
54+
# skip-files:
55+
# - ".*\\.hcl2spec\\.go$"
7956
# - lib/bad.go
8057

81-
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
82-
# If invoked with -mod=readonly, the go command is disallowed from the implicit
83-
# automatic updating of go.mod described above. Instead, it fails when any changes
84-
# to go.mod are needed. This setting is most useful to check that go.mod does
85-
# not need updates, such as in a continuous integration and testing system.
86-
# If invoked with -mod=vendor, the go command assumes that the vendor
87-
# directory holds the correct copies of dependencies and ignores
88-
# the dependency descriptions in go.mod.
89-
# modules-download-mode: vendor
90-
91-
92-
# output configuration options
93-
output:
94-
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
95-
format: colored-line-number
96-
97-
# print lines of code with issue, default is true
98-
print-issued-lines: true
99-
100-
# print linter name in the end of issue text, default is true
101-
print-linter-name: true
102-
103-
# make issues output unique by line, default is true
104-
uniq-by-line: true
105-
106-
107-
# all available settings of specific linters
108-
linters-settings:
109-
errcheck:
110-
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
111-
# default is false: such cases aren't reported by default.
112-
check-type-assertions: false
113-
114-
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
115-
# default is false: such cases aren't reported by default.
116-
check-blank: false
117-
118-
# [deprecated] comma-separated list of pairs of the form pkg:regex
119-
# the regex is used to ignore names within pkg. (default "fmt:.*").
120-
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
121-
ignore: fmt:.*,io/ioutil:^Read.*,io:Close
122-
123-
# path to a file containing a list of functions to exclude from checking
124-
# see https://github.com/kisielk/errcheck#excluding-functions for details
125-
#exclude: /path/to/file.txt
58+
formatters:
59+
enable:
60+
- gofmt
61+
- goimports

builder/azure/arm/azure_error_response.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ func (e *azureErrorResponse) Error() string {
4545
//
4646
// Errors may contain nested errors, which are JSON documents that have been
4747
// serialized and escaped. Keep following this nesting all the way down...
48-
func formatAzureErrorResponse(error azureErrorDetails, buf *bytes.Buffer, indent string) {
49-
if error.isEmpty() {
48+
func formatAzureErrorResponse(err azureErrorDetails, buf *bytes.Buffer, indent string) {
49+
if err.isEmpty() {
5050
return
5151
}
5252

53-
buf.WriteString(fmt.Sprintf("ERROR: %s-> %s : %s\n", indent, error.Code, error.Message))
54-
for _, x := range error.Details {
53+
buf.WriteString(fmt.Sprintf("ERROR: %s-> %s : %s\n", indent, err.Code, err.Message))
54+
for _, x := range err.Details {
5555
newIndent := fmt.Sprintf("%s ", indent)
5656

5757
var aer azureErrorResponse
58-
err := json.Unmarshal([]byte(x.Message), &aer)
59-
if err == nil {
58+
errJson := json.Unmarshal([]byte(x.Message), &aer)
59+
if errJson == nil {
6060
buf.WriteString(fmt.Sprintf("ERROR: %s-> %s\n", newIndent, x.Code))
6161
formatAzureErrorResponse(aer.ErrorDetails, buf, newIndent)
6262
} else {

builder/azure/arm/builder.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
226226
buildGroupId := commonids.NewResourceGroupID(b.config.ClientConfig.SubscriptionID, b.config.BuildResourceGroupName)
227227
group, err := azureClient.ResourceGroupsClient.Get(builderPollingContext, buildGroupId)
228228
if err != nil {
229-
return nil, fmt.Errorf("Cannot locate the existing build resource resource group %s.", b.config.BuildResourceGroupName)
229+
return nil, fmt.Errorf("Cannot locate the existing build resource group %s.", b.config.BuildResourceGroupName)
230230
}
231231

232232
b.config.Location = group.Model.Location
@@ -336,7 +336,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
336336
normalizedRegions = append(normalizedRegions, TargetRegion{Name: region, ReplicaCount: b.config.SharedGalleryImageVersionReplicaCount})
337337
}
338338
// SIG requires that replication regions include the region in which the created image version resides
339-
if foundMandatoryReplicationRegion == false {
339+
if !foundMandatoryReplicationRegion {
340340
normalizedRegions = append(normalizedRegions, TargetRegion{
341341
Name: buildLocation,
342342
DiskEncryptionSetId: b.config.DiskEncryptionSetId,
@@ -393,7 +393,8 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
393393
}
394394
generatedData := &packerbuilderdata.GeneratedData{State: b.stateBag}
395395
var steps []multistep.Step
396-
if b.config.OSType == constants.Target_Linux {
396+
switch b.config.OSType {
397+
case constants.Target_Linux:
397398
steps = []multistep.Step{
398399
NewStepGetSourceImageName(azureClient, ui, &b.config, generatedData),
399400
NewStepCreateResourceGroup(azureClient, ui),
@@ -415,7 +416,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
415416
NewStepSnapshotOSDisk(azureClient, ui, &b.config),
416417
NewStepSnapshotDataDisks(azureClient, ui, &b.config),
417418
}
418-
} else if b.config.OSType == constants.Target_Windows {
419+
case constants.Target_Windows:
419420
steps = []multistep.Step{
420421
NewStepGetSourceImageName(azureClient, ui, &b.config, generatedData),
421422
NewStepCreateResourceGroup(azureClient, ui),
@@ -495,7 +496,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
495496
NewStepSnapshotOSDisk(azureClient, ui, &b.config),
496497
NewStepSnapshotDataDisks(azureClient, ui, &b.config),
497498
)
498-
} else {
499+
default:
499500
return nil, fmt.Errorf("Builder does not support the os_type '%s'", b.config.OSType)
500501
}
501502

@@ -574,6 +575,7 @@ func (b *Builder) writeSSHPrivateKey(ui packersdk.Ui, debugKeyPath string) {
574575
if err != nil {
575576
ui.Say(fmt.Sprintf("Error saving debug key: %s", err))
576577
}
578+
//nolint:errcheck
577579
defer f.Close()
578580

579581
// Write the key out
@@ -706,7 +708,7 @@ func (b *Builder) setImageParameters(stateBag multistep.StateBag) {
706708
}
707709

708710
func normalizeAzureRegion(name string) string {
709-
return strings.ToLower(strings.Replace(name, " ", "", -1))
711+
return strings.ToLower(strings.ReplaceAll(name, " ", ""))
710712
}
711713

712714
func (b *Builder) enhanceStateData(stateData map[string]interface{}) {

builder/azure/arm/builder_acc_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func TestBuilderUserData_Linux(t *testing.T) {
257257
t.Fatalf("failed creating tempfile: %s", err)
258258
}
259259

260+
//nolint:errcheck
260261
defer os.Remove(tmpfile.Name())
261262

262263
if _, err := tmpfile.WriteString(testBuilderCustomDataLinux); err != nil {

builder/azure/arm/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"strings"
2323
"time"
2424

25-
"github.com/hashicorp/packer-plugin-sdk/packer"
2625
"github.com/hashicorp/packer-plugin-sdk/random"
2726

2827
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/images"
@@ -975,7 +974,7 @@ func setWinRMCertificate(c *Config) error {
975974
cert, err := c.createCertificate()
976975

977976
// Hide the generated certificate from logs
978-
packer.LogSecretFilter.Set(cert)
977+
packersdk.LogSecretFilter.Set(cert)
979978

980979
c.winrmCertificate = cert
981980

@@ -1171,7 +1170,7 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
11711170
if err != nil {
11721171
err := fmt.Errorf("Error parsing resource ID from `user_assigned_managed_identities`; please make sure"+
11731172
" that this value follows the full resource id format: "+
1174-
"/subscriptions/<SUBSCRIPTON_ID>/resourcegroups/<RESOURCE_GROUP>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<USER_ASSIGNED_IDENTITY_NAME>.\n"+
1173+
"/subscriptions/<SUBSCRIPTION_ID>/resourcegroups/<RESOURCE_GROUP>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<USER_ASSIGNED_IDENTITY_NAME>.\n"+
11751174
" Original error: %s", err)
11761175
errs = packersdk.MultiErrorAppend(errs, err)
11771176
} else {
@@ -1318,7 +1317,7 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
13181317
}
13191318

13201319
if c.SkipCreateBuildKeyVault && !strings.EqualFold(c.Comm.Type, "winrm") {
1321-
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Communicator type must be winrm when skip_create_build_key_vault is set"))
1320+
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("Communicator type must be winrm when skip_create_build_key_vault is set"))
13221321
}
13231322

13241323
/////////////////////////////////////////////

builder/azure/arm/config_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,9 @@ func TestConfigShouldRejectUserDataAndUserDataFile(t *testing.T) {
26832683
if err != nil {
26842684
t.Fatalf("failed creating tempfile: %s", err)
26852685
}
2686+
//nolint:errcheck
2687+
defer os.Remove(tmpfile.Name())
2688+
26862689
config := map[string]interface{}{
26872690
"capture_container_name": "ignore",
26882691
"capture_name_prefix": "ignore",
@@ -2703,7 +2706,6 @@ func TestConfigShouldRejectUserDataAndUserDataFile(t *testing.T) {
27032706
var c Config
27042707
_, err = c.Prepare(config, getPackerConfiguration())
27052708

2706-
defer os.Remove(tmpfile.Name())
27072709
if err == nil {
27082710
t.Fatal("expected config to reject the use of both user_data and user_data_file")
27092711
}
@@ -2714,6 +2716,9 @@ func TestConfigShouldRejectCustomDataAndCustomDataFile(t *testing.T) {
27142716
if err != nil {
27152717
t.Fatalf("failed creating tempfile: %s", err)
27162718
}
2719+
//nolint:errcheck
2720+
defer os.Remove(tmpfile.Name())
2721+
27172722
config := map[string]interface{}{
27182723
"capture_container_name": "ignore",
27192724
"capture_name_prefix": "ignore",
@@ -2734,7 +2739,6 @@ func TestConfigShouldRejectCustomDataAndCustomDataFile(t *testing.T) {
27342739
var c Config
27352740
_, err = c.Prepare(config, getPackerConfiguration())
27362741

2737-
defer os.Remove(tmpfile.Name())
27382742
if err == nil {
27392743
t.Fatal("expected config to reject the use of both custom_data and custom_data_file")
27402744
}

builder/azure/arm/template_factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func GetVirtualMachineTemplateBuilder(config *Config) (*template.TemplateBuilder
336336
}
337337

338338
// In Azure Network Security Groups define the access controls for the network
339-
// They are required when specifiying which inbound IPs are allowed to connect to the network
339+
// They are required when specifying which inbound IPs are allowed to connect to the network
340340
// They are also required when creating a standard sku public IP Address regardless of inbound IPs allowed.
341341
// If a standard IP is set with no inbound addresses, we default to allowing all IP addresses
342342
if (config.PublicIpSKU != "Basic") || (len(config.AllowedInboundIpAddresses) >= 1) {

builder/azure/chroot/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func buildsteps(
551551
}),
552552
)
553553
} else {
554-
panic("Couldn't parse platfrom image urn: " + config.Source + " err: " + err.Error())
554+
panic("Couldn't parse platform image urn: " + config.Source + " err: " + err.Error())
555555
}
556556

557557
case sourceDisk:

builder/azure/chroot/shared_image_gallery_destination.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (sigd *SharedImageGalleryDestination) Validate(prefix string) (errs []error
6565
warns = append(warns,
6666
fmt.Sprintf("%s.target_regions is empty; image will only be available in the region of the gallery", prefix))
6767
}
68-
if sigd.ExcludeFromLatestTypo == true && sigd.ExcludeFromLatest == false {
68+
if sigd.ExcludeFromLatestTypo && !sigd.ExcludeFromLatest {
6969
warns = append(warns,
7070
fmt.Sprintf("%s.exlude_from_latest is being deprecated, please use exclude_from_latest", prefix))
7171
sigd.ExcludeFromLatest = sigd.ExcludeFromLatestTypo

0 commit comments

Comments
 (0)