Skip to content

Commit 17f0189

Browse files
Update golangci-lint (#2378)
1 parent 10c1411 commit 17f0189

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+285
-284
lines changed

Diff for: .github/workflows/check-go-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
- name: golangci-lint
117117
uses: golangci/golangci-lint-action@v3
118118
with:
119-
version: v1.54
119+
version: v1.55
120120

121121
- name: Check style
122122
env:

Diff for: .golangci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ linters:
2929
- tenv
3030
- typecheck
3131
- unconvert
32+
- protogetter
3233

3334
linters-settings:
3435
forbidigo:
@@ -55,7 +56,7 @@ linters-settings:
5556
- name: errorf
5657
- name: exported
5758
- name: increment-decrement
58-
- name: indent-error-flow
59+
#- name: indent-error-flow
5960
- name: package-comments
6061
- name: range
6162
- name: receiver-naming

Diff for: arduino/cores/packagemanager/install_uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (pme *Explorer) IsToolRequired(toolRelease *cores.ToolRelease) bool {
448448

449449
func skipEmptyMessageTaskProgressCB(taskCB rpc.TaskProgressCB) rpc.TaskProgressCB {
450450
return func(msg *rpc.TaskProgress) {
451-
if msg != nil && len(msg.Message) == 0 {
451+
if msg != nil && len(msg.GetMessage()) == 0 {
452452
return
453453
}
454454
taskCB(msg)

Diff for: arduino/discovery/discovery.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ func PortFromRPCPort(o *rpc.Port) (p *Port) {
125125
return nil
126126
}
127127
res := &Port{
128-
Address: o.Address,
129-
AddressLabel: o.Label,
130-
Protocol: o.Protocol,
131-
ProtocolLabel: o.ProtocolLabel,
132-
HardwareID: o.HardwareId,
133-
}
134-
if o.Properties != nil {
135-
res.Properties = properties.NewFromHashmap(o.Properties)
128+
Address: o.GetAddress(),
129+
AddressLabel: o.GetLabel(),
130+
Protocol: o.GetProtocol(),
131+
ProtocolLabel: o.GetProtocolLabel(),
132+
HardwareID: o.GetHardwareId(),
133+
}
134+
if o.GetProperties() != nil {
135+
res.Properties = properties.NewFromHashmap(o.GetProperties())
136136
}
137137
return res
138138
}

Diff for: arduino/errors.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ type NoBoardsDetectedError struct {
134134
func (e *NoBoardsDetectedError) Error() string {
135135
return tr(
136136
"Please specify an FQBN. The board on port %[1]s with protocol %[2]s can't be identified",
137-
e.Port.Address,
138-
e.Port.Protocol,
137+
e.Port.GetAddress(),
138+
e.Port.GetProtocol(),
139139
)
140140
}
141141

@@ -154,8 +154,8 @@ type MultipleBoardsDetectedError struct {
154154
func (e *MultipleBoardsDetectedError) Error() string {
155155
return tr(
156156
"Please specify an FQBN. Multiple possible boards detected on port %[1]s with protocol %[2]s",
157-
e.Port.Address,
158-
e.Port.Protocol,
157+
e.Port.GetAddress(),
158+
e.Port.GetProtocol(),
159159
)
160160
}
161161

Diff for: client_example/main.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func createInstance(client rpc.ArduinoCoreServiceClient) *rpc.Instance {
330330
if err != nil {
331331
log.Fatalf("Error creating server instance: %s", err)
332332
}
333-
return res.Instance
333+
return res.GetInstance()
334334
}
335335

336336
func initInstance(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
@@ -521,8 +521,8 @@ func callBoardSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance
521521
log.Fatalf("Error getting board data: %s\n", err)
522522
}
523523

524-
for _, board := range res.Boards {
525-
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Metadata.Id)
524+
for _, board := range res.GetBoards() {
525+
log.Printf("Board Name: %s, Board Platform: %s\n", board.GetName(), board.GetPlatform().GetMetadata().GetId())
526526
}
527527
}
528528

@@ -650,16 +650,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
650650
} else if err != nil {
651651
log.Fatalf("Board list watch error: %s\n", err)
652652
}
653-
if res.EventType == "error" {
654-
log.Printf("res: %s\n", res.Error)
653+
if res.GetEventType() == "error" {
654+
log.Printf("res: %s\n", res.GetError())
655655
continue
656656
}
657657

658-
log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Port.Address)
659-
if res.EventType == "add" {
660-
log.Printf("protocol: %s, ", res.Port.Port.Protocol)
661-
log.Printf("protocolLabel: %s, ", res.Port.Port.ProtocolLabel)
662-
log.Printf("boards: %s\n\n", res.Port.MatchingBoards)
658+
log.Printf("event: %s, address: %s\n", res.GetEventType(), res.GetPort().GetPort().GetAddress())
659+
if res.GetEventType() == "add" {
660+
log.Printf("protocol: %s, ", res.GetPort().GetPort().GetProtocol())
661+
log.Printf("protocolLabel: %s, ", res.GetPort().GetPort().GetProtocolLabel())
662+
log.Printf("boards: %s\n\n", res.GetPort().GetMatchingBoards())
663663
}
664664
}
665665
}()

Diff for: commands/board/details.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
5252
details.Version = board.PlatformRelease.Version.String()
5353
details.IdentificationProperties = []*rpc.BoardIdentificationProperties{}
5454
for _, p := range board.GetIdentificationProperties() {
55-
details.IdentificationProperties = append(details.IdentificationProperties, &rpc.BoardIdentificationProperties{
55+
details.IdentificationProperties = append(details.GetIdentificationProperties(), &rpc.BoardIdentificationProperties{
5656
Properties: p.AsMap(),
5757
})
5858
}
5959
for _, k := range boardProperties.Keys() {
6060
v := boardProperties.Get(k)
61-
details.BuildProperties = append(details.BuildProperties, k+"="+v)
61+
details.BuildProperties = append(details.GetBuildProperties(), k+"="+v)
6262
}
6363
if !req.GetDoNotExpandBuildProperties() {
64-
details.BuildProperties, _ = utils.ExpandBuildProperties(details.BuildProperties)
64+
details.BuildProperties, _ = utils.ExpandBuildProperties(details.GetBuildProperties())
6565
}
6666

6767
details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
@@ -111,10 +111,10 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
111111
}
112112
configValue.Value = value
113113
configValue.ValueLabel = values.Get(value)
114-
configOption.Values = append(configOption.Values, configValue)
114+
configOption.Values = append(configOption.GetValues(), configValue)
115115
}
116116

117-
details.ConfigOptions = append(details.ConfigOptions, configOption)
117+
details.ConfigOptions = append(details.GetConfigOptions(), configOption)
118118
}
119119

120120
details.ToolsDependencies = []*rpc.ToolsDependencies{}
@@ -132,7 +132,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
132132
})
133133
}
134134
}
135-
details.ToolsDependencies = append(details.ToolsDependencies, &rpc.ToolsDependencies{
135+
details.ToolsDependencies = append(details.GetToolsDependencies(), &rpc.ToolsDependencies{
136136
Name: tool.ToolName,
137137
Packager: tool.ToolPackager,
138138
Version: tool.ToolVersion.String(),
@@ -142,7 +142,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
142142

143143
details.Programmers = []*rpc.Programmer{}
144144
for id, p := range boardPlatformRelease.Programmers {
145-
details.Programmers = append(details.Programmers, &rpc.Programmer{
145+
details.Programmers = append(details.GetProgrammers(), &rpc.Programmer{
146146
Platform: boardPlatformRelease.Name,
147147
Id: id,
148148
Name: p.Name,

Diff for: commands/board/list.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
182182

183183
// Sort by FQBN alphabetically
184184
sort.Slice(boards, func(i, j int) bool {
185-
return strings.ToLower(boards[i].Fqbn) < strings.ToLower(boards[j].Fqbn)
185+
return strings.ToLower(boards[i].GetFqbn()) < strings.ToLower(boards[j].GetFqbn())
186186
})
187187

188188
// Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination
189189
sort.SliceStable(boards, func(i, j int) bool {
190-
if boards[i].Platform.Metadata.Maintainer == "Arduino" && boards[j].Platform.Metadata.Maintainer != "Arduino" {
190+
if boards[i].GetPlatform().GetMetadata().GetMaintainer() == "Arduino" && boards[j].GetPlatform().GetMetadata().GetMaintainer() != "Arduino" {
191191
return true
192192
}
193193
return false
@@ -246,8 +246,8 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
246246
}
247247

248248
func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool {
249-
for _, detectedBoard := range b.MatchingBoards {
250-
detectedFqbn, err := cores.ParseFQBN(detectedBoard.Fqbn)
249+
for _, detectedBoard := range b.GetMatchingBoards() {
250+
detectedFqbn, err := cores.ParseFQBN(detectedBoard.GetFqbn())
251251
if err != nil {
252252
continue
253253
}

Diff for: commands/board/list_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestGetByVidPid(t *testing.T) {
5454
res, err := apiByVidPid("0xf420", "0XF069")
5555
require.Nil(t, err)
5656
require.Len(t, res, 1)
57-
require.Equal(t, "Arduino/Genuino MKR1000", res[0].Name)
58-
require.Equal(t, "arduino:samd:mkr1000", res[0].Fqbn)
57+
require.Equal(t, "Arduino/Genuino MKR1000", res[0].GetName())
58+
require.Equal(t, "arduino:samd:mkr1000", res[0].GetFqbn())
5959

6060
// wrong vid (too long), wrong pid (not an hex value)
6161
_, err = apiByVidPid("0xfffff", "0xDEFG")
@@ -156,8 +156,8 @@ func TestBoardIdentifySorting(t *testing.T) {
156156
require.Len(t, res, 4)
157157

158158
// Verify expected sorting
159-
require.Equal(t, res[0].Fqbn, "arduino:avr:assurdo")
160-
require.Equal(t, res[1].Fqbn, "arduino:avr:nessuno")
161-
require.Equal(t, res[2].Fqbn, "packager:platform:boardA")
162-
require.Equal(t, res[3].Fqbn, "packager:platform:boardB")
159+
require.Equal(t, res[0].GetFqbn(), "arduino:avr:assurdo")
160+
require.Equal(t, res[1].GetFqbn(), "arduino:avr:nessuno")
161+
require.Equal(t, res[2].GetFqbn(), "packager:platform:boardA")
162+
require.Equal(t, res[3].GetFqbn(), "packager:platform:boardB")
163163
}

Diff for: commands/board/listall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
7171
continue
7272
}
7373

74-
list.Boards = append(list.Boards, &rpc.BoardListItem{
74+
list.Boards = append(list.GetBoards(), &rpc.BoardListItem{
7575
Name: board.Name(),
7676
Fqbn: board.FQBN(),
7777
IsHidden: board.IsHidden(),

Diff for: commands/board/search.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
9494
}
9595

9696
sort.Slice(foundBoards, func(i, j int) bool {
97-
if foundBoards[i].Name != foundBoards[j].Name {
98-
return foundBoards[i].Name < foundBoards[j].Name
97+
if foundBoards[i].GetName() != foundBoards[j].GetName() {
98+
return foundBoards[i].GetName() < foundBoards[j].GetName()
9999
}
100-
return foundBoards[i].Platform.Metadata.Id < foundBoards[j].Platform.Metadata.Id
100+
return foundBoards[i].GetPlatform().GetMetadata().GetId() < foundBoards[j].GetPlatform().GetMetadata().GetId()
101101
})
102102

103103
return &rpc.BoardSearchResponse{Boards: foundBoards}, nil

Diff for: commands/compile/compile.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
5454
// the optionality of this property, otherwise we would have no way of knowing if the property
5555
// was set in the request or it's just the default boolean value.
5656
if reqExportBinaries := req.GetExportBinaries(); reqExportBinaries != nil {
57-
exportBinaries = reqExportBinaries.Value
57+
exportBinaries = reqExportBinaries.GetValue()
5858
}
5959

6060
pme, release := instances.GetPackageManagerExplorer(req.GetInstance())
@@ -110,13 +110,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
110110
r.BuildPlatform = buildPlatform.ToRPCPlatformReference()
111111

112112
// Setup sign keys if requested
113-
if req.KeysKeychain != "" {
113+
if req.GetKeysKeychain() != "" {
114114
boardBuildProperties.Set("build.keys.keychain", req.GetKeysKeychain())
115115
}
116-
if req.SignKey != "" {
116+
if req.GetSignKey() != "" {
117117
boardBuildProperties.Set("build.keys.sign_key", req.GetSignKey())
118118
}
119-
if req.EncryptKey != "" {
119+
if req.GetEncryptKey() != "" {
120120
boardBuildProperties.Set("build.keys.encrypt_key", req.GetEncryptKey())
121121
}
122122
// At the current time we do not have a way of knowing if a board supports the secure boot or not,
@@ -197,7 +197,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
197197
targetPlatform, actualPlatform,
198198
req.GetSkipLibrariesDiscovery(),
199199
libsManager,
200-
paths.NewPathList(req.Library...),
200+
paths.NewPathList(req.GetLibrary()...),
201201
outStream, errStream, req.GetVerbose(), req.GetWarnings(),
202202
progressCB,
203203
)
@@ -231,10 +231,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
231231
keys := buildProperties.Keys()
232232
sort.Strings(keys)
233233
for _, key := range keys {
234-
r.BuildProperties = append(r.BuildProperties, key+"="+buildProperties.Get(key))
234+
r.BuildProperties = append(r.GetBuildProperties(), key+"="+buildProperties.Get(key))
235235
}
236236
if !req.GetDoNotExpandBuildProperties() {
237-
r.BuildProperties, _ = utils.ExpandBuildProperties(r.BuildProperties)
237+
r.BuildProperties, _ = utils.ExpandBuildProperties(r.GetBuildProperties())
238238
}
239239
}()
240240

Diff for: commands/core/download.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, dow
4242
}
4343

4444
ref := &packagemanager.PlatformReference{
45-
Package: req.PlatformPackage,
46-
PlatformArchitecture: req.Architecture,
45+
Package: req.GetPlatformPackage(),
46+
PlatformArchitecture: req.GetArchitecture(),
4747
PlatformVersion: version,
4848
}
4949
platform, tools, err := pme.FindPlatformReleaseDependencies(ref)

Diff for: commands/core/install.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
4141
}
4242

4343
ref := &packagemanager.PlatformReference{
44-
Package: req.PlatformPackage,
45-
PlatformArchitecture: req.Architecture,
44+
Package: req.GetPlatformPackage(),
45+
PlatformArchitecture: req.GetArchitecture(),
4646
PlatformVersion: version,
4747
}
4848
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref)
@@ -74,7 +74,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
7474
if err := install(); err != nil {
7575
return nil, err
7676
}
77-
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
77+
if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
7878
return nil, err
7979
}
8080
return &rpc.PlatformInstallResponse{}, nil

Diff for: commands/core/search.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
3737
defer release()
3838

3939
res := []*cores.Platform{}
40-
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.SearchArgs); isUsb {
41-
vid, pid := req.SearchArgs[:4], req.SearchArgs[5:]
40+
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.GetSearchArgs()); isUsb {
41+
vid, pid := req.GetSearchArgs()[:4], req.GetSearchArgs()[5:]
4242
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
4343
} else {
44-
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
44+
searchArgs := utils.SearchTermsFromQueryString(req.GetSearchArgs())
4545
for _, targetPackage := range pme.GetPackages() {
4646
for _, platform := range targetPackage.Platforms {
4747
if platform == nil {
4848
continue
4949
}
5050
// Users can install platforms manually in the Sketchbook hardware folder,
5151
// if not explictily requested we skip them.
52-
if !req.ManuallyInstalled && platform.ManuallyInstalled {
52+
if !req.GetManuallyInstalled() && platform.ManuallyInstalled {
5353
continue
5454
}
5555

@@ -94,7 +94,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
9494
}
9595
for _, platformRelease := range platform.GetAllReleases() {
9696
rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease)
97-
rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease
97+
rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease
9898
}
9999
out = append(out, rpcPlatformSummary)
100100
}
@@ -104,7 +104,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
104104
return strings.ToLower(out[i].GetMetadata().GetId()) < strings.ToLower(out[j].GetMetadata().GetId())
105105
})
106106
sort.SliceStable(out, func(i, j int) bool {
107-
return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated
107+
return !out[i].GetMetadata().GetDeprecated() && out[j].GetMetadata().GetDeprecated()
108108
})
109109
return &rpc.PlatformSearchResponse{SearchOutput: out}, nil
110110
}

0 commit comments

Comments
 (0)