From da074e2d3455f547843fb44dd303d6409416c3d8 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 12:58:30 +0200 Subject: [PATCH 01/18] Added linter configurations and disabled all the linters except golint --- .golangci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000000..583a23d8062 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,40 @@ +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 + + misspell: + locale: US + +linters: + enable-all: true + disable: + - deadcode + - dupl + - errcheck + - goconst + - gocyclo + - gofmt + - govet + - ineffassign + - interfacer + - lll + - maligned + - megacheck + - megacheck + - misspell + - nakedret + - prealloc + - unconvert + - unparam + - varcheck From 2ec92e7c3ebdd5ca48fb9a49206a3ea33d574b02 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 12:59:22 +0200 Subject: [PATCH 02/18] Fixed almost all the problem reported by golint --- .../cores/packagemanager/package_manager.go | 36 +++++++++---------- arduino/cores/status.go | 12 +++---- arduino/cores/tools.go | 7 ++-- arduino/resources/helpers.go | 8 ++--- arduino/resources/install.go | 6 ++-- builder_client_helpers/alive.go | 2 +- builder_client_helpers/boards.go | 2 +- builder_client_helpers/boards_v2.go | 2 +- builder_client_helpers/client.go | 2 +- builder_client_helpers/compilations.go | 2 +- builder_client_helpers/examples.go | 12 +++---- builder_client_helpers/files.go | 2 +- builder_client_helpers/libraries.go | 12 +++---- builder_client_helpers/media_types.go | 2 +- builder_client_helpers/pinned_libraries.go | 2 +- builder_client_helpers/public.go | 2 +- builder_client_helpers/user_types.go | 2 +- commands/commands_test.go | 2 +- commands/sketch/sync.go | 26 +++++++------- common/formatter/examples_test.go | 2 +- common/formatter/formatter.go | 4 +-- configs/preferences_txt_serializer.go | 4 +-- create_client_helpers/alive.go | 2 +- create_client_helpers/client.go | 2 +- create_client_helpers/files.go | 6 ++-- create_client_helpers/media_types.go | 2 +- create_client_helpers/sketches.go | 2 +- create_client_helpers/user_types.go | 2 +- 28 files changed, 84 insertions(+), 83 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index f5c650fb210..963d97acc8d 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -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 @@ -210,14 +210,14 @@ 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, } @@ -225,16 +225,16 @@ func (pm *PackageManager) Package(name string) *packageActions { // 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 { @@ -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, } @@ -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 @@ -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 } @@ -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) 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 } diff --git a/arduino/cores/status.go b/arduino/cores/status.go index e2d1349b61c..0bbf7f96fde 100644 --- a/arduino/cores/status.go +++ b/arduino/cores/status.go @@ -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 } @@ -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 } @@ -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) } diff --git a/arduino/cores/tools.go b/arduino/cores/tools.go index 308fa86966d..20c71cbf098 100644 --- a/arduino/cores/tools.go +++ b/arduino/cores/tools.go @@ -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.GetRelease(latest) } // latestReleaseVersion obtains latest version number. diff --git a/arduino/resources/helpers.go b/arduino/resources/helpers.go index a71fe87f568..4328743902d 100644 --- a/arduino/resources/helpers.go +++ b/arduino/resources/helpers.go @@ -41,12 +41,12 @@ func (r *DownloadResource) IsCached(downloadDir *paths.Path) (bool, error) { if err != nil { return false, fmt.Errorf("getting archive path: %s", err) } - - if exist, err := archivePath.Exist(); err != nil { + exist, err := archivePath.Exist() + if err != nil { return false, fmt.Errorf("checking archive existence: %s", err) - } else { - return exist, nil } + + return exist, nil } // Download a DownloadResource. diff --git a/arduino/resources/install.go b/arduino/resources/install.go index d1919683a1b..decaa35281b 100644 --- a/arduino/resources/install.go +++ b/arduino/resources/install.go @@ -96,11 +96,11 @@ func (release *DownloadResource) Install(downloadDir, tempPath, destDir *paths.P // IsDirEmpty returns true if the directory specified by path is empty. func IsDirEmpty(path *paths.Path) (bool, error) { - if files, err := path.ReadDir(); err != nil { + files, err := path.ReadDir() + if err != nil { return false, err - } else { - return len(files) == 0, nil } + return len(files) == 0, nil } func findPackageRoot(parent *paths.Path) (*paths.Path, error) { diff --git a/builder_client_helpers/alive.go b/builder_client_helpers/alive.go index f5a9b79ebd5..767f16b2a44 100644 --- a/builder_client_helpers/alive.go +++ b/builder_client_helpers/alive.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" diff --git a/builder_client_helpers/boards.go b/builder_client_helpers/boards.go index a522308e0fb..75ceb336362 100644 --- a/builder_client_helpers/boards.go +++ b/builder_client_helpers/boards.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" diff --git a/builder_client_helpers/boards_v2.go b/builder_client_helpers/boards_v2.go index fea62d72dfc..957e536b701 100644 --- a/builder_client_helpers/boards_v2.go +++ b/builder_client_helpers/boards_v2.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" diff --git a/builder_client_helpers/client.go b/builder_client_helpers/client.go index 5dd4b90bb4e..6ec3ff668f8 100644 --- a/builder_client_helpers/client.go +++ b/builder_client_helpers/client.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "github.com/goadesign/goa" diff --git a/builder_client_helpers/compilations.go b/builder_client_helpers/compilations.go index e811e881b4a..0a1e57396b4 100644 --- a/builder_client_helpers/compilations.go +++ b/builder_client_helpers/compilations.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "bytes" diff --git a/builder_client_helpers/examples.go b/builder_client_helpers/examples.go index fa9a7ba87ec..b825d405a3a 100644 --- a/builder_client_helpers/examples.go +++ b/builder_client_helpers/examples.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" @@ -30,8 +30,8 @@ func ListExamplesPath() string { } // ListExamples provides a list of all the builtin examples -func (c *Client) ListExamples(ctx context.Context, path string, maintainer *string, type_ *string) (*http.Response, error) { - req, err := c.NewListExamplesRequest(ctx, path, maintainer, type_) +func (c *Client) ListExamples(ctx context.Context, path string, maintainer *string, type1 *string) (*http.Response, error) { + req, err := c.NewListExamplesRequest(ctx, path, maintainer, type1) if err != nil { return nil, err } @@ -39,7 +39,7 @@ func (c *Client) ListExamples(ctx context.Context, path string, maintainer *stri } // NewListExamplesRequest create the request corresponding to the list action endpoint of the examples resource. -func (c *Client) NewListExamplesRequest(ctx context.Context, path string, maintainer *string, type_ *string) (*http.Request, error) { +func (c *Client) NewListExamplesRequest(ctx context.Context, path string, maintainer *string, type1 *string) (*http.Request, error) { scheme := c.Scheme if scheme == "" { scheme = "http" @@ -49,8 +49,8 @@ func (c *Client) NewListExamplesRequest(ctx context.Context, path string, mainta if maintainer != nil { values.Set("maintainer", *maintainer) } - if type_ != nil { - values.Set("type", *type_) + if type1 != nil { + values.Set("type", *type1) } u.RawQuery = values.Encode() req, err := http.NewRequest("GET", u.String(), nil) diff --git a/builder_client_helpers/files.go b/builder_client_helpers/files.go index 91f140a8f15..fe6fef3cb23 100644 --- a/builder_client_helpers/files.go +++ b/builder_client_helpers/files.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" diff --git a/builder_client_helpers/libraries.go b/builder_client_helpers/libraries.go index 06a83f28a4a..edf86c5485a 100644 --- a/builder_client_helpers/libraries.go +++ b/builder_client_helpers/libraries.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" @@ -30,8 +30,8 @@ func ListLibrariesPath() string { } // ListLibraries provides a list of all the latest versions of the libraries supported by Arduino Create. Doesn't require any authentication. -func (c *Client) ListLibraries(ctx context.Context, path string, maintainer *string, type_ *string, withoutType *string) (*http.Response, error) { - req, err := c.NewListLibrariesRequest(ctx, path, maintainer, type_, withoutType) +func (c *Client) ListLibraries(ctx context.Context, path string, maintainer *string, type1 *string, withoutType *string) (*http.Response, error) { + req, err := c.NewListLibrariesRequest(ctx, path, maintainer, type1, withoutType) if err != nil { return nil, err } @@ -39,7 +39,7 @@ func (c *Client) ListLibraries(ctx context.Context, path string, maintainer *str } // NewListLibrariesRequest create the request corresponding to the list action endpoint of the libraries resource. -func (c *Client) NewListLibrariesRequest(ctx context.Context, path string, maintainer *string, type_ *string, withoutType *string) (*http.Request, error) { +func (c *Client) NewListLibrariesRequest(ctx context.Context, path string, maintainer *string, type1 *string, withoutType *string) (*http.Request, error) { scheme := c.Scheme if scheme == "" { scheme = "http" @@ -49,8 +49,8 @@ func (c *Client) NewListLibrariesRequest(ctx context.Context, path string, maint if maintainer != nil { values.Set("maintainer", *maintainer) } - if type_ != nil { - values.Set("type", *type_) + if type1 != nil { + values.Set("type", *type1) } if withoutType != nil { values.Set("without_type", *withoutType) diff --git a/builder_client_helpers/media_types.go b/builder_client_helpers/media_types.go index 098f2632084..0e8256c5118 100644 --- a/builder_client_helpers/media_types.go +++ b/builder_client_helpers/media_types.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "net/http" diff --git a/builder_client_helpers/pinned_libraries.go b/builder_client_helpers/pinned_libraries.go index d684e233f59..99a5a031241 100644 --- a/builder_client_helpers/pinned_libraries.go +++ b/builder_client_helpers/pinned_libraries.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "context" diff --git a/builder_client_helpers/public.go b/builder_client_helpers/public.go index a98ecc78ab7..9416f7f3f38 100644 --- a/builder_client_helpers/public.go +++ b/builder_client_helpers/public.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient /* import ( diff --git a/builder_client_helpers/user_types.go b/builder_client_helpers/user_types.go index 4926633628f..89b99fff571 100644 --- a/builder_client_helpers/user_types.go +++ b/builder_client_helpers/user_types.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package builderClient +package builderclient import ( "github.com/goadesign/goa" diff --git a/commands/commands_test.go b/commands/commands_test.go index 404f1d504be..c1ed1307d4c 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -35,7 +35,7 @@ import ( // Redirecting stdOut so we can analyze output line by // line and check with what we want. -var stdOut *os.File = os.Stdout +var stdOut = os.Stdout // *os.File type stdOutRedirect struct { tempFile *os.File diff --git a/commands/sketch/sync.go b/commands/sketch/sync.go index 30437ef1e1f..e9631de83ac 100644 --- a/commands/sketch/sync.go +++ b/commands/sketch/sync.go @@ -129,9 +129,9 @@ func runSyncCommand(cmd *cobra.Command, args []string) { sketchMap := sketches.Find(sketchbook.String(), "libraries") // Exclude libraries dirs. logrus.Info("Finding online sketches") - client := createClient.New(nil) + client := createclient.New(nil) tok := "Bearer " + bearerToken - resp, err := client.SearchSketches(context.Background(), createClient.SearchSketchesPath(), nil, &username, &tok) + resp, err := client.SearchSketches(context.Background(), createclient.SearchSketchesPath(), nil, &username, &tok) if err != nil { stopSpinner() formatter.PrintError(err, "Cannot get create sketches, sync failed.") @@ -146,7 +146,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) { os.Exit(commands.ErrGeneric) } - onlineSketchesMap := make(map[string]*createClient.ArduinoCreateSketch, len(onlineSketches.Sketches)) + onlineSketchesMap := make(map[string]*createclient.ArduinoCreateSketch, len(onlineSketches.Sketches)) for _, item := range onlineSketches.Sketches { onlineSketchesMap[*item.Name] = item } @@ -271,9 +271,9 @@ func runSyncCommand(cmd *cobra.Command, args []string) { } func pushSketch(sketch sketches.Sketch, sketchbook *paths.Path, bearerToken string) error { - client := createClient.New(nil) + client := createclient.New(nil) - resp, err := client.CreateSketches(context.Background(), createClient.CreateSketchesPath(), createClient.ConvertFrom(sketch), "Bearer "+bearerToken) + resp, err := client.CreateSketches(context.Background(), createclient.CreateSketchesPath(), createclient.ConvertFrom(sketch), "Bearer "+bearerToken) if err != nil { return err } @@ -295,8 +295,8 @@ func pushSketch(sketch sketches.Sketch, sketchbook *paths.Path, bearerToken stri } func editSketch(sketch sketches.Sketch, sketchbook *paths.Path, bearerToken string) error { - client := createClient.New(nil) - resp, err := client.EditSketches(context.Background(), createClient.EditSketchesPath(sketch.ID), createClient.ConvertFrom(sketch), "Bearer "+bearerToken) + client := createclient.New(nil) + resp, err := client.EditSketches(context.Background(), createclient.EditSketchesPath(sketch.ID), createclient.ConvertFrom(sketch), "Bearer "+bearerToken) if err != nil { return err } @@ -317,11 +317,11 @@ func editSketch(sketch sketches.Sketch, sketchbook *paths.Path, bearerToken stri return nil } -func pullSketch(sketch *createClient.ArduinoCreateSketch, sketchbook *paths.Path, bearerToken string) error { - client := createClient.New(nil) +func pullSketch(sketch *createclient.ArduinoCreateSketch, sketchbook *paths.Path, bearerToken string) error { + client := createclient.New(nil) bearer := "Bearer " + bearerToken - resp, err := client.ShowSketches(context.Background(), createClient.ShowSketchesPath(fmt.Sprint(sketch.ID)), &bearer) + resp, err := client.ShowSketches(context.Background(), createclient.ShowSketchesPath(fmt.Sprint(sketch.ID)), &bearer) if err != nil { return err } @@ -356,7 +356,7 @@ func pullSketch(sketch *createClient.ArduinoCreateSketch, sketchbook *paths.Path return err } - resp, err = client.ShowFiles(context.Background(), createClient.ShowFilesPath("sketch", sketch.ID.String(), path)) + resp, err = client.ShowFiles(context.Background(), createclient.ShowFilesPath("sketch", sketch.ID.String(), path)) if err != nil { return err } @@ -379,7 +379,7 @@ func pullSketch(sketch *createClient.ArduinoCreateSketch, sketchbook *paths.Path destFile := sketchDir.Join(path) err = destFile.WriteFile(decodedData) if err != nil { - return errors.New("Copy of a file of the downloaded sketch failed, sync failed.") + return errors.New("copy of a file of the downloaded sketch failed, sync failed") } } @@ -431,7 +431,7 @@ func login() (string, string, error) { arduinoMachine := NetRC.FindMachine("arduino.cc") if arduinoMachine == nil || arduinoMachine.Name != "arduino.cc" { logrus.WithError(err).Error("Credentials not found") - return "", "", errors.New("Credentials not found, try typing `arduino login` to login") + return "", "", errors.New("credentials not found, try typing `arduino login` to login") } logrus.Info("Refreshing user session") diff --git a/common/formatter/examples_test.go b/common/formatter/examples_test.go index f4b92332673..47fd6334c18 100644 --- a/common/formatter/examples_test.go +++ b/common/formatter/examples_test.go @@ -49,7 +49,7 @@ func ExampleJSONFormatter_Format() { var jf formatter.JSONFormatter fmt.Println(jf.Format(example)) - var example2 float64 = 3.14 + var example2 = 3.14 fmt.Println(jf.Format(example2)) var example3 float32 = 3.14 diff --git a/common/formatter/formatter.go b/common/formatter/formatter.go index 8a959183240..0561dab2fed 100644 --- a/common/formatter/formatter.go +++ b/common/formatter/formatter.go @@ -54,7 +54,7 @@ func init() { // SetFormatter sets the defaults format to the one specified, if valid. Otherwise it returns an error. func SetFormatter(formatName string) error { if !IsSupported(formatName) { - return fmt.Errorf("Formatter for %s format not implemented", formatName) + return fmt.Errorf("formatter for %s format not implemented", formatName) } defaultFormatter = formatters[formatName] return nil @@ -91,7 +91,7 @@ func AddCustomFormatter(formatName string, form Formatter) Formatter { // Format formats a message formatted using a Formatter specified by SetFormatter(...) function. func Format(msg interface{}) (string, error) { if defaultFormatter == nil { - return "", errors.New("No formatter set") + return "", errors.New("no formatter set") } return defaultFormatter.Format(msg) } diff --git a/configs/preferences_txt_serializer.go b/configs/preferences_txt_serializer.go index ec5bb5106a1..3ff4b097bae 100644 --- a/configs/preferences_txt_serializer.go +++ b/configs/preferences_txt_serializer.go @@ -105,7 +105,7 @@ func proxyConfigsFromIDEPrefs(props properties.Map) error { manualConfig := proxy.SubTree("manual") hostname, exists := manualConfig["hostname"] if !exists { - return errors.New("Proxy hostname not found in preferences.txt") + return errors.New("proxy hostname not found in preferences.txt") } username := manualConfig["username"] password := manualConfig["password"] @@ -119,7 +119,7 @@ func proxyConfigsFromIDEPrefs(props properties.Map) error { // No proxy break default: - return errors.New("Unsupported proxy config") + return errors.New("unsupported proxy config") } return nil } diff --git a/create_client_helpers/alive.go b/create_client_helpers/alive.go index d57f40b5756..311c57d4a0b 100644 --- a/create_client_helpers/alive.go +++ b/create_client_helpers/alive.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package createClient +package createclient import ( "context" diff --git a/create_client_helpers/client.go b/create_client_helpers/client.go index 385b4160fda..bbdc7498787 100644 --- a/create_client_helpers/client.go +++ b/create_client_helpers/client.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package createClient +package createclient import ( "github.com/goadesign/goa" diff --git a/create_client_helpers/files.go b/create_client_helpers/files.go index 8337b5f61ee..81d02b6a767 100644 --- a/create_client_helpers/files.go +++ b/create_client_helpers/files.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package createClient +package createclient import ( "context" @@ -25,8 +25,8 @@ import ( ) // ShowFilesPath computes a request path to the show action of files. -func ShowFilesPath(type_ string, id string, name string) string { - param0 := type_ +func ShowFilesPath(fileType string, id string, name string) string { + param0 := fileType param1 := id param2 := name diff --git a/create_client_helpers/media_types.go b/create_client_helpers/media_types.go index fcfec728efb..94fd7d77d58 100644 --- a/create_client_helpers/media_types.go +++ b/create_client_helpers/media_types.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package createClient +package createclient import ( "net/http" diff --git a/create_client_helpers/sketches.go b/create_client_helpers/sketches.go index e359cf253c0..db3171fbaf1 100644 --- a/create_client_helpers/sketches.go +++ b/create_client_helpers/sketches.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package createClient +package createclient import ( "bytes" diff --git a/create_client_helpers/user_types.go b/create_client_helpers/user_types.go index 80f4342c883..de99a43fff1 100644 --- a/create_client_helpers/user_types.go +++ b/create_client_helpers/user_types.go @@ -15,7 +15,7 @@ * a commercial license, send an email to license@arduino.cc. */ -package createClient +package createclient import ( "encoding/base64" From e0009794a563405cabb80ddf578b4dbc37dd4af9 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 13:57:02 +0200 Subject: [PATCH 03/18] Fixed all the problem reported by misspell --- .golangci.yml | 1 - arduino/cores/packageindex/index.go | 12 +++++----- arduino/cores/tools.go | 14 ++++++------ arduino/cores/tools_test.go | 20 ++++++++--------- arduino/libraries/libraries.go | 2 +- arduino/libraries/libraries_layout.go | 2 +- arduino/libraries/librariesresolver/cpp.go | 2 +- builder_client_helpers/media_types.go | 26 +++++++++++----------- commands/board/attach.go | 2 +- commands/compile/compile.go | 2 +- commands/compile/ctags.go | 12 +++++----- commands/core/download.go | 2 +- 12 files changed, 48 insertions(+), 49 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 583a23d8062..ea38971a98e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,7 +32,6 @@ linters: - maligned - megacheck - megacheck - - misspell - nakedret - prealloc - unconvert diff --git a/arduino/cores/packageindex/index.go b/arduino/cores/packageindex/index.go index 51587e6d57b..075dc0fda16 100644 --- a/arduino/cores/packageindex/index.go +++ b/arduino/cores/packageindex/index.go @@ -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"` @@ -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, diff --git a/arduino/cores/tools.go b/arduino/cores/tools.go index 20c71cbf098..d4349dfce10 100644 --- a/arduino/cores/tools.go +++ b/arduino/cores/tools.go @@ -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 } @@ -150,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 } @@ -183,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 } diff --git a/arduino/cores/tools_test.go b/arduino/cores/tools_test.go index fed6ecc798e..d590dca8097 100644 --- a/arduino/cores/tools_test.go +++ b/arduino/cores/tools_test.go @@ -52,13 +52,13 @@ 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}}, + &test{&Flavor{OS: "i686-mingw32"}, []*os{windowsi386, windowsx8664}}, + &test{&Flavor{OS: "i386-apple-darwin11"}, []*os{darwini386, darwinamd646}}, + &test{&Flavor{OS: "x86_64-apple-darwin"}, []*os{darwinamd646}}, // Raspberry PI, BBB or other ARM based host // PI: "arm-linux-gnueabihf" @@ -66,14 +66,14 @@ func TestFlavorCompatibility(t *testing.T) { // 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}}, + &test{&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}}, + &test{&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}}, + &test{&Flavor{OS: "i686-linux-gnu"}, []*os{linuxi386}}, + &test{&Flavor{OS: "i686-pc-linux-gnu"}, []*os{linuxi386}}, + &test{&Flavor{OS: "x86_64-linux-gnu"}, []*os{linuxamd64}}, + &test{&Flavor{OS: "x86_64-pc-linux-gnu"}, []*os{linuxamd64}}, } check := func(test *test, os *os) { diff --git a/arduino/libraries/libraries.go b/arduino/libraries/libraries.go index 5b7a042a5e2..e9340face1a 100644 --- a/arduino/libraries/libraries.go +++ b/arduino/libraries/libraries.go @@ -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("*") diff --git a/arduino/libraries/libraries_layout.go b/arduino/libraries/libraries_layout.go index a3a60a6b406..ee9ca771117 100644 --- a/arduino/libraries/libraries_layout.go +++ b/arduino/libraries/libraries_layout.go @@ -22,7 +22,7 @@ import ( "fmt" ) -// LibraryLayout represents how the library source code is layed out in the library +// LibraryLayout represents how the library source code is laid out in the library type LibraryLayout uint16 const ( diff --git a/arduino/libraries/librariesresolver/cpp.go b/arduino/libraries/librariesresolver/cpp.go index 83f0f5ecb5b..8810e7468d3 100644 --- a/arduino/libraries/librariesresolver/cpp.go +++ b/arduino/libraries/librariesresolver/cpp.go @@ -106,7 +106,7 @@ func computePriority(lib *libraries.Library, header, arch string) int { header = simplify(header) name := simplify(lib.Name) - priority := int(lib.PriorityForArchitecture(arch)) // bewteen 0..255 + priority := int(lib.PriorityForArchitecture(arch)) // between 0..255 if name == header { priority += 0x500 } else if name == header+"-master" { diff --git a/builder_client_helpers/media_types.go b/builder_client_helpers/media_types.go index 0e8256c5118..a310e8abdfa 100644 --- a/builder_client_helpers/media_types.go +++ b/builder_client_helpers/media_types.go @@ -32,7 +32,7 @@ type ArduinoBuilderBoard struct { Architecture *string `form:"architecture,omitempty" json:"architecture,omitempty" xml:"architecture,omitempty"` Bootloader []*ArduinoBuilderBoardBootloader `form:"bootloader,omitempty" json:"bootloader,omitempty" xml:"bootloader,omitempty"` Build []*ArduinoBuilderBoardBuild `form:"build,omitempty" json:"build,omitempty" xml:"build,omitempty"` - // The default flavour of the board + // The default flavor of the board DefaultFlavour *string `form:"default_flavour,omitempty" json:"default_flavour,omitempty" xml:"default_flavour,omitempty"` // An identifier used by the tools to determine which tools to use on it Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"` @@ -62,7 +62,7 @@ func (c *Client) DecodeArduinoBuilderBoard(resp *http.Response) (*ArduinoBuilder type ArduinoBuilderBoardBootloader struct { // The commandline used to bootload Commandline *string `form:"commandline,omitempty" json:"commandline,omitempty" xml:"commandline,omitempty"` - // The flavour of the board. Usually it's default + // The flavor of the board. Usually it's default Flavour *string `form:"flavour,omitempty" json:"flavour,omitempty" xml:"flavour,omitempty"` // The signature of the commandline Signature *string `form:"signature,omitempty" json:"signature,omitempty" xml:"signature,omitempty"` @@ -75,11 +75,11 @@ func (c *Client) DecodeArduinoBuilderBoardBootloader(resp *http.Response) (*Ardu return &decoded, err } -// ArduinoBuilderBoardBuild contains the info used to compile for a certain flavour of board. (default view) +// ArduinoBuilderBoardBuild contains the info used to compile for a certain flavor of board. (default view) // // Identifier: application/vnd.arduino.builder.board.build; view=default type ArduinoBuilderBoardBuild struct { - // The flavour of the board. Usually it's default + // The flavor of the board. Usually it's default Flavour *string `form:"flavour,omitempty" json:"flavour,omitempty" xml:"flavour,omitempty"` // An identifier used by the tools to determine which tools to use on it Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"` @@ -92,7 +92,7 @@ func (c *Client) DecodeArduinoBuilderBoardBuild(resp *http.Response) (*ArduinoBu return &decoded, err } -// ArduinoBuilderBoardUpload contains the info used to upload a certain flavour of board. (default view) +// ArduinoBuilderBoardUpload contains the info used to upload a certain flavor of board. (default view) // // Identifier: application/vnd.arduino.builder.board.upload; view=default type ArduinoBuilderBoardUpload struct { @@ -102,7 +102,7 @@ type ArduinoBuilderBoardUpload struct { Ext *string `form:"ext,omitempty" json:"ext,omitempty" xml:"ext,omitempty"` // Files used by the programmer Files ArduinoBuilderFileCollection `form:"files,omitempty" json:"files,omitempty" xml:"files,omitempty"` - // The flavour of the board. Usually it's default + // The flavor of the board. Usually it's default Flavour *string `form:"flavour,omitempty" json:"flavour,omitempty" xml:"flavour,omitempty"` // Some options used for uploading, like the speed. Options map[string]string `form:"options,omitempty" json:"options,omitempty" xml:"options,omitempty"` @@ -167,7 +167,7 @@ type ArduinoBuilderBoardv2 struct { // The architecture of the board Architecture *string `form:"architecture,omitempty" json:"architecture,omitempty" xml:"architecture,omitempty"` Build ArduinoBuilderBoardv2BuildCollection `form:"build,omitempty" json:"build,omitempty" xml:"build,omitempty"` - // The default flavour of the board + // The default flavor of the board DefaultFlavour *string `form:"default_flavour,omitempty" json:"default_flavour,omitempty" xml:"default_flavour,omitempty"` // An identifier used by the tools to determine which tools to use on it Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"` @@ -185,7 +185,7 @@ type ArduinoBuilderBoardv2Full struct { Architecture *string `form:"architecture,omitempty" json:"architecture,omitempty" xml:"architecture,omitempty"` Bootloader ArduinoBuilderBoardv2BootloaderCollection `form:"bootloader,omitempty" json:"bootloader,omitempty" xml:"bootloader,omitempty"` Build ArduinoBuilderBoardv2BuildCollection `form:"build,omitempty" json:"build,omitempty" xml:"build,omitempty"` - // The default flavour of the board + // The default flavor of the board DefaultFlavour *string `form:"default_flavour,omitempty" json:"default_flavour,omitempty" xml:"default_flavour,omitempty"` // An identifier used by the tools to determine which tools to use on it Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"` @@ -224,7 +224,7 @@ func (c *Client) DecodeArduinoBuilderBoardv2Full(resp *http.Response) (*ArduinoB type ArduinoBuilderBoardv2Bootloader struct { // The commandline used to bootload Commandline *string `form:"commandline,omitempty" json:"commandline,omitempty" xml:"commandline,omitempty"` - // The flavour of the board. Usually it's default + // The flavor of the board. Usually it's default Flavour *string `form:"flavour,omitempty" json:"flavour,omitempty" xml:"flavour,omitempty"` // The signature of the commandline Signature *string `form:"signature,omitempty" json:"signature,omitempty" xml:"signature,omitempty"` @@ -249,11 +249,11 @@ func (c *Client) DecodeArduinoBuilderBoardv2BootloaderCollection(resp *http.Resp return decoded, err } -// Build contains the info used to compile for a certain flavour of board. (default view) +// Build contains the info used to compile for a certain flavor of board. (default view) // // Identifier: application/vnd.arduino.builder.boardv2.build; view=default type ArduinoBuilderBoardv2Build struct { - // The flavour of the board. Usually it's default + // The flavor of the board. Usually it's default Flavour *string `form:"flavour,omitempty" json:"flavour,omitempty" xml:"flavour,omitempty"` // An identifier used by the tools to determine which tools to use on it Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"` @@ -278,7 +278,7 @@ func (c *Client) DecodeArduinoBuilderBoardv2BuildCollection(resp *http.Response) return decoded, err } -// ArduinoBuilderBoardv2Upload contains the info used to upload a certain flavour of board. (default view) +// ArduinoBuilderBoardv2Upload contains the info used to upload a certain flavor of board. (default view) // // Identifier: application/vnd.arduino.builder.boardv2.upload; view=default type ArduinoBuilderBoardv2Upload struct { @@ -288,7 +288,7 @@ type ArduinoBuilderBoardv2Upload struct { Ext *string `form:"ext,omitempty" json:"ext,omitempty" xml:"ext,omitempty"` // Files used by the programmer Files ArduinoBuilderFileCollection `form:"files,omitempty" json:"files,omitempty" xml:"files,omitempty"` - // The flavour of the board. Usually it's default + // The flavor of the board. Usually it's default Flavour *string `form:"flavour,omitempty" json:"flavour,omitempty" xml:"flavour,omitempty"` // Some options used for uploading, like the speed. Options map[string]string `form:"options,omitempty" json:"options,omitempty" xml:"options,omitempty"` diff --git a/commands/board/attach.go b/commands/board/attach.go index d69c2ae43a6..c9bdef8da4b 100644 --- a/commands/board/attach.go +++ b/commands/board/attach.go @@ -52,7 +52,7 @@ func initAttachCommand() *cobra.Command { } var attachFlags struct { - boardFlavour string // The flavour of the chipset of the cpu of the connected board, if not specified it is set to "default". + boardFlavour string // The flavor of the chipset of the cpu of the connected board, if not specified it is set to "default". searchTimeout string // Expressed in a parsable duration, is the timeout for the list and attach commands. } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index b786e2397b3..5441e29da41 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -70,7 +70,7 @@ var flags struct { buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties. warnings string // Used to tell gcc which warning level to use. verbose bool // Turns on verbose mode. - quiet bool // Supresses almost every output. + quiet bool // Suppresses almost every output. vidPid string // VID/PID specific build properties. } diff --git a/commands/compile/ctags.go b/commands/compile/ctags.go index 9b8748e849c..7d0395bbd38 100644 --- a/commands/compile/ctags.go +++ b/commands/compile/ctags.go @@ -28,8 +28,8 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { builtinPackage := pm.GetPackages().GetOrCreatePackage("builtin") ctagsTool := builtinPackage.GetOrCreateTool("ctags") ctagsRel := ctagsTool.GetOrCreateRelease(semver.ParseRelaxed("5.8-arduino11")) - ctagsRel.Flavours = []*cores.Flavour{ - &cores.Flavour{ + ctagsRel.Flavors = []*cores.Flavor{ + &cores.Flavor{ OS: "i686-pc-linux-gnu", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-i686-pc-linux-gnu.tar.bz2", @@ -39,7 +39,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavour{ + &cores.Flavor{ OS: "x86_64-pc-linux-gnu", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-x86_64-pc-linux-gnu.tar.bz2", @@ -49,7 +49,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavour{ + &cores.Flavor{ OS: "i686-mingw32", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-i686-mingw32.zip", @@ -59,7 +59,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavour{ + &cores.Flavor{ OS: "x86_64-apple-darwin", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-x86_64-apple-darwin.zip", @@ -69,7 +69,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavour{ + &cores.Flavor{ OS: "arm-linux-gnueabihf", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-armv6-linux-gnueabihf.tar.bz2", diff --git a/commands/core/download.go b/commands/core/download.go index 6d04455e3e4..0df8041266a 100644 --- a/commands/core/download.go +++ b/commands/core/download.go @@ -60,7 +60,7 @@ func downloadPlatformByRef(pm *packagemanager.PackageManager, platformsRef *pack os.Exit(commands.ErrBadCall) } - // Check if all tools have a flavour available for the current OS + // Check if all tools have a flavor available for the current OS for _, tool := range tools { if tool.GetCompatibleFlavour() == nil { formatter.PrintErrorMessage("The tool " + tool.String() + " is not available for the current OS") From c244d866193e2073ea226e6931a4d2fc75dfebd8 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:00:31 +0200 Subject: [PATCH 04/18] Fixed all the problem reported by gofmt --- .golangci.yml | 1 - arduino/cores/tools_test.go | 18 +++++++++--------- commands/compile/ctags.go | 10 +++++----- commands/sketch/sync.go | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ea38971a98e..eae6faafaea 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,7 +24,6 @@ linters: - errcheck - goconst - gocyclo - - gofmt - govet - ineffassign - interfacer diff --git a/arduino/cores/tools_test.go b/arduino/cores/tools_test.go index d590dca8097..4f7a002f3ad 100644 --- a/arduino/cores/tools_test.go +++ b/arduino/cores/tools_test.go @@ -56,9 +56,9 @@ func TestFlavorCompatibility(t *testing.T) { Positives []*os } tests := []*test{ - &test{&Flavor{OS: "i686-mingw32"}, []*os{windowsi386, windowsx8664}}, - &test{&Flavor{OS: "i386-apple-darwin11"}, []*os{darwini386, darwinamd646}}, - &test{&Flavor{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" @@ -66,14 +66,14 @@ func TestFlavorCompatibility(t *testing.T) { // Ubuntu Mate on PI2: "arm-linux-gnueabihf" // Debian 7.9 on BBB: "arm-linux-gnueabihf" // Raspbian on PI Zero: "arm-linux-gnueabihf" - &test{&Flavor{OS: "arm-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}}, + {&Flavor{OS: "arm-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}}, // Arch-linux on PI2: "armv7l-unknown-linux-gnueabihf" - &test{&Flavor{OS: "armv7l-unknown-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}}, + {&Flavor{OS: "armv7l-unknown-linux-gnueabihf"}, []*os{linuxarm, linuxarmbe}}, - &test{&Flavor{OS: "i686-linux-gnu"}, []*os{linuxi386}}, - &test{&Flavor{OS: "i686-pc-linux-gnu"}, []*os{linuxi386}}, - &test{&Flavor{OS: "x86_64-linux-gnu"}, []*os{linuxamd64}}, - &test{&Flavor{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) { diff --git a/commands/compile/ctags.go b/commands/compile/ctags.go index 7d0395bbd38..a5118f0baa8 100644 --- a/commands/compile/ctags.go +++ b/commands/compile/ctags.go @@ -29,7 +29,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { ctagsTool := builtinPackage.GetOrCreateTool("ctags") ctagsRel := ctagsTool.GetOrCreateRelease(semver.ParseRelaxed("5.8-arduino11")) ctagsRel.Flavors = []*cores.Flavor{ - &cores.Flavor{ + { OS: "i686-pc-linux-gnu", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-i686-pc-linux-gnu.tar.bz2", @@ -39,7 +39,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavor{ + { OS: "x86_64-pc-linux-gnu", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-x86_64-pc-linux-gnu.tar.bz2", @@ -49,7 +49,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavor{ + { OS: "i686-mingw32", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-i686-mingw32.zip", @@ -59,7 +59,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavor{ + { OS: "x86_64-apple-darwin", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-x86_64-apple-darwin.zip", @@ -69,7 +69,7 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) { CachePath: "tools", }, }, - &cores.Flavor{ + { OS: "arm-linux-gnueabihf", Resource: &resources.DownloadResource{ ArchiveFileName: "ctags-5.8-arduino11-pm-armv6-linux-gnueabihf.tar.bz2", diff --git a/commands/sketch/sync.go b/commands/sketch/sync.go index e9631de83ac..adca7d2c99f 100644 --- a/commands/sketch/sync.go +++ b/commands/sketch/sync.go @@ -400,7 +400,7 @@ func findPathOf(sketchName string, path string) string { for i := len(list) - 1; i > -1; i-- { //fmt.Println(list[i], "==", sketchName, "?", list[i] == sketchName) if list[i] == sketchName { - return filepath.Join(list[i+1 : len(list)]...) + return filepath.Join(list[i+1:]...) } } return "" From 3a661373e5cd8e63b30c876811765dc42dd3471e Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:02:36 +0200 Subject: [PATCH 05/18] Fixed all the problem reported by unconvert --- .golangci.yml | 1 - commands/login/login.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index eae6faafaea..6ceee0a4098 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -33,6 +33,5 @@ linters: - megacheck - nakedret - prealloc - - unconvert - unparam - varcheck diff --git a/commands/login/login.go b/commands/login/login.go index 85d7ff8aa13..880e4999731 100644 --- a/commands/login/login.go +++ b/commands/login/login.go @@ -80,7 +80,7 @@ func run(cmd *cobra.Command, args []string) { if passwordEmpty { fmt.Print("Password: ") - pass, err := terminal.ReadPassword(int(syscall.Stdin)) + pass, err := terminal.ReadPassword(syscall.Stdin) if err != nil { formatter.PrintError(err, "Cannot read password, login aborted.") return From b5cab6ec331d6e44e0409f4723fb6d1a3ade1291 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:04:50 +0200 Subject: [PATCH 06/18] Fixed all the problem reported by nakedret --- .golangci.yml | 2 -- commands/commands_test.go | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6ceee0a4098..8740734eb75 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,8 +30,6 @@ linters: - lll - maligned - megacheck - - megacheck - - nakedret - prealloc - unparam - varcheck diff --git a/commands/commands_test.go b/commands/commands_test.go index c1ed1307d4c..3767848c1d5 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -102,7 +102,7 @@ func executeWithArgs(t *testing.T, args ...string) (exitCode int, output []byte) cmd.SetArgs(args) cmd.Execute() - return + return exitCode, output } var currDataDir *paths.Path From 0561a765b878b085ca55313ab702a10344a8f6e6 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:09:17 +0200 Subject: [PATCH 07/18] Fixed all the problem reported by ineffassign ( ineffectual assignment) --- .golangci.yml | 1 - commands/commands_test.go | 4 +++- commands/compile/compile.go | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8740734eb75..d20e59f8024 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,6 @@ linters: - goconst - gocyclo - govet - - ineffassign - interfacer - lll - maligned diff --git a/commands/commands_test.go b/commands/commands_test.go index 3767848c1d5..3fa271d9567 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -206,8 +206,10 @@ func TestUserLibs(t *testing.T) { func TestLibDownloadAndInstall(t *testing.T) { defer makeTempDataDir(t)() defer makeTempSketchbookDir(t)() + var d []byte + var exitCode int - exitCode, d := executeWithArgs(t, "core", "update-index") + exitCode, _ = executeWithArgs(t, "core", "update-index") require.Zero(t, exitCode, "exit code") // Download inexistent diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 5441e29da41..b4e5904eeeb 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -106,7 +106,7 @@ func run(cmd *cobra.Command, args []string) { // Check for ctags tool loadBuiltinCtagsMetadata(pm) - ctags, err := getBuiltinCtagsTool(pm) + ctags, _ := getBuiltinCtagsTool(pm) if !ctags.IsInstalled() { formatter.Print("Downloading and installing missing tool: " + ctags.String()) core.DownloadToolRelease(pm, ctags) @@ -116,7 +116,7 @@ func run(cmd *cobra.Command, args []string) { formatter.PrintError(err, "Could not load hardware packages.") os.Exit(commands.ErrCoreConfig) } - ctags, err = getBuiltinCtagsTool(pm) + ctags, _ = getBuiltinCtagsTool(pm) if !ctags.IsInstalled() { formatter.PrintErrorMessage("Missing ctags tool.") os.Exit(commands.ErrCoreConfig) From 402648322a25f7382f98b5c044652b559432b8cd Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:31:50 +0200 Subject: [PATCH 08/18] Fixed all the problem reported by interfacer (replace with the interface when is possible) These warnings were suppressed by putting the type in the name of the method --- .golangci.yml | 1 - arduino/cores/cores.go | 7 ++++--- arduino/cores/packagemanager/download.go | 2 +- arduino/cores/packagemanager/package_manager.go | 2 +- arduino/cores/tools.go | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d20e59f8024..32c4e720df5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,6 @@ linters: - goconst - gocyclo - govet - - interfacer - lll - maligned - megacheck diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index ae8bbc4e5fc..8a0341548ef 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -111,9 +111,10 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) (*Platform return release, nil } -// GetRelease returns the specified release corresponding the provided version, +// GetReleaseRelaxedVersion returns the specified release corresponding the provided version, // or nil if not found. -func (platform *Platform) GetRelease(version *semver.Version) *PlatformRelease { +func (platform *Platform) GetReleaseVersion(version *semver.Version) *PlatformRelease { + // use as an fmt.Stringer return platform.Releases[version.String()] } @@ -124,7 +125,7 @@ func (platform *Platform) GetLatestRelease() *PlatformRelease { if latestVersion == nil { return nil } - return platform.GetRelease(latestVersion) + return platform.GetReleaseVersion(latestVersion) } // GetAllReleasesVersions returns all the version numbers in this Platform Package. diff --git a/arduino/cores/packagemanager/download.go b/arduino/cores/packagemanager/download.go index 42db32b8aeb..0381cdd004f 100644 --- a/arduino/cores/packagemanager/download.go +++ b/arduino/cores/packagemanager/download.go @@ -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.GetReleaseVersion(item.PlatformVersion) if release == nil { return nil, nil, fmt.Errorf("required version %s not found for platform %s", item.PlatformVersion, platform.String()) } diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 963d97acc8d..0addeb6e547 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -288,7 +288,7 @@ func (ta *ToolActions) Release(version *semver.RelaxedVersion) *ToolReleaseActio if ta.forwardError != nil { return &ToolReleaseActions{forwardError: ta.forwardError} } - release := ta.tool.GetRelease(version) + release := ta.tool.GetReleaseRelaxedVersion(version) if release == nil { return &ToolReleaseActions{forwardError: fmt.Errorf("release %s not found for tool %s", version, ta.tool.String())} } diff --git a/arduino/cores/tools.go b/arduino/cores/tools.go index d4349dfce10..dbc78fe7d55 100644 --- a/arduino/cores/tools.go +++ b/arduino/cores/tools.go @@ -62,9 +62,9 @@ func (tool *Tool) GetOrCreateRelease(version *semver.RelaxedVersion) *ToolReleas return release } -// GetRelease returns the specified release corresponding the provided version, +// GetReleaseRelaxedVersion returns the specified release corresponding the provided version, // or nil if not found. -func (tool *Tool) GetRelease(version *semver.RelaxedVersion) *ToolRelease { +func (tool *Tool) GetReleaseRelaxedVersion(version *semver.RelaxedVersion) *ToolRelease { return tool.Releases[version.String()] } @@ -86,7 +86,7 @@ func (tool *Tool) LatestRelease() *ToolRelease { return nil } - return tool.GetRelease(latest) + return tool.GetReleaseRelaxedVersion(latest) } // latestReleaseVersion obtains latest version number. From c39c49805970165fae7427bbcb037fc4bffcca8d Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:35:59 +0200 Subject: [PATCH 09/18] Fixed all the problem reported by varcheck (unused variables) --- .golangci.yml | 2 -- commands/config/dump.go | 9 +++++---- commands/lib/uninstall.go | 9 +++++---- common/formatter/formatter.go | 2 -- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 32c4e720df5..cd8794b32bb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,6 +28,4 @@ linters: - lll - maligned - megacheck - - prealloc - unparam - - varcheck diff --git a/commands/config/dump.go b/commands/config/dump.go index ed0253abbb8..1fe51c4a2c5 100644 --- a/commands/config/dump.go +++ b/commands/config/dump.go @@ -38,10 +38,11 @@ func initDumpCommand() *cobra.Command { } } -var dumpFlags struct { - _default bool // If false, ask questions to the user about setting configuration properties, otherwise use default configuration. - location string // The custom location of the file to create. -} +// This struct is unused +//var dumpFlags struct { +// _default bool // If false, ask questions to the user about setting configuration properties, otherwise use default configuration. +// location string // The custom location of the file to create. +//} func runDumpCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino config dump`") diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index d71bab9eade..f169ad62640 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -27,10 +27,11 @@ import ( "github.com/spf13/cobra" ) -const ( - versionAll string = "all" - versionLatest string = "latest" -) +// These const are unused +//const ( +// versionAll string = "all" +// versionLatest string = "latest" +//) func initUninstallCommand() *cobra.Command { uninstallCommand := &cobra.Command{ diff --git a/common/formatter/formatter.go b/common/formatter/formatter.go index 0561dab2fed..4eefd5f5a39 100644 --- a/common/formatter/formatter.go +++ b/common/formatter/formatter.go @@ -42,8 +42,6 @@ var defaultFormatter Formatter var logger *logrus.Logger -var debug bool - func init() { formatters = make(map[string]Formatter, 2) AddCustomFormatter("text", &TextFormatter{}) From 52abbe6faf3deb33a041d252560a604bd70a077b Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 14:51:34 +0200 Subject: [PATCH 10/18] Fixed all the problem reported by lll (max line length set to 160) --- .golangci.yml | 3 +- arduino/cores/fqbn_test.go | 4 ++- auth/auth.go | 6 ++-- builder_client_helpers/compilations.go | 5 ++- builder_client_helpers/libraries.go | 11 ++++-- builder_client_helpers/media_types.go | 40 ++++++++++++++++------ builder_client_helpers/pinned_libraries.go | 3 +- builder_client_helpers/user_types.go | 26 ++++++++++---- commands/board/attach.go | 6 ++-- commands/board/list.go | 3 +- commands/compile/compile.go | 35 +++++++++++++------ commands/config/init.go | 10 ++++-- commands/sketch/sync.go | 9 +++-- create_client_helpers/media_types.go | 8 +++-- 14 files changed, 123 insertions(+), 46 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index cd8794b32bb..df3907ee38f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,6 +12,8 @@ linters-settings: goconst: min-len: 2 min-occurrences: 2 + lll: + line-length: 160 misspell: locale: US @@ -25,7 +27,6 @@ linters: - goconst - gocyclo - govet - - lll - maligned - megacheck - unparam diff --git a/arduino/cores/fqbn_test.go b/arduino/cores/fqbn_test.go index 1a77368cce2..1f998e690b5 100644 --- a/arduino/cores/fqbn_test.go +++ b/arduino/cores/fqbn_test.go @@ -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()) } diff --git a/auth/auth.go b/auth/auth.go index f40b0ade569..83b775d0ac4 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -54,7 +54,8 @@ type Config struct { // ClientID is the client id you are using ClientID string - // RedirectURI is the redirectURI where the oauth process will redirect. It's only required since the oauth system checks for it, but we intercept the redirect before hitting it + // RedirectURI is the redirectURI where the oauth process will redirect. + // It's only required since the oauth system checks for it, but we intercept the redirect before hitting it RedirectURI string // Scopes is a space-separated list of scopes to require @@ -157,7 +158,8 @@ func (c *Config) Refresh(token string) (*Token, error) { // cookies keeps track of the cookies for each request type cookies map[string][]*http.Cookie -// requestAuth calls hydra and follows the redirects until it reaches the authentication page. It saves the cookie it finds so it can apply them to subsequent requests +// requestAuth calls hydra and follows the redirects until it reaches the authentication page. +// It saves the cookie it finds so it can apply them to subsequent requests func (c *Config) requestAuth(client *http.Client) (string, cookies, error) { uri, err := url.Parse(c.CodeURL) if err != nil { diff --git a/builder_client_helpers/compilations.go b/builder_client_helpers/compilations.go index 0a1e57396b4..3f025786160 100644 --- a/builder_client_helpers/compilations.go +++ b/builder_client_helpers/compilations.go @@ -30,7 +30,10 @@ func StartCompilationsPath() string { return fmt.Sprintf("/builder/v1/compile") } -// Start a compilation for the given user and saves the request (but not the generated files) on the database. requires authentication. Can return PreconditionFailed if the user has reached their maximum number of compilations per day. If the compilation failed it returns UnprocessableEntity +// Start a compilation for the given user and saves the request (but not the generated files) on the database. +// requires authentication. +// Can return PreconditionFailed if the user has reached their maximum number of compilations per day. +// If the compilation failed it returns UnprocessableEntity func (c *Client) StartCompilations(ctx context.Context, path string, payload *Compilation) (*http.Response, error) { req, err := c.NewStartCompilationsRequest(ctx, path, payload) if err != nil { diff --git a/builder_client_helpers/libraries.go b/builder_client_helpers/libraries.go index edf86c5485a..3d902eabe78 100644 --- a/builder_client_helpers/libraries.go +++ b/builder_client_helpers/libraries.go @@ -29,8 +29,12 @@ func ListLibrariesPath() string { return fmt.Sprintf("/builder/v1/libraries") } -// ListLibraries provides a list of all the latest versions of the libraries supported by Arduino Create. Doesn't require any authentication. -func (c *Client) ListLibraries(ctx context.Context, path string, maintainer *string, type1 *string, withoutType *string) (*http.Response, error) { +// ListLibraries provides a list of all the latest versions of the libraries supported by Arduino Create. +// Doesn't require any authentication. +func (c *Client) ListLibraries( + ctx context.Context, + path string, maintainer *string, type1 *string, withoutType *string) (*http.Response, error) { + req, err := c.NewListLibrariesRequest(ctx, path, maintainer, type1, withoutType) if err != nil { return nil, err @@ -68,7 +72,8 @@ func ShowLibrariesPath(id string) string { return fmt.Sprintf("/builder/v1/libraries/%s", id) } -// ShowLibraries provides the library identified by the :id and :pid param. Doesn't require authentication. Also contains a list of other versions of the library +// ShowLibraries provides the library identified by the :id and :pid param. Doesn't require authentication. +// Also contains a list of other versions of the library func (c *Client) ShowLibraries(ctx context.Context, path string) (*http.Response, error) { req, err := c.NewShowLibrariesRequest(ctx, path) if err != nil { diff --git a/builder_client_helpers/media_types.go b/builder_client_helpers/media_types.go index a310e8abdfa..d1d170919c9 100644 --- a/builder_client_helpers/media_types.go +++ b/builder_client_helpers/media_types.go @@ -24,7 +24,11 @@ import ( "github.com/goadesign/goa" ) -// ArduinoBuilderBoard is a physical board belonging to a certain architecture in a package. The most obvious package is arduino, which contains architectures avr, sam and samd. It can contain multiple versions of the upload commands and options. If there is a default version it means that it's the only version officially supported. Of course if there is only one version it will be called default (default view) +// ArduinoBuilderBoard is a physical board belonging to a certain architecture in a package. +// The most obvious package is arduino, which contains architectures avr, sam and samd. +// It can contain multiple versions of the upload commands and options. +// If there is a default version it means that it's the only version officially supported. +// Of course if there is only one version it will be called default (default view) // // Identifier: application/vnd.arduino.builder.board+json; view=default type ArduinoBuilderBoard struct { @@ -160,7 +164,11 @@ func (c *Client) DecodeArduinoBuilderBoardsv2(resp *http.Response) (*ArduinoBuil return &decoded, err } -// ArduinoBuilderBoardv2 is a physical board belonging to a certain architecture in a package. The most obvious package is arduino, which contains architectures avr, sam and samd. It can contain multiple versions of the upload commands and options. If there is a default version it means that it's the only version officially supported. Of course if there is only one version it will be called default (default view) +// ArduinoBuilderBoardv2 is a physical board belonging to a certain architecture in a package. +// The most obvious package is arduino, which contains architectures avr, sam and samd. +// It can contain multiple versions of the upload commands and options. +// If there is a default version it means that it's the only version officially supported. +// Of course if there is only one version it will be called default (default view) // // Identifier: application/vnd.arduino.builder.boardv2+json; view=default type ArduinoBuilderBoardv2 struct { @@ -177,7 +185,11 @@ type ArduinoBuilderBoardv2 struct { Name *string `form:"name,omitempty" json:"name,omitempty" xml:"name,omitempty"` } -// ArduinoBuilderBoardv2Full is a physical board belonging to a certain architecture in a package. The most obvious package is arduino, which contains architectures avr, sam and samd. It can contain multiple versions of the upload commands and options. If there is a default version it means that it's the only version officially supported. Of course if there is only one version it will be called default (full view) +// ArduinoBuilderBoardv2Full is a physical board belonging to a certain architecture in a package. +// The most obvious package is arduino, which contains architectures avr, sam and samd. +// It can contain multiple versions of the upload commands and options. +// If there is a default version it means that it's the only version officially supported. +// Of course if there is only one version it will be called default (full view) // // Identifier: application/vnd.arduino.builder.boardv2+json; view=full type ArduinoBuilderBoardv2Full struct { @@ -343,7 +355,9 @@ func (c *Client) DecodeArduinoBuilderBoardv2FullCollection(resp *http.Response) return decoded, err } -// ArduinoBuilderCompilationResult is the result of a compilation. It contains the output and the eventual errors. If successful it contains the generated files. (default view) +// ArduinoBuilderCompilationResult is the result of a compilation. +// It contains the output and the eventual errors. +// If successful it contains the generated files. (default view) // // Identifier: application/vnd.arduino.builder.compilation.result; view=default type ArduinoBuilderCompilationResult struct { @@ -388,8 +402,8 @@ type ArduinoBuilderExample struct { Types []string `form:"types,omitempty" json:"types,omitempty" xml:"types,omitempty"` } -// An ArduinoBuilderExampleLink is a simple sketch with the purpose of demonstrating the capabilities of the language. (link view) -// +// An ArduinoBuilderExampleLink is a simple sketch with the purpose of demonstrating the capabilities of the language. +// (link view) // Identifier: application/vnd.arduino.builder.example+json; view=link type ArduinoBuilderExampleLink struct { // The url where to find the details @@ -471,7 +485,9 @@ func (c *Client) DecodeArduinoBuilderFileCollection(resp *http.Response) (Arduin return decoded, err } -// ArduinoBuilderLibrary is a collection of header files containing arduino reusable code and functions. It typically contains its info in a library.properties files. The examples property contains a list of examples that use that library. (default view) +// ArduinoBuilderLibrary is a collection of header files containing arduino reusable code and functions. +// It typically contains its info in a library.properties files. +// The examples property contains a list of examples that use that library. (default view) // // Identifier: application/vnd.arduino.builder.library+json; view=default type ArduinoBuilderLibrary struct { @@ -489,7 +505,8 @@ type ArduinoBuilderLibrary struct { Files []*ArduinoBuilderFile `form:"files,omitempty" json:"files,omitempty" xml:"files,omitempty"` // The url where to find the details Href *string `form:"href,omitempty" json:"href,omitempty" xml:"href,omitempty"` - // The id of the library. It could be a combination of name and version, a combination of the package and architecture, or an uuid id + // The id of the library. + // It could be a combination of name and version, a combination of the package and architecture, or an uuid id ID *string `form:"id,omitempty" json:"id,omitempty" xml:"id,omitempty"` // The maintainer of the library Maintainer *string `form:"maintainer,omitempty" json:"maintainer,omitempty" xml:"maintainer,omitempty"` @@ -507,7 +524,9 @@ type ArduinoBuilderLibrary struct { Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` } -// ArduinoBuilderLibraryLink is a collection of header files containing arduino reusable code and functions. It typically contains its info in a library.properties files. The examples property contains a list of examples that use that library. (link view) +// ArduinoBuilderLibraryLink is a collection of header files containing arduino reusable code and functions. +// It typically contains its info in a library.properties files. +// The examples property contains a list of examples that use that library. (link view) // // Identifier: application/vnd.arduino.builder.library+json; view=link type ArduinoBuilderLibraryLink struct { @@ -542,7 +561,8 @@ type ArduinoBuilderSlimlibrary struct { // The number of examples that it contains ExamplesNumber *int `form:"examples_number,omitempty" json:"examples_number,omitempty" xml:"examples_number,omitempty"` Href *string `form:"href,omitempty" json:"href,omitempty" xml:"href,omitempty"` - // The id of the library. It could be a combination of name and version, a combination of the package and architecture, or an uuid id + // The id of the library. + // It could be a combination of name and version, a combination of the package and architecture, or an uuid id ID *string `form:"id,omitempty" json:"id,omitempty" xml:"id,omitempty"` // The maintainer of the library Maintainer *string `form:"maintainer,omitempty" json:"maintainer,omitempty" xml:"maintainer,omitempty"` diff --git a/builder_client_helpers/pinned_libraries.go b/builder_client_helpers/pinned_libraries.go index 99a5a031241..37ba77a0374 100644 --- a/builder_client_helpers/pinned_libraries.go +++ b/builder_client_helpers/pinned_libraries.go @@ -40,7 +40,8 @@ func (c *Client) AddPinnedLibraries(ctx context.Context, path string) (*http.Res return c.Client.Do(ctx, req) } -// NewAddPinnedLibrariesRequest create the request corresponding to the add action endpoint of the pinnedLibraries resource. +// NewAddPinnedLibrariesRequest create the request +// corresponding to the add action endpoint of the pinnedLibraries resource. func (c *Client) NewAddPinnedLibrariesRequest(ctx context.Context, path string) (*http.Request, error) { scheme := c.Scheme if scheme == "" { diff --git a/builder_client_helpers/user_types.go b/builder_client_helpers/user_types.go index 89b99fff571..b4bb9440c7d 100644 --- a/builder_client_helpers/user_types.go +++ b/builder_client_helpers/user_types.go @@ -21,7 +21,9 @@ import ( "github.com/goadesign/goa" ) -// A compilation is made up of a sketch (or a path to a sketch) and an fqbn. Eventual libraries are automatically determined and linked. NOTE: swagger will force you to define the files inside the sketch because of a bug. But they are not mandatory. +// A compilation is made up of a sketch (or a path to a sketch) and an fqbn. +// Eventual libraries are automatically determined and linked. +// NOTE: swagger will force you to define the files inside the sketch because of a bug. But they are not mandatory. type compilation struct { // The fully qualified board name Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"` @@ -72,7 +74,9 @@ func (ut *compilation) Publicize() *Compilation { return &pub } -// A Compilation is made up of a sketch (or a path to a sketch) and an fqbn. Eventual libraries are automatically determined and linked. NOTE: swagger will force you to define the files inside the sketch because of a bug. But they are not mandatory. +// A Compilation is made up of a sketch (or a path to a sketch) and an fqbn. +// Eventual libraries are automatically determined and linked. +// NOTE: swagger will force you to define the files inside the sketch because of a bug. But they are not mandatory. type Compilation struct { // The fully qualified board name Fqbn string `form:"fqbn" json:"fqbn" xml:"fqbn"` @@ -275,7 +279,8 @@ func (ut *filemeta) Publicize() *Filemeta { return &pub } -// FileMeta represent a file in the filesystem, belonging to a sketch, a library or an example. Can contain a data property with the content of the file. +// FileMeta represent a file in the filesystem, belonging to a sketch, a library or an example. +// Can contain a data property with the content of the file. type Filemeta struct { // The contents of the file, in base64 Data *string `form:"data,omitempty" json:"data,omitempty" xml:"data,omitempty"` @@ -291,7 +296,9 @@ func (ut *Filemeta) Validate() (err error) { return } -// Library is a collection of header files containing arduino reusable code and functions. It typically contains its info in a library.properties files. The examples property contains a list of examples that use that library. +// Library is a collection of header files containing arduino reusable code and functions. +// It typically contains its info in a library.properties files. +// The examples property contains a list of examples that use that library. type library struct { // The architectures supported by the library. Architectures []string `form:"architectures,omitempty" json:"architectures,omitempty" xml:"architectures,omitempty"` @@ -391,7 +398,9 @@ func (ut *library) Publicize() *Library { return &pub } -// Library is a collection of header files containing arduino reusable code and functions. It typically contains its info in a library.properties files. The examples property contains a list of examples that use that library. +// Library is a collection of header files containing arduino reusable code and functions. +// It typically contains its info in a library.properties files. +// The examples property contains a list of examples that use that library. type Library struct { // The architectures supported by the library. Architectures []string `form:"architectures,omitempty" json:"architectures,omitempty" xml:"architectures,omitempty"` @@ -468,7 +477,9 @@ type PinnedLib struct { Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` } -// A sketch is a program intended to run on an arduino board. It's composed by a main .ino file and optional other files. You should upload only .ino and .h files. +// A sketch is a program intended to run on an arduino board. +// It's composed by a main .ino file and optional other files. +// You should upload only .ino and .h files. type sketch struct { // Other files contained in the example Files []*filefull `form:"files,omitempty" json:"files,omitempty" xml:"files,omitempty"` @@ -527,7 +538,8 @@ func (ut *sketch) Publicize() *Sketch { return &pub } -// A sketch is a program intended to run on an arduino board. It's composed by a main .ino file and optional other files. You should upload only .ino and .h files. +// A sketch is a program intended to run on an arduino board. +// It's composed by a main .ino file and optional other files. You should upload only .ino and .h files. type Sketch struct { // Other files contained in the example Files []*Filefull `form:"files,omitempty" json:"files,omitempty" xml:"files,omitempty"` diff --git a/commands/board/attach.go b/commands/board/attach.go index c9bdef8da4b..29142061728 100644 --- a/commands/board/attach.go +++ b/commands/board/attach.go @@ -46,8 +46,10 @@ func initAttachCommand() *cobra.Command { Args: cobra.RangeArgs(1, 2), Run: runAttachCommand, } - attachCommand.Flags().StringVar(&attachFlags.boardFlavour, "flavour", "default", "The Name of the CPU flavour, it is required for some boards (e.g. Arduino Nano).") - attachCommand.Flags().StringVar(&attachFlags.searchTimeout, "timeout", "5s", "The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s).") + attachCommand.Flags().StringVar(&attachFlags.boardFlavour, "flavour", "default", + "The Name of the CPU flavour, it is required for some boards (e.g. Arduino Nano).") + attachCommand.Flags().StringVar(&attachFlags.searchTimeout, "timeout", "5s", + "The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s).") return attachCommand } diff --git a/commands/board/list.go b/commands/board/list.go index 0e40274550c..f46421891f2 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -39,7 +39,8 @@ func initListCommand() *cobra.Command { Args: cobra.NoArgs, Run: runListCommand, } - listCommand.Flags().StringVar(&listFlags.timeout, "timeout", "5s", "The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s).") + usage := "The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s)." + listCommand.Flags().StringVar(&listFlags.timeout, "timeout", "5s", usage) return listCommand } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index b4e5904eeeb..2b5ee391dc4 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -48,16 +48,26 @@ func InitCommand() *cobra.Command { Args: cobra.MaximumNArgs(1), Run: run, } - command.Flags().StringVarP(&flags.fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno") - command.Flags().BoolVar(&flags.showProperties, "show-properties", false, "Show all build properties used instead of compiling.") - command.Flags().BoolVar(&flags.preprocess, "preprocess", false, "Print preprocessed code to stdout instead of compiling.") - command.Flags().StringVar(&flags.buildCachePath, "build-cache-path", "", "Builds of 'core.a' are saved into this path to be cached and reused.") - command.Flags().StringVar(&flags.buildPath, "build-path", "", "Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.") - command.Flags().StringSliceVar(&flags.buildProperties, "build-properties", []string{}, "List of custom build properties separated by commas. Or can be used multiple times for multiple properties.") - command.Flags().StringVar(&flags.warnings, "warnings", "none", `Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).`) - command.Flags().BoolVarP(&flags.verbose, "verbose", "v", false, "Optional, turns on verbose mode.") - command.Flags().BoolVar(&flags.quiet, "quiet", false, "Optional, supresses almost every output.") - command.Flags().StringVar(&flags.vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.") + command.Flags().StringVarP(&flags.fqbn, "fqbn", "b", "", + "Fully Qualified Board Name, e.g.: arduino:avr:uno") + command.Flags().BoolVar(&flags.showProperties, "show-properties", false, + "Show all build properties used instead of compiling.") + command.Flags().BoolVar(&flags.preprocess, "preprocess", false, + "Print preprocessed code to stdout instead of compiling.") + command.Flags().StringVar(&flags.buildCachePath, "build-cache-path", "", + "Builds of 'core.a' are saved into this path to be cached and reused.") + command.Flags().StringVar(&flags.buildPath, "build-path", "", + "Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.") + command.Flags().StringSliceVar(&flags.buildProperties, "build-properties", []string{}, + "List of custom build properties separated by commas. Or can be used multiple times for multiple properties.") + command.Flags().StringVar(&flags.warnings, "warnings", "none", + `Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).`) + command.Flags().BoolVarP(&flags.verbose, "verbose", "v", false, + "Optional, turns on verbose mode.") + command.Flags().BoolVar(&flags.quiet, "quiet", false, + "Optional, supresses almost every output.") + command.Flags().StringVar(&flags.vidPid, "vid-pid", "", + "When specified, VID/PID specific build properties are used, if boards supports them.") return command } @@ -128,7 +138,10 @@ func run(cmd *cobra.Command, args []string) { PlatformArchitecture: coreName, }) if targetPlatform == nil || targetPlatform.GetInstalled() == nil { - formatter.PrintErrorMessage(fmt.Sprintf("\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+commands.AppName+" core install %[1]s:%[2]s\".", packageName, coreName)) + errorMessage := fmt.Sprintf( + "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+ + commands.AppName+" core install %[1]s:%[2]s\".", packageName, coreName) + formatter.PrintErrorMessage(errorMessage) os.Exit(commands.ErrCoreConfig) } diff --git a/commands/config/init.go b/commands/config/init.go index e8bd55480fa..ff223781d9c 100644 --- a/commands/config/init.go +++ b/commands/config/init.go @@ -39,8 +39,14 @@ func initInitCommand() *cobra.Command { Args: cobra.NoArgs, Run: runInitCommand, } - initCommand.Flags().BoolVar(&initFlags._default, "default", false, "If omitted, ask questions to the user about setting configuration properties, otherwise use default configuration.") - initCommand.Flags().StringVar(&initFlags.location, "save-as", "", "Sets where to save the configuration file [default is ./.cli-config.yml].") + initCommand.Flags().BoolVar(&initFlags._default, + "default", + false, + "If omitted, ask questions to the user about setting configuration properties, otherwise use default configuration.") + initCommand.Flags().StringVar(&initFlags.location, + "save-as", + "", + "Sets where to save the configuration file [default is ./.cli-config.yml].") return initCommand } diff --git a/commands/sketch/sync.go b/commands/sketch/sync.go index adca7d2c99f..11f399b62af 100644 --- a/commands/sketch/sync.go +++ b/commands/sketch/sync.go @@ -57,7 +57,8 @@ func initSyncCommand() *cobra.Command { Args: cobra.NoArgs, Run: runSyncCommand, } - syncCommand.Flags().StringVar(&syncFlags.priority, "conflict-policy", prioritySkip, "The decision made by default on conflicting sketches. Can be push-local, pull-remote, skip, ask-once, ask-always.") + usage := "The decision made by default on conflicting sketches. Can be push-local, pull-remote, skip, ask-once, ask-always." + syncCommand.Flags().StringVar(&syncFlags.priority, "conflict-policy", prioritySkip, usage) return syncCommand } @@ -296,7 +297,11 @@ func pushSketch(sketch sketches.Sketch, sketchbook *paths.Path, bearerToken stri func editSketch(sketch sketches.Sketch, sketchbook *paths.Path, bearerToken string) error { client := createclient.New(nil) - resp, err := client.EditSketches(context.Background(), createclient.EditSketchesPath(sketch.ID), createclient.ConvertFrom(sketch), "Bearer "+bearerToken) + resp, err := client.EditSketches( + context.Background(), + createclient.EditSketchesPath(sketch.ID), + createclient.ConvertFrom(sketch), + "Bearer "+bearerToken) if err != nil { return err } diff --git a/create_client_helpers/media_types.go b/create_client_helpers/media_types.go index 94fd7d77d58..2084ca0df8b 100644 --- a/create_client_helpers/media_types.go +++ b/create_client_helpers/media_types.go @@ -77,7 +77,9 @@ func (c *Client) DecodeArduinoCreateLibraries(resp *http.Response) (*ArduinoCrea return &decoded, err } -// Library is a collection of header files containing arduino reusable code and functions. It typically contains its info in a library.properties files. The examples property contains a list of examples that use that library. (default view) +// Library is a collection of header files containing arduino reusable code and functions. +// It typically contains its info in a library.properties files. +// The examples property contains a list of examples that use that library. (default view) // // Identifier: application/vnd.arduino.create.library+json; view=default type ArduinoCreateLibrary struct { @@ -115,7 +117,9 @@ type ArduinoCreateLibrary struct { Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` } -// Library is a collection of header files containing arduino reusable code and functions. It typically contains its info in a library.properties files. The examples property contains a list of examples that use that library. (link view) +// Library is a collection of header files containing arduino reusable code and functions. +// It typically contains its info in a library.properties files. +// The examples property contains a list of examples that use that library. (link view) // // Identifier: application/vnd.arduino.create.library+json; view=link type ArduinoCreateLibraryLink struct { From 573f69e1f180425501a04ff59ca864a63b78d0b6 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 15:01:15 +0200 Subject: [PATCH 11/18] =?UTF-8?q?Added=E2=88=82=20golangci-lint=20run=20to?= =?UTF-8?q?=20the=20drone=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index d1523ae25aa..64c422c6703 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,4 +19,5 @@ pipeline: # Build - go build - go test -timeout 20m -v ./... -race + - golangci-lint run secrets: [TEST_USERNAME, TEST_PASSWORD] From 2e5768cf3c00686695f18298a0de08de4b8fbc9d Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 17:38:19 +0200 Subject: [PATCH 12/18] Removed unused code --- commands/config/dump.go | 6 ------ commands/lib/uninstall.go | 6 ------ 2 files changed, 12 deletions(-) diff --git a/commands/config/dump.go b/commands/config/dump.go index 1fe51c4a2c5..2095e3861a0 100644 --- a/commands/config/dump.go +++ b/commands/config/dump.go @@ -38,12 +38,6 @@ func initDumpCommand() *cobra.Command { } } -// This struct is unused -//var dumpFlags struct { -// _default bool // If false, ask questions to the user about setting configuration properties, otherwise use default configuration. -// location string // The custom location of the file to create. -//} - func runDumpCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino config dump`") diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index f169ad62640..060de573f7a 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -27,12 +27,6 @@ import ( "github.com/spf13/cobra" ) -// These const are unused -//const ( -// versionAll string = "all" -// versionLatest string = "latest" -//) - func initUninstallCommand() *cobra.Command { uninstallCommand := &cobra.Command{ Use: "uninstall LIBRARY_NAME(S)", From cd95478c0b9d32722e819974150298c3984c1b2d Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 17:42:11 +0200 Subject: [PATCH 13/18] Removed comments and rename type1 to libType --- builder_client_helpers/examples.go | 10 +++++----- builder_client_helpers/libraries.go | 6 +++--- commands/commands_test.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/builder_client_helpers/examples.go b/builder_client_helpers/examples.go index b825d405a3a..e56a598abf3 100644 --- a/builder_client_helpers/examples.go +++ b/builder_client_helpers/examples.go @@ -30,8 +30,8 @@ func ListExamplesPath() string { } // ListExamples provides a list of all the builtin examples -func (c *Client) ListExamples(ctx context.Context, path string, maintainer *string, type1 *string) (*http.Response, error) { - req, err := c.NewListExamplesRequest(ctx, path, maintainer, type1) +func (c *Client) ListExamples(ctx context.Context, path string, maintainer *string, libType *string) (*http.Response, error) { + req, err := c.NewListExamplesRequest(ctx, path, maintainer, libType) if err != nil { return nil, err } @@ -39,7 +39,7 @@ func (c *Client) ListExamples(ctx context.Context, path string, maintainer *stri } // NewListExamplesRequest create the request corresponding to the list action endpoint of the examples resource. -func (c *Client) NewListExamplesRequest(ctx context.Context, path string, maintainer *string, type1 *string) (*http.Request, error) { +func (c *Client) NewListExamplesRequest(ctx context.Context, path string, maintainer *string, libType *string) (*http.Request, error) { scheme := c.Scheme if scheme == "" { scheme = "http" @@ -49,8 +49,8 @@ func (c *Client) NewListExamplesRequest(ctx context.Context, path string, mainta if maintainer != nil { values.Set("maintainer", *maintainer) } - if type1 != nil { - values.Set("type", *type1) + if libType != nil { + values.Set("type", *libType) } u.RawQuery = values.Encode() req, err := http.NewRequest("GET", u.String(), nil) diff --git a/builder_client_helpers/libraries.go b/builder_client_helpers/libraries.go index 3d902eabe78..73a0539c954 100644 --- a/builder_client_helpers/libraries.go +++ b/builder_client_helpers/libraries.go @@ -43,7 +43,7 @@ func (c *Client) ListLibraries( } // NewListLibrariesRequest create the request corresponding to the list action endpoint of the libraries resource. -func (c *Client) NewListLibrariesRequest(ctx context.Context, path string, maintainer *string, type1 *string, withoutType *string) (*http.Request, error) { +func (c *Client) NewListLibrariesRequest(ctx context.Context, path string, maintainer *string, libType *string, withoutType *string) (*http.Request, error) { scheme := c.Scheme if scheme == "" { scheme = "http" @@ -53,8 +53,8 @@ func (c *Client) NewListLibrariesRequest(ctx context.Context, path string, maint if maintainer != nil { values.Set("maintainer", *maintainer) } - if type1 != nil { - values.Set("type", *type1) + if libType != nil { + values.Set("type", *libType) } if withoutType != nil { values.Set("without_type", *withoutType) diff --git a/commands/commands_test.go b/commands/commands_test.go index 3fa271d9567..7e6d989b17b 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -35,7 +35,7 @@ import ( // Redirecting stdOut so we can analyze output line by // line and check with what we want. -var stdOut = os.Stdout // *os.File +var stdOut = os.Stdout type stdOutRedirect struct { tempFile *os.File From 737a9fcf69b6a7c2388761eb9c95f9e0f23a859b Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 17:46:20 +0200 Subject: [PATCH 14/18] Apply style 2 in the flags (a line break before the description) https://github.com/arduino/arduino-cli/pull/24#discussion_r213709753 --- commands/board/list.go | 5 +++-- commands/config/init.go | 8 ++------ commands/upload/upload.go | 12 ++++++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/commands/board/list.go b/commands/board/list.go index f46421891f2..8d604153a18 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -39,8 +39,9 @@ func initListCommand() *cobra.Command { Args: cobra.NoArgs, Run: runListCommand, } - usage := "The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s)." - listCommand.Flags().StringVar(&listFlags.timeout, "timeout", "5s", usage) + + listCommand.Flags().StringVar(&listFlags.timeout, "timeout", "5s", + "The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s).") return listCommand } diff --git a/commands/config/init.go b/commands/config/init.go index ff223781d9c..1b1774fcb67 100644 --- a/commands/config/init.go +++ b/commands/config/init.go @@ -39,13 +39,9 @@ func initInitCommand() *cobra.Command { Args: cobra.NoArgs, Run: runInitCommand, } - initCommand.Flags().BoolVar(&initFlags._default, - "default", - false, + initCommand.Flags().BoolVar(&initFlags._default, "default", false, "If omitted, ask questions to the user about setting configuration properties, otherwise use default configuration.") - initCommand.Flags().StringVar(&initFlags.location, - "save-as", - "", + initCommand.Flags().StringVar(&initFlags.location, "save-as", "", "Sets where to save the configuration file [default is ./.cli-config.yml].") return initCommand } diff --git a/commands/upload/upload.go b/commands/upload/upload.go index ca122925681..4c7fa1a96ee 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -45,10 +45,14 @@ func InitCommand() *cobra.Command { Args: cobra.MaximumNArgs(1), Run: run, } - uploadCommand.Flags().StringVarP(&flags.fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno") - uploadCommand.Flags().StringVarP(&flags.port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0") - uploadCommand.Flags().BoolVarP(&flags.verbose, "verify", "t", false, "Verify uploaded binary after the upload.") - uploadCommand.Flags().BoolVarP(&flags.verbose, "verbose", "v", false, "Optional, turns on verbose mode.") + uploadCommand.Flags().StringVarP(&flags.fqbn, "fqbn", "b", "", + "Fully Qualified Board Name, e.g.: arduino:avr:uno") + uploadCommand.Flags().StringVarP(&flags.port, "port", "p", "", + "Upload port, e.g.: COM10 or /dev/ttyACM0") + uploadCommand.Flags().BoolVarP(&flags.verbose, "verify", "t", false, + "Verify uploaded binary after the upload.") + uploadCommand.Flags().BoolVarP(&flags.verbose, "verbose", "v", false, + "Optional, turns on verbose mode.") return uploadCommand } From 30057cefc97e864849e2e475581ee8a65b303c0a Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Wed, 29 Aug 2018 18:00:47 +0200 Subject: [PATCH 15/18] Removed the name in the return parameters --- commands/commands_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/commands_test.go b/commands/commands_test.go index 7e6d989b17b..876c19ff6a5 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -67,7 +67,9 @@ func (grabber *stdOutRedirect) Close() { // executeWithArgs executes the Cobra Command with the given arguments // and intercepts any errors (even `os.Exit()` ones), returning the exit code -func executeWithArgs(t *testing.T, args ...string) (exitCode int, output []byte) { +func executeWithArgs(t *testing.T, args ...string) (int, []byte) { + var output []byte + var exitCode int fmt.Printf("RUNNING: %s\n", args) redirect := &stdOutRedirect{} From ab16a2b2b2ada57c5fe49779bdd9a6ff7a267851 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Thu, 30 Aug 2018 10:05:00 +0200 Subject: [PATCH 16/18] Convert error to lowercase --- arduino/cores/status.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/cores/status.go b/arduino/cores/status.go index 0bbf7f96fde..af127b9d304 100644 --- a/arduino/cores/status.go +++ b/arduino/cores/status.go @@ -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 } From 939029ef6d64add032c11cd11bfcd5c15347b6e2 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Thu, 30 Aug 2018 11:12:26 +0200 Subject: [PATCH 17/18] Changed name of GetRelease to FindReleaseWith* --- arduino/cores/cores.go | 8 ++++---- arduino/cores/packagemanager/download.go | 2 +- arduino/cores/packagemanager/package_manager.go | 2 +- arduino/cores/tools.go | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index 8a0341548ef..d60aa5fa4f9 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -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" ) @@ -111,9 +111,9 @@ func (platform *Platform) GetOrCreateRelease(version *semver.Version) (*Platform return release, nil } -// GetReleaseRelaxedVersion 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) GetReleaseVersion(version *semver.Version) *PlatformRelease { +func (platform *Platform) FindReleaseWithVersion(version *semver.Version) *PlatformRelease { // use as an fmt.Stringer return platform.Releases[version.String()] } @@ -125,7 +125,7 @@ func (platform *Platform) GetLatestRelease() *PlatformRelease { if latestVersion == nil { return nil } - return platform.GetReleaseVersion(latestVersion) + return platform.FindReleaseWithVersion(latestVersion) } // GetAllReleasesVersions returns all the version numbers in this Platform Package. diff --git a/arduino/cores/packagemanager/download.go b/arduino/cores/packagemanager/download.go index 0381cdd004f..d3da91f3e45 100644 --- a/arduino/cores/packagemanager/download.go +++ b/arduino/cores/packagemanager/download.go @@ -81,7 +81,7 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc var release *cores.PlatformRelease if item.PlatformVersion != nil { - release = platform.GetReleaseVersion(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()) } diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 0addeb6e547..2a44c33ed25 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -288,7 +288,7 @@ func (ta *ToolActions) Release(version *semver.RelaxedVersion) *ToolReleaseActio if ta.forwardError != nil { return &ToolReleaseActions{forwardError: ta.forwardError} } - release := ta.tool.GetReleaseRelaxedVersion(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())} } diff --git a/arduino/cores/tools.go b/arduino/cores/tools.go index dbc78fe7d55..69611fd3d34 100644 --- a/arduino/cores/tools.go +++ b/arduino/cores/tools.go @@ -62,9 +62,9 @@ func (tool *Tool) GetOrCreateRelease(version *semver.RelaxedVersion) *ToolReleas return release } -// GetReleaseRelaxedVersion 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) GetReleaseRelaxedVersion(version *semver.RelaxedVersion) *ToolRelease { +func (tool *Tool) FindReleaseWithRelaxedVersion(version *semver.RelaxedVersion) *ToolRelease { return tool.Releases[version.String()] } @@ -86,7 +86,7 @@ func (tool *Tool) LatestRelease() *ToolRelease { return nil } - return tool.GetReleaseRelaxedVersion(latest) + return tool.FindReleaseWithRelaxedVersion(latest) } // latestReleaseVersion obtains latest version number. From 35cb251156ed5305eb01013edd0ec2e33af58e96 Mon Sep 17 00:00:00 2001 From: Mattia Bertorello Date: Thu, 30 Aug 2018 12:33:12 +0200 Subject: [PATCH 18/18] Use a closure to avoid the defer called after the executeWithArgs method --- commands/commands_test.go | 62 ++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/commands/commands_test.go b/commands/commands_test.go index 876c19ff6a5..6862cfa4d2e 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -71,38 +71,40 @@ func executeWithArgs(t *testing.T, args ...string) (int, []byte) { var output []byte var exitCode int fmt.Printf("RUNNING: %s\n", args) - - redirect := &stdOutRedirect{} - redirect.Open(t) - defer func() { - output = redirect.GetOutput() - redirect.Close() - fmt.Print(string(output)) - fmt.Println() - }() - - // Mock the os.Exit function, so that we can use the - // error result for the test and prevent the test from exiting - fakeExitFired := false - fakeExit := func(code int) { - exitCode = code - fakeExitFired = true - - // use panic to exit and jump to deferred recover - panic(fmt.Errorf("os.Exit(%d)", code)) - } - patch := monkey.Patch(os.Exit, fakeExit) - defer patch.Unpatch() - defer func() { - if fakeExitFired { - recover() + // This closure is here because we won'that the defer are execute at the end of the "executeWithArgs" method + func() { + redirect := &stdOutRedirect{} + redirect.Open(t) + defer func() { + output = redirect.GetOutput() + redirect.Close() + fmt.Print(string(output)) + fmt.Println() + }() + + // Mock the os.Exit function, so that we can use the + // error result for the test and prevent the test from exiting + fakeExitFired := false + fakeExit := func(code int) { + exitCode = code + fakeExitFired = true + + // use panic to exit and jump to deferred recover + panic(fmt.Errorf("os.Exit(%d)", code)) } - }() + patch := monkey.Patch(os.Exit, fakeExit) + defer patch.Unpatch() + defer func() { + if fakeExitFired { + recover() + } + }() - // Execute the CLI command, in this process - cmd := root.Init() - cmd.SetArgs(args) - cmd.Execute() + // Execute the CLI command, in this process + cmd := root.Init() + cmd.SetArgs(args) + cmd.Execute() + }() return exitCode, output }