Skip to content

Pass of lint for .proto files #1223

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

Merged
merged 17 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.14"
go-version: "1.16"

- name: Install Go deps
# Since 10/23/2019 pwsh is the default shell
Expand Down Expand Up @@ -50,16 +50,27 @@ jobs:
- name: Install Poetry
run: pip install poetry

- name: Install buf (protoc linter)
if: runner.os == 'Linux'
run: |
go install github.com/bufbuild/buf/cmd/buf@latest
go install github.com/bufbuild/buf/cmd/protoc-gen-buf-breaking@latest
go install github.com/bufbuild/buf/cmd/protoc-gen-buf-lint@latest
shell: bash

- name: Check the code is good
if: runner.os == 'Linux'
run: task check

- name: Install protoc compiler
if: runner.os == 'Linux'
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check protocol buffers compile correctly
run: task protoc
if: runner.os == 'Linux'
run: task protoc:compile

- name: Build the CLI
run: task build
Expand Down
42 changes: 30 additions & 12 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ tasks:
docs:gen:protobuf:
desc: Generate markdown contents for protobuffers
cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/commands/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,monitor.md --proto_path=rpc ./rpc/monitor/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/settings/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/debug/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,monitor.md --proto_path=rpc ./rpc/cc/arduino/cli/monitor/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/cc/arduino/cli/debug/v1/*.proto'
- task: docs:format

docs:gen:
Expand Down Expand Up @@ -77,20 +77,37 @@ tasks:
- npx {{ .PRETTIER }} --write "**/*.md"

protoc:
desc: Lint, format and compile protobuf definitions
deps:
- protoc:check
- protoc:format
- protoc:compile

