Skip to content

Lint tasks refactory #250

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 18 commits into from
Jun 13, 2019
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
40 changes: 0 additions & 40 deletions .golangci.yml

This file was deleted.

16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ env:
# Anything in before_script that returns a nonzero exit code will flunk the
# build and immediately stop. It's sorta like having set -e enabled in bash.
# Make sure golangci-lint is vendored.
before_install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.16.0
install:
- curl -sL https://taskfile.dev/install.sh | sh

install: true
- go get github.com/golangci/govet
- go get golang.org/x/lint/golint

script:
# Check if the code is formatted
- $(exit $(go fmt ./... | wc -l))
# Run linter
- golangci-lint run
# Check if the code is formatted and run linter
- ./bin/task check
# Build and test
- ./bin/task build
- ./bin/task test
- ./bin/task test-legacy

after_success:
- bash <(curl -s https://codecov.io/bash) -cF unittests,integration
- bash <(curl -s https://codecov.io/bash) -cF unit -f '*_unit.txt'
- bash <(curl -s https://codecov.io/bash) -cF integ -f '*_integ.txt'


6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,13 @@ Currently Unit and Integration test are available for launch in 2 ways:

```
* build: Build the project
* test: Run the full testsuite
* check: Check fmt and lint, `legacy` will be skipped
* check-legacy: Check fmt and lint for the `legacy` package
* test: Run the full testsuite, `legacy` will be skipped
* test-integration: Run integration tests only
* test-legacy: Run tests for the `legacy` package
* test-unit: Run unit tests only
* test-unit-race: Run unit tests only with race condition detection
```

For Example to launch unit tests only run: `task test-unit`
29 changes: 26 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,28 @@ tasks:
cmds:
- go test {{ default "-v" .GOFLAGS }} ./legacy/...

test-unit-race:
desc: Run unit tests only with race condition detection
cmds:
- go test -short -race {{ default "-v" .GOFLAGS }} -coverprofile=coverage_race_unit.txt {{ default .DEFAULT_TARGETS .TARGETS }}

check:
desc: Check fmt and lint, `legacy` will be skipped
cmds:
- test -z $(go fmt {{ default .DEFAULT_TARGETS .TARGETS }})
- go vet {{ default .DEFAULT_TARGETS .TARGETS }}
- golint {{.GOLINTFLAGS}} {{ default .DEFAULT_TARGETS .TARGETS }}

check-legacy:
desc: Check fmt and lint for the `legacy` package
cmds:
- test -z $(go fmt ./legacy/...)
- go vet ./legacy/...

vars:
DEFAULT_TARGETS: "./arduino/... ./auth/... ./cli/... ./commands/... ./executils/... ./version/..."
# all modules of this project except for "legacy/..." module
DEFAULT_TARGETS:
sh: echo `go list ./... | grep -v legacy | tr '\n' ' '`

# build vars
VERSIONSTRING: "0.3.6-alpha.preview"
Expand All @@ -39,9 +59,12 @@ vars:
-X github.com/arduino/arduino-cli/version.commit={{.COMMIT}}'

# test vars
GOFLAGS: "-timeout 5m -v -coverpkg=./... -covermode=atomic"
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"
TEST_VERSIONSTRING: "0.0.0-test.preview"
TEST_COMMIT: "deadbeef"
TEST_LDFLAGS: >
-ldflags '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}}
-X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}'
-X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}'

# check-lint vars
GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status"
4 changes: 3 additions & 1 deletion arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/arduino/arduino-cli/configs"
"github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
"go.bug.st/relaxed-semver"
semver "go.bug.st/relaxed-semver"
)

// LoadHardware read all plaforms from the configured paths
Expand Down Expand Up @@ -361,6 +361,7 @@ func (pm *PackageManager) loadToolReleasesFromTool(tool *cores.Tool, toolPath *p
return nil
}

// LoadToolsFromBundleDirectories FIXMEDOC
func (pm *PackageManager) LoadToolsFromBundleDirectories(dirs paths.PathList) error {
for _, dir := range dirs {
if err := pm.LoadToolsFromBundleDirectory(dir); err != nil {
Expand All @@ -370,6 +371,7 @@ func (pm *PackageManager) LoadToolsFromBundleDirectories(dirs paths.PathList) er
return nil
}

// LoadToolsFromBundleDirectory FIXMEDOC
func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) error {
pm.Log.Infof("Loading tools from bundle dir: %s", toolsPath)

Expand Down
10 changes: 10 additions & 0 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ func NewPackageManager(indexDir, packagesDir, downloadDir, tempDir *paths.Path)
}
}

// Clear FIXMEDOC
func (pm *PackageManager) Clear() {
pm.packages = cores.NewPackages()
}

// GetPackages FIXMEDOC
func (pm *PackageManager) GetPackages() *cores.Packages {
return pm.packages
}

// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC
func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.PlatformRelease {
res := []*cores.PlatformRelease{}
for _, targetPackage := range pm.packages.Packages {
Expand All @@ -86,6 +89,7 @@ func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid
return res
}

// FindBoardsWithVidPid FIXMEDOC
func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board {
res := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages {
Expand All @@ -102,6 +106,7 @@ func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board {
return res
}

// FindBoardsWithID FIXMEDOC
func (pm *PackageManager) FindBoardsWithID(id string) []*cores.Board {
res := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages {
Expand Down Expand Up @@ -290,6 +295,7 @@ func (ta *ToolActions) IsInstalled() (bool, error) {
return false, nil
}

// Release FIXMEDOC
func (ta *ToolActions) Release(version *semver.RelaxedVersion) *ToolReleaseActions {
if ta.forwardError != nil {
return &ToolReleaseActions{forwardError: ta.forwardError}
Expand All @@ -310,6 +316,7 @@ type ToolReleaseActions struct {
forwardError error
}

// Get FIXMEDOC
func (tr *ToolReleaseActions) Get() (*cores.ToolRelease, error) {
if tr.forwardError != nil {
return nil, tr.forwardError
Expand Down Expand Up @@ -340,6 +347,7 @@ func (pm *PackageManager) GetInstalledPlatformRelease(platform *cores.Platform)
return best
}

// GetAllInstalledToolsReleases FIXMEDOC
func (pm *PackageManager) GetAllInstalledToolsReleases() []*cores.ToolRelease {
tools := []*cores.ToolRelease{}
for _, targetPackage := range pm.packages.Packages {
Expand Down Expand Up @@ -384,6 +392,7 @@ func (pm *PackageManager) InstalledBoards() []*cores.Board {
return boards
}

// FindToolsRequiredForBoard FIXMEDOC
func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.ToolRelease, error) {
pm.Log.Infof("Searching tools required for board %s", board)

Expand Down Expand Up @@ -421,6 +430,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core
return requiredTools, nil
}

// FindToolDependency FIXMEDOC
func (pm *PackageManager) FindToolDependency(dep *cores.ToolDependency) *cores.ToolRelease {
toolRelease, err := pm.Package(dep.ToolPackager).Tool(dep.ToolName).Release(dep.ToolVersion).Get()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ import (
semver "go.bug.st/relaxed-semver"
)

// MandatoryProperties FIXMEDOC
var MandatoryProperties = []string{"name", "version", "author", "maintainer"}

// OptionalProperties FIXMEDOC
var OptionalProperties = []string{"sentence", "paragraph", "url"}

// ValidCategories FIXMEDOC
var ValidCategories = map[string]bool{
"Display": true,
"Communication": true,
Expand Down
3 changes: 3 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var appName = filepath.Base(os.Args[0])
// VersionInfo contains all info injected during build
var VersionInfo = version.NewInfo(appName)

// HTTPClientHeader is the object that will be propagated to configure the clients inside the downloaders
var HTTPClientHeader = getHTTPClientHeader()

// ErrLogrus represents the logrus instance, which has the role to
Expand All @@ -70,6 +71,7 @@ var GlobalFlags struct {
OutputJSON bool // true output in JSON, false output as Text
}

// Config FIXMEDOC
var Config *configs.Configuration

func packageManagerInitReq() *rpc.InitReq {
Expand All @@ -96,6 +98,7 @@ func getHTTPClientHeader() http.Header {
return downloaderHeaders
}

// InitInstance FIXMEDOC
func InitInstance() *rpc.InitResp {
logrus.Info("Initializing package manager")
req := packageManagerInitReq()
Expand Down
1 change: 1 addition & 0 deletions commands/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
paths "github.com/arduino/go-paths-helper"
)

// Attach FIXMEDOC
func Attach(ctx context.Context, req *rpc.BoardAttachReq, taskCB commands.TaskProgressCB) (*rpc.BoardAttachResp, error) {

pm := commands.GetPackageManager(req)
Expand Down
1 change: 1 addition & 0 deletions commands/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// Details FIXMEDOC
func Details(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// List FIXMEDOC
func List(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// ListAll FIXMEDOC
func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/sirupsen/logrus"
)

// Compile FIXMEDOC
func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errStream io.Writer) (*rpc.CompileResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/core/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// PlatformDownload FIXMEDOC
func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB,
downloaderHeaders http.Header) (*rpc.PlatformDownloadResp, error) {
pm := commands.GetPackageManager(req)
Expand Down
1 change: 1 addition & 0 deletions commands/core/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// PlatformInstall FIXMEDOC
func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq,
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) (*rpc.PlatformInstallResp, error) {

Expand Down
1 change: 1 addition & 0 deletions commands/core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// PlatformList FIXMEDOC
func PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// PlatformSearch FIXMEDOC
func PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/core/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// PlatformUninstall FIXMEDOC
func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq, taskCB commands.TaskProgressCB) (*rpc.PlatformUninstallResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
Expand Down
1 change: 1 addition & 0 deletions commands/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/rpc"
)

// PlatformUpgrade FIXMEDOC
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq,
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) (*rpc.PlatformUpgradeResp, error) {

Expand Down
Loading