Skip to content

The introduction of golangci-lint during the CI #24

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
Aug 30, 2018
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
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ pipeline:
# Build
- go build
- go test -timeout 20m -v ./... -race
- golangci-lint run
secrets: [TEST_USERNAME, TEST_PASSWORD]
32 changes: 32 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 13 # Should be 10 but was brought to 13 to speed up the development
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
lll:
line-length: 160

misspell:
locale: US

linters:
enable-all: true
disable:
- deadcode
- dupl
- errcheck
- goconst
- gocyclo
- govet
- maligned
- megacheck
- unparam
9 changes: 5 additions & 4 deletions arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/arduino/go-paths-helper"

"github.com/arduino/arduino-cli/arduino/resources"
properties "github.com/arduino/go-properties-map"
"github.com/arduino/go-properties-map"
"go.bug.st/relaxed-semver"
)

Expand Down Expand Up @@ -111,9 +111,10 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) (*Platform
return release, nil
}

// GetRelease returns the specified release corresponding the provided version,
// FindReleaseWithRelaxedVersion returns the specified release corresponding the provided version,
// or nil if not found.
func (platform *Platform) GetRelease(version *semver.Version) *PlatformRelease {
func (platform *Platform) FindReleaseWithVersion(version *semver.Version) *PlatformRelease {
// use as an fmt.Stringer
return platform.Releases[version.String()]
}

Expand All @@ -124,7 +125,7 @@ func (platform *Platform) GetLatestRelease() *PlatformRelease {
if latestVersion == nil {
return nil
}
return platform.GetRelease(latestVersion)
return platform.FindReleaseWithVersion(latestVersion)
}

// GetAllReleasesVersions returns all the version numbers in this Platform Package.
Expand Down
4 changes: 3 additions & 1 deletion arduino/cores/fqbn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@ func TestFQBN(t *testing.T) {
require.Equal(t, f.Package, "arduino")
require.Equal(t, f.PlatformArch, "avr")
require.Equal(t, f.BoardID, "uno")
require.Equal(t, "properties.Map{\n \"cpu\": \"atmega\",\n \"extra\": \"core=arduino\",\n \"speed\": \"1000\",\n}", f.Configs.Dump())
require.Equal(t,
"properties.Map{\n \"cpu\": \"atmega\",\n \"extra\": \"core=arduino\",\n \"speed\": \"1000\",\n}",
f.Configs.Dump())
}
12 changes: 6 additions & 6 deletions arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type indexToolRelease struct {
Systems []indexToolReleaseFlavour `json:"systems,required"`
}

// indexToolReleaseFlavour represents a single tool flavour in the package_index.json file.
// indexToolReleaseFlavour represents a single tool flavor in the package_index.json file.
type indexToolReleaseFlavour struct {
OS string `json:"host,required"`
URL string `json:"url,required"`
Expand Down Expand Up @@ -178,15 +178,15 @@ func (inToolRelease indexToolRelease) extractToolIn(outPackage *cores.Package) {
outTool := outPackage.GetOrCreateTool(inToolRelease.Name)

outToolRelease := outTool.GetOrCreateRelease(inToolRelease.Version)
outToolRelease.Flavours = inToolRelease.extractFlavours()
outToolRelease.Flavors = inToolRelease.extractFlavours()
}

// extractFlavours extracts a map[OS]Flavour object from an indexToolRelease entry.
func (inToolRelease indexToolRelease) extractFlavours() []*cores.Flavour {
ret := make([]*cores.Flavour, len(inToolRelease.Systems))
// extractFlavours extracts a map[OS]Flavor object from an indexToolRelease entry.
func (inToolRelease indexToolRelease) extractFlavours() []*cores.Flavor {
ret := make([]*cores.Flavor, len(inToolRelease.Systems))
for i, flavour := range inToolRelease.Systems {
size, _ := flavour.Size.Int64()
ret[i] = &cores.Flavour{
ret[i] = &cores.Flavor{
OS: flavour.OS,
Resource: &resources.DownloadResource{
ArchiveFileName: flavour.ArchiveFileName,
Expand Down
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc

var release *cores.PlatformRelease
if item.PlatformVersion != nil {
release = platform.GetRelease(item.PlatformVersion)
release = platform.FindReleaseWithVersion(item.PlatformVersion)
if release == nil {
return nil, nil, fmt.Errorf("required version %s not found for platform %s", item.PlatformVersion, platform.String())
}
Expand Down
38 changes: 19 additions & 19 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
platformRelease := platform.GetInstalled()
if platformRelease == nil {
return targetPackage, nil, nil, nil, nil,
fmt.Errorf("Platform %s is not installed", platformRelease)
fmt.Errorf("platform %s is not installed", platformRelease)
}

// Find board
Expand Down Expand Up @@ -210,31 +210,31 @@ func (pm *PackageManager) LoadPackageIndex(URL *url.URL) error {

// Package looks for the Package with the given name, returning a structure
// able to perform further operations on that given resource
func (pm *PackageManager) Package(name string) *packageActions {
func (pm *PackageManager) Package(name string) *PackageActions {
//TODO: perhaps these 2 structure should be merged? cores.Packages vs pkgmgr??
var err error
thePackage := pm.packages.Packages[name]
if thePackage == nil {
err = fmt.Errorf("package '%s' not found", name)
}
return &packageActions{
return &PackageActions{
aPackage: thePackage,
forwardError: err,
}
}

// Actions that can be done on a Package

// packageActions defines what actions can be performed on the specific Package
// PackageActions defines what actions can be performed on the specific Package
// It serves as a status container for the fluent APIs
type packageActions struct {
type PackageActions struct {
aPackage *cores.Package
forwardError error
}

// Tool looks for the Tool with the given name, returning a structure
// able to perform further operations on that given resource
func (pa *packageActions) Tool(name string) *toolActions {
func (pa *PackageActions) Tool(name string) *ToolActions {
var tool *cores.Tool
err := pa.forwardError
if err == nil {
Expand All @@ -244,7 +244,7 @@ func (pa *packageActions) Tool(name string) *toolActions {
err = fmt.Errorf("tool '%s' not found in package '%s'", name, pa.aPackage.Name)
}
}
return &toolActions{
return &ToolActions{
tool: tool,
forwardError: err,
}
Expand All @@ -254,15 +254,15 @@ func (pa *packageActions) Tool(name string) *toolActions {

// Actions that can be done on a Tool

// toolActions defines what actions can be performed on the specific Tool
// ToolActions defines what actions can be performed on the specific Tool
// It serves as a status container for the fluent APIs
type toolActions struct {
type ToolActions struct {
tool *cores.Tool
forwardError error
}

// Get returns the final representation of the Tool
func (ta *toolActions) Get() (*cores.Tool, error) {
func (ta *ToolActions) Get() (*cores.Tool, error) {
err := ta.forwardError
if err == nil {
return ta.tool, nil
Expand All @@ -271,7 +271,7 @@ func (ta *toolActions) Get() (*cores.Tool, error) {
}

// IsInstalled checks whether any release of the Tool is installed in the system
func (ta *toolActions) IsInstalled() (bool, error) {
func (ta *ToolActions) IsInstalled() (bool, error) {
if ta.forwardError != nil {
return false, ta.forwardError
}
Expand All @@ -284,27 +284,27 @@ func (ta *toolActions) IsInstalled() (bool, error) {
return false, nil
}

func (ta *toolActions) Release(version *semver.RelaxedVersion) *toolReleaseActions {
func (ta *ToolActions) Release(version *semver.RelaxedVersion) *ToolReleaseActions {
if ta.forwardError != nil {
return &toolReleaseActions{forwardError: ta.forwardError}
return &ToolReleaseActions{forwardError: ta.forwardError}
}
release := ta.tool.GetRelease(version)
release := ta.tool.FindReleaseWithRelaxedVersion(version)
if release == nil {
return &toolReleaseActions{forwardError: fmt.Errorf("release %s not found for tool %s", version, ta.tool.String())}
return &ToolReleaseActions{forwardError: fmt.Errorf("release %s not found for tool %s", version, ta.tool.String())}
}
return &toolReleaseActions{release: release}
return &ToolReleaseActions{release: release}
}

// END -- Actions that can be done on a Tool

// toolReleaseActions defines what actions can be performed on the specific ToolRelease
// ToolReleaseActions defines what actions can be performed on the specific ToolRelease
// It serves as a status container for the fluent APIs
type toolReleaseActions struct {
type ToolReleaseActions struct {
release *cores.ToolRelease
forwardError error
}

func (tr *toolReleaseActions) Get() (*cores.ToolRelease, error) {
func (tr *ToolReleaseActions) Get() (*cores.ToolRelease, error) {
if tr.forwardError != nil {
return nil, tr.forwardError
}
Expand Down
12 changes: 6 additions & 6 deletions arduino/cores/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ func (targetPackage *Package) String() string {
func (tdep ToolDependency) extractTool(sc Packages) (*Tool, error) {
pkg, exists := sc.Packages[tdep.ToolPackager]
if !exists {
return nil, errors.New("Package not found")
return nil, errors.New("package not found")
}
tool, exists := pkg.Tools[tdep.ToolName]
if !exists {
return nil, errors.New("Tool not found")
return nil, errors.New("tool not found")
}
return tool, nil
}
Expand All @@ -129,7 +129,7 @@ func (tdep ToolDependency) extractRelease(sc Packages) (*ToolRelease, error) {
}
release, exists := tool.Releases[tdep.ToolVersion.String()]
if !exists {
return nil, errors.New("Release Not Found")
return nil, errors.New("release not found")
}
return release, nil
}
Expand All @@ -143,15 +143,15 @@ func (packages *Packages) GetDepsOfPlatformRelease(release *PlatformRelease) ([]
for _, dep := range release.Dependencies {
pkg, exists := packages.Packages[dep.ToolPackager]
if !exists {
return nil, fmt.Errorf("Package %s not found", dep.ToolPackager)
return nil, fmt.Errorf("package %s not found", dep.ToolPackager)
}
tool, exists := pkg.Tools[dep.ToolName]
if !exists {
return nil, fmt.Errorf("Tool %s not found", dep.ToolName)
return nil, fmt.Errorf("tool %s not found", dep.ToolName)
}
toolRelease, exists := tool.Releases[dep.ToolVersion.String()]
if !exists {
return nil, fmt.Errorf("Tool version %s not found", dep.ToolVersion)
return nil, fmt.Errorf("tool version %s not found", dep.ToolVersion)
}
ret = append(ret, toolRelease)
}
Expand Down
25 changes: 13 additions & 12 deletions arduino/cores/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ type Tool struct {
// ToolRelease represents a single release of a tool
type ToolRelease struct {
Version *semver.RelaxedVersion `json:"version,required"` // The version number of this Release.
Flavours []*Flavour `json:"systems"` // Maps OS to Flavour
Flavors []*Flavor `json:"systems"` // Maps OS to Flavor
Tool *Tool `json:"-"`
InstallDir *paths.Path `json:"-"`
}

// Flavour represents a flavour of a Tool version.
type Flavour struct {
OS string `json:"os,required"` // The OS Supported by this flavour.
// Flavor represents a flavor of a Tool version.
type Flavor struct {
OS string `json:"os,required"` // The OS Supported by this flavor.
Resource *resources.DownloadResource
}

Expand All @@ -62,9 +62,9 @@ func (tool *Tool) GetOrCreateRelease(version *semver.RelaxedVersion) *ToolReleas
return release
}

// GetRelease returns the specified release corresponding the provided version,
// FindReleaseWithRelaxedVersion returns the specified release corresponding the provided version,
// or nil if not found.
func (tool *Tool) GetRelease(version *semver.RelaxedVersion) *ToolRelease {
func (tool *Tool) FindReleaseWithRelaxedVersion(version *semver.RelaxedVersion) *ToolRelease {
return tool.Releases[version.String()]
}

Expand All @@ -81,11 +81,12 @@ func (tool *Tool) GetAllReleasesVersions() []*semver.RelaxedVersion {

// LatestRelease obtains latest version of a core package.
func (tool *Tool) LatestRelease() *ToolRelease {
if latest := tool.latestReleaseVersion(); latest == nil {
latest := tool.latestReleaseVersion()
if latest == nil {
return nil
} else {
return tool.GetRelease(latest)
}

return tool.FindReleaseWithRelaxedVersion(latest)
}

// latestReleaseVersion obtains latest version number.
Expand Down Expand Up @@ -149,11 +150,11 @@ var (
regexpArmBSD = regexp.MustCompile("arm.*-freebsd[0-9]*")
)

func (f *Flavour) isCompatibleWithCurrentMachine() bool {
func (f *Flavor) isCompatibleWithCurrentMachine() bool {
return f.isCompatibleWith(runtime.GOOS, runtime.GOARCH)
}

func (f *Flavour) isCompatibleWith(osName, osArch string) bool {
func (f *Flavor) isCompatibleWith(osName, osArch string) bool {
if f.OS == "all" {
return true
}
Expand Down Expand Up @@ -182,7 +183,7 @@ func (f *Flavour) isCompatibleWith(osName, osArch string) bool {

// GetCompatibleFlavour returns the downloadable resource compatible with the running O.S.
func (tr *ToolRelease) GetCompatibleFlavour() *resources.DownloadResource {
for _, flavour := range tr.Flavours {
for _, flavour := range tr.Flavors {
if flavour.isCompatibleWithCurrentMachine() {
return flavour.Resource
}
Expand Down
20 changes: 10 additions & 10 deletions arduino/cores/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ func TestFlavorCompatibility(t *testing.T) {
}

type test struct {
Flavour *Flavour
Flavour *Flavor
Positives []*os
}
tests := []*test{
&test{&Flavour{OS: "i686-mingw32"}, []*os{windowsi386, windowsx8664}},
&test{&Flavour{OS: "i386-apple-darwin11"}, []*os{darwini386, darwinamd646}},
&test{&Flavour{OS: "x86_64-apple-darwin"}, []*os{darwinamd646}},
{&Flavor{OS: "i686-mingw32"}, []*os{windowsi386, windowsx8664}},
{&Flavor{OS: "i386-apple-darwin11"}, []*os{darwini386, darwinamd646}},
{&Flavor{OS: "x86_64-apple-darwin"}, []*os{darwinamd646}},

// Raspberry PI, BBB or other ARM based host
// PI: "arm-linux-gnueabihf"
// Raspbian on PI2: "arm-linux-gnueabihf"
// Ubuntu Mate on PI2: "arm-linux-gnueabihf"
// Debian 7.9 on BBB: "arm-linux-gnueabihf"
// Raspbian on PI Zero: "arm-linux-gnueabihf"
&test{&Flavour{OS: "arm-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}},
{&Flavor{OS: "arm-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}},
// Arch-linux on PI2: "armv7l-unknown-linux-gnueabihf"
&test{&Flavour{OS: "armv7l-unknown-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}},
{&Flavor{OS: "armv7l-unknown-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}},

&test{&Flavour{OS: "i686-linux-gnu"}, []*os{linuxi386}},
&test{&Flavour{OS: "i686-pc-linux-gnu"}, []*os{linuxi386}},
&test{&Flavour{OS: "x86_64-linux-gnu"}, []*os{linuxamd64}},
&test{&Flavour{OS: "x86_64-pc-linux-gnu"}, []*os{linuxamd64}},
{&Flavor{OS: "i686-linux-gnu"}, []*os{linuxi386}},
{&Flavor{OS: "i686-pc-linux-gnu"}, []*os{linuxi386}},
{&Flavor{OS: "x86_64-linux-gnu"}, []*os{linuxamd64}},
{&Flavor{OS: "x86_64-pc-linux-gnu"}, []*os{linuxamd64}},
}

check := func(test *test, os *os) {
Expand Down
2 changes: 1 addition & 1 deletion arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (library *Library) IsOptimizedForArchitecture(arch string) bool {
}

// IsArchitectureIndependent returns true if the library declares to be
// compatibile with all architectures (the `architecture` field in
// compatible with all architectures (the `architecture` field in
// library.properties contains the `*` item)
func (library *Library) IsArchitectureIndependent() bool {
return library.IsOptimizedForArchitecture("*")
Expand Down
Loading