protoc:compile:
desc: Compile protobuf definitions
cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/commands/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/monitor/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/settings/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/debug/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/cc/arduino/cli/monitor/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=plugins=grpc,paths=source_relative:rpc ./rpc/cc/arduino/cli/debug/v1/*.proto'

protoc:docs:
desc: Generate docs for protobuf definitions
cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/commands/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,monitor.md --proto_path=rpc ./rpc/monitor/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/settings/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/debug/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,monitor.md --proto_path=rpc ./rpc/cc/arduino/cli/monitor/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/cc/arduino/cli/debug/v1/*.proto'

protoc:check:
desc: Perform linting of the protobuf definitions
cmds:
- buf lint rpc

protoc:format:
desc: Perform formatting of the protobuf definitions
cmds:
- clang-format -i rpc/cc/arduino/cli/*/*/*.proto

build:
desc: Build the project
Expand Down Expand Up @@ -134,6 +151,7 @@ tasks:
- task: python:check
- task: docs:check
- task: config:check
- task: protoc:check

config:check:
desc: Check linting of configuration and supporting files
Expand Down
2 changes: 1 addition & 1 deletion arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/arduino/arduino-cli/arduino/cores"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
semver "go.bug.st/relaxed-semver"
Expand Down
6 changes: 3 additions & 3 deletions arduino/libraries/libraries_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"encoding/json"
"fmt"

rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

// LibraryLayout represents how the library source code is laid out in the library
Expand Down Expand Up @@ -72,9 +72,9 @@ func (d *LibraryLayout) UnmarshalJSON(b []byte) error {
func (d *LibraryLayout) ToRPCLibraryLayout() rpc.LibraryLayout {
switch *d {
case FlatLayout:
return rpc.LibraryLayout_flat_layout
return rpc.LibraryLayout_LIBRARY_LAYOUT_FLAT
case RecursiveLayout:
return rpc.LibraryLayout_recursive_layout
return rpc.LibraryLayout_LIBRARY_LAYOUT_RECURSIVE
}
panic(fmt.Sprintf("invalid LibraryLayout value %d", *d))
}
18 changes: 9 additions & 9 deletions arduino/libraries/libraries_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"encoding/json"
"fmt"

rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

// LibraryLocation represents where the library is installed
Expand Down Expand Up @@ -89,27 +89,27 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
switch *d {
case IDEBuiltIn:
return rpc.LibraryLocation_ide_builtin
return rpc.LibraryLocation_LIBRARY_LOCATION_IDE_BUILTIN
case PlatformBuiltIn:
return rpc.LibraryLocation_platform_builtin
return rpc.LibraryLocation_LIBRARY_LOCATION_PLATFORM_BUILTIN
case ReferencedPlatformBuiltIn:
return rpc.LibraryLocation_referenced_platform_builtin
return rpc.LibraryLocation_LIBRARY_LOCATION_REFERENCED_PLATFORM_BUILTIN
case User:
return rpc.LibraryLocation_user
return rpc.LibraryLocation_LIBRARY_LOCATION_USER
}
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
}

// FromRPCLibraryLocation converts a rpc.LibraryLocation to a LibraryLocation
func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
switch l {
case rpc.LibraryLocation_ide_builtin:
case rpc.LibraryLocation_LIBRARY_LOCATION_IDE_BUILTIN:
return IDEBuiltIn
case rpc.LibraryLocation_platform_builtin:
case rpc.LibraryLocation_LIBRARY_LOCATION_PLATFORM_BUILTIN:
return PlatformBuiltIn
case rpc.LibraryLocation_referenced_platform_builtin:
case rpc.LibraryLocation_LIBRARY_LOCATION_REFERENCED_PLATFORM_BUILTIN:
return ReferencedPlatformBuiltIn
case rpc.LibraryLocation_user:
case rpc.LibraryLocation_LIBRARY_LOCATION_USER:
return User
}
panic(fmt.Sprintf("invalid rpc.LibraryLocation value %d", l))
Expand Down
2 changes: 1 addition & 1 deletion arduino/libraries/librariesindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/arduino/resources"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
semver "go.bug.st/relaxed-semver"
)

Expand Down
4 changes: 2 additions & 2 deletions cli/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/board"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -64,7 +64,7 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
path = initSketchPath(path)
}

if _, err = board.Attach(context.Background(), &rpc.BoardAttachReq{
if _, err = board.Attach(context.Background(), &rpc.BoardAttachRequest{
Instance: instance,
BoardUri: args[0],
SketchPath: path.String(),
Expand Down
18 changes: 9 additions & 9 deletions cli/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/i18n"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -66,7 +66,7 @@ func runDetailsCommand(cmd *cobra.Command, args []string) {
fqbn = args[0]
}

res, err := board.Details(context.Background(), &rpc.BoardDetailsReq{
res, err := board.Details(context.Background(), &rpc.BoardDetailsRequest{
Instance: inst,
Fqbn: fqbn,
})
Expand All @@ -82,7 +82,7 @@ func runDetailsCommand(cmd *cobra.Command, args []string) {
// output from this command requires special formatting, let's create a dedicated
// feedback.Result implementation
type detailsResult struct {
details *rpc.BoardDetailsResp
details *rpc.BoardDetailsResponse
}

func (dr detailsResult) Data() interface{} {
Expand Down Expand Up @@ -134,28 +134,28 @@ func (dr detailsResult) String() string {
table.NewCell("✔", color.New(color.FgGreen)))
}

for i, idp := range details.IdentificationPref {
for i, idp := range details.IdentificationPrefs {
if i == 0 {
t.AddRow() // get some space from above
t.AddRow(tr("Identification properties:"), "VID:"+idp.UsbID.VID+" PID:"+idp.UsbID.PID)
t.AddRow(tr("Identification properties:"), "VID:"+idp.UsbId.Vid+" PID:"+idp.UsbId.Pid)
continue
}
t.AddRow("", "VID:"+idp.UsbID.VID+" PID:"+idp.UsbID.PID)
t.AddRow("", "VID:"+idp.UsbId.Vid+" PID:"+idp.UsbId.Pid)
}

t.AddRow() // get some space from above
addIfNotEmpty(tr("Package name:"), details.Package.Name)
addIfNotEmpty(tr("Package maintainer:"), details.Package.Maintainer)
addIfNotEmpty(tr("Package URL:"), details.Package.Url)
addIfNotEmpty(tr("Package website:"), details.Package.WebsiteURL)
addIfNotEmpty(tr("Package website:"), details.Package.WebsiteUrl)
addIfNotEmpty(tr("Package online help:"), details.Package.Help.Online)

t.AddRow() // get some space from above
addIfNotEmpty(tr("Platform name:"), details.Platform.Name)
addIfNotEmpty(tr("Platform category:"), details.Platform.Category)
addIfNotEmpty(tr("Platform architecture:"), details.Platform.Architecture)
addIfNotEmpty(tr("Platform URL:"), details.Platform.Url)
addIfNotEmpty(tr("Platform file name:"), details.Platform.ArchiveFileName)
addIfNotEmpty(tr("Platform file name:"), details.Platform.ArchiveFilename)
if details.Platform.Size != 0 {
addIfNotEmpty(tr("Platform size (bytes):"), fmt.Sprint(details.Platform.Size))
}
Expand All @@ -167,7 +167,7 @@ func (dr detailsResult) String() string {
if showFullDetails {
for _, sys := range tool.Systems {
t.AddRow("", tr("OS:"), "", sys.Host)
t.AddRow("", tr("File:"), "", sys.ArchiveFileName)
t.AddRow("", tr("File:"), "", sys.ArchiveFilename)
t.AddRow("", tr("Size (bytes):"), "", fmt.Sprint(sys.Size))
t.AddRow("", tr("Checksum:"), "", sys.Checksum)
t.AddRow("", "URL:", "", sys.Url)
Expand Down
10 changes: 5 additions & 5 deletions cli/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -147,15 +147,15 @@ func (dr result) String() string {
if boards := port.GetBoards(); len(boards) > 0 {
sort.Slice(boards, func(i, j int) bool {
x, y := boards[i], boards[j]
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFQBN() < y.GetFQBN())
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFqbn() < y.GetFqbn())
})
for _, b := range boards {
board := b.GetName()

// to improve the user experience, show on a dedicated column
// the name of the core supporting the board detected
var coreName = ""
fqbn, err := cores.ParseFQBN(b.GetFQBN())
fqbn, err := cores.ParseFQBN(b.GetFqbn())
if err == nil {
coreName = fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch)
}
Expand Down Expand Up @@ -206,15 +206,15 @@ func (dr watchEvent) String() string {
if boards := dr.Boards; len(boards) > 0 {
sort.Slice(boards, func(i, j int) bool {
x, y := boards[i], boards[j]
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFQBN() < y.GetFQBN())
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFqbn() < y.GetFqbn())
})
for _, b := range boards {
board := b.GetName()

// to improve the user experience, show on a dedicated column
// the name of the core supporting the board detected
var coreName = ""
fqbn, err := cores.ParseFQBN(b.GetFQBN())
fqbn, err := cores.ParseFQBN(b.GetFqbn())
if err == nil {
coreName = fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch)
}
Expand Down
8 changes: 4 additions & 4 deletions cli/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -56,7 +56,7 @@ func runListAllCommand(cmd *cobra.Command, args []string) {
os.Exit(errorcodes.ErrGeneric)
}

list, err := board.ListAll(context.Background(), &rpc.BoardListAllReq{
list, err := board.ListAll(context.Background(), &rpc.BoardListAllRequest{
Instance: inst,
SearchArgs: args,
IncludeHiddenBoards: showHiddenBoard,
Expand All @@ -72,7 +72,7 @@ func runListAllCommand(cmd *cobra.Command, args []string) {
// output from this command requires special formatting, let's create a dedicated
// feedback.Result implementation
type resultAll struct {
list *rpc.BoardListAllResp
list *rpc.BoardListAllResponse
}

func (dr resultAll) Data() interface{} {
Expand All @@ -91,7 +91,7 @@ func (dr resultAll) String() string {
if item.IsHidden {
hidden = "(hidden)"
}
t.AddRow(item.GetName(), item.GetFQBN(), hidden)
t.AddRow(item.GetName(), item.GetFqbn(), hidden)
}
return t.Render()
}
6 changes: 3 additions & 3 deletions cli/board/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
rpc "github.com/arduino/arduino-cli/rpc/commands"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -58,7 +58,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
os.Exit(errorcodes.ErrGeneric)
}

res, err := board.Search(context.Background(), &rpc.BoardSearchReq{
res, err := board.Search(context.Background(), &rpc.BoardSearchRequest{
Instance: inst,
SearchArgs: strings.Join(args, " "),
IncludeHiddenBoards: searchFlags.showHiddenBoard,
Expand Down Expand Up @@ -93,7 +93,7 @@ func (r searchResults) String() string {
if item.IsHidden {
hidden = "(hidden)"
}
t.AddRow(item.GetName(), item.GetFQBN(), item.Platform.ID, hidden)
t.AddRow(item.GetName(), item.GetFqbn(), item.Platform.Id, hidden)
}
return t.Render()
}
Loading