Skip to content

Commit

Permalink
Merge pull request #960 from Scalingo/fix/linter_offenses
Browse files Browse the repository at this point in the history
refactor: various linter offenses
  • Loading branch information
EtienneM authored Jun 1, 2023
2 parents 15f9b41 + af7fbb7 commit 71ae5be
Show file tree
Hide file tree
Showing 66 changed files with 63,768 additions and 39 deletions.
5 changes: 3 additions & 2 deletions apps/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func Run(ctx context.Context, opts RunOpts) error {
if err != nil {
return errgo.Mask(err, errgo.Any)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return errgo.Newf("Fail to attach: %s", res.Status)
}
Expand Down Expand Up @@ -264,7 +265,7 @@ func (runCtx *runContext) buildEnv(cmdEnv []string) (map[string]string, error) {

for _, cmdVar := range cmdEnv {
v := strings.SplitN(cmdVar, "=", 2)
if len(v) != 2 || len(v[0]) == 0 || len(v[1]) == 0 {
if len(v) != 2 || v[0] == "" || v[1] == "" {
return nil, fmt.Errorf("Invalid environment, format is '--env VARIABLE=value'")
}
env[v[0]] = v[1]
Expand Down Expand Up @@ -357,7 +358,7 @@ func (runCtx *runContext) connectToRunServer(ctx context.Context) (*http.Respons
} else if url.Scheme == "http" {
conn = httputil.NewClientConn(dial, nil)
} else {
return nil, nil, errgo.Newf("Invalid scheme format %s", url.Scheme)
return nil, nil, errgo.Newf("invalid scheme format %s", url.Scheme)
}

res, err := conn.Do(req)
Expand Down
2 changes: 1 addition & 1 deletion cmd/autocomplete/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func appsAutoCompleteCache() ([]*scalingo.App, error) {
return nil, errgo.Mask(err)
}

if time.Now().Sub(cache.CreatedAt).Seconds() > appsCacheDuration {
if time.Since(cache.CreatedAt).Seconds() > appsCacheDuration {
return nil, errExpiredCache
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/autocomplete/collaborators_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func CollaboratorsAddAutoComplete(c *cli.Context) error {
return nil
}

var apiError error = nil
var apiError error
ch := make(chan string)
var wg sync.WaitGroup
wg.Add(len(apps))
Expand Down
2 changes: 1 addition & 1 deletion cmd/autocomplete/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ScaleAutoComplete(c *cli.Context) error {
return errgo.Mask(err)
}
for _, ct := range processes {
fmt.Println(fmt.Sprintf("%s:%d:%s", ct.Name, ct.Amount, ct.Size))
fmt.Printf("%s:%d:%s\n", ct.Name, ct.Amount, ct.Size)
}

return nil
Expand Down
12 changes: 7 additions & 5 deletions cmd/stats.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/urfave/cli/v2"
cli "github.com/urfave/cli/v2"

"github.com/Scalingo/cli/apps"
"github.com/Scalingo/cli/detect"
Expand All @@ -25,13 +25,15 @@ var (
currentApp := detect.CurrentApp(c)
if c.Args().Len() != 0 {
cli.ShowCommandHelp(c, "stats")
} else if err := apps.Stats(c.Context, currentApp, c.Bool("stream")); err != nil {
return nil
}

err := apps.Stats(c.Context, currentApp, c.Bool("stream"))
if err != nil {
errorQuit(err)
}
return nil
},
BashComplete: func(c *cli.Context) {
return
},
BashComplete: func(c *cli.Context) {},
}
)
6 changes: 3 additions & 3 deletions collaborators/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"

"gopkg.in/errgo.v1"
errgo "gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
Expand All @@ -26,9 +26,9 @@ func Remove(ctx context.Context, app, email string) error {
if err == notFound {
io.Error(email + " is not a collaborator of " + app + ".")
return nil
} else {
return errgo.Mask(err, errgo.Any)
}

return errgo.Mask(err, errgo.Any)
}
err = client.CollaboratorRemove(ctx, app, collaborator.ID)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ func (a *CliAuthenticator) RemoveAuth() error {
if err != nil {
return errgo.Notef(err, "fail to get authentication service host")
}
if _, ok := c[authHost]; ok {
delete(c, authHost)
}

delete(c, authHost)

buffer, err := json.Marshal(&c)
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions dists/download_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package main
import (
"encoding/json"
"fmt"
"log"
"net/http"

"github.com/Scalingo/go-utils/logger"
)

type Asset struct {
Expand All @@ -20,15 +21,20 @@ type Repo struct {
type Repos []Repo

func main() {
log := logger.Default()

res, err := http.Get("https://api.github.com/repos/Scalingo/cli/releases")
if err != nil {
log.Fatalln(err)
log.WithError(err).Error("Fail to query the CLI releases from GitHub")
return
}
defer res.Body.Close()

var repos Repos
err = json.NewDecoder(res.Body).Decode(&repos)
if err != nil {
log.Fatalln(err)
log.WithError(err).Error("")
return
}

for _, repo := range repos {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/urfave/cli/v2 v2.24.2
golang.org/x/crypto v0.9.0
golang.org/x/term v0.8.0
golang.org/x/text v0.9.0
gopkg.in/errgo.v1 v1.0.1
)

Expand Down Expand Up @@ -65,7 +66,6 @@ require (
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.2 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
5 changes: 2 additions & 3 deletions logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"fmt"
stdio "io"
"net/http"
"net/url"
"os"
Expand All @@ -14,8 +15,6 @@ import (
"time"
"unicode"

stdio "io"

"github.com/fatih/color"
"github.com/gorilla/websocket"
errgo "gopkg.in/errgo.v1"
Expand Down Expand Up @@ -76,7 +75,7 @@ func Dump(ctx context.Context, logsURL string, n int, filter string) error {
go func() {
defer wg.Done()
for bline := range buff {
colorizeLogs(string(bline))
colorizeLogs(bline)
}
}()

Expand Down
4 changes: 2 additions & 2 deletions notifiers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func collaboratorUserIDs(ctx context.Context, c *scalingo.Client, app string, us
}
if id == "" {
return nil, errgo.Newf("no such collaborator: %v", u)
} else {
ids = append(ids, id)
}

ids = append(ids, id)
}

return ids, nil
Expand Down
18 changes: 10 additions & 8 deletions notifiers/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/olekukonko/tablewriter"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
Expand Down Expand Up @@ -38,22 +39,23 @@ func displayDetails(notifier scalingo.DetailedNotifier, types []scalingo.EventTy
t := tablewriter.NewWriter(os.Stdout)
// Basic data
data := [][]string{
[]string{"ID", notifier.GetID()},
[]string{"Type", string(notifier.GetType())},
[]string{"Name", notifier.GetName()},
[]string{"Enabled", strconv.FormatBool(notifier.IsActive())},
[]string{"Send all events", strconv.FormatBool(notifier.GetSendAllEvents())},
{"ID", notifier.GetID()},
{"Type", string(notifier.GetType())},
{"Name", notifier.GetName()},
{"Enabled", strconv.FormatBool(notifier.IsActive())},
{"Send all events", strconv.FormatBool(notifier.GetSendAllEvents())},
}
for _, v := range data {
t.Append(v)
}

// Type data
caser := cases.Title(language.English)
for key, value := range notifier.TypeDataMap() {
t.Append([]string{strings.Title(key), fmt.Sprintf("%v", value)})
t.Append([]string{caser.String(key), fmt.Sprintf("%v", value)})
}

//Selected events
// Selected events
if !notifier.GetSendAllEvents() {
if len(notifier.GetSelectedEventIDs()) <= 0 {
t.Append([]string{"Selected events", ""})
Expand Down
4 changes: 1 addition & 3 deletions notifiers/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func Update(ctx context.Context, app, ID string, params ProvisionParams) error {

// If there is no selected events, keep the existing ones
if len(params.SelectedEventNames) == 0 {
for _, id := range notifier.SelectedEventIDs {
params.SelectedEventIDs = append(params.SelectedEventIDs, id)
}
params.SelectedEventIDs = append([]string{}, notifier.SelectedEventIDs...)
} else {
for _, name := range params.SelectedEventNames {
for _, t := range eventTypes {
Expand Down
2 changes: 1 addition & 1 deletion regionmigrations/refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *Refresher) writeMigration(w *uilive.Writer, migration *scalingo.RegionM
defer w.Flush()

if errCount != 0 {
fmt.Fprintf(w.Newline(), color.RedString("Connection lost. Retrying (%v/%v)\n", errCount, maxErrors))
fmt.Fprint(w.Newline(), color.RedString("Connection lost. Retrying (%v/%v)\n", errCount, maxErrors))
}

if migration == nil {
Expand Down
4 changes: 2 additions & 2 deletions term/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Password(prompt string) (string, error) {
bytePassword, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", errgo.Notef(err, "fail to read the password on stdin")
} else {
return string(bytePassword), nil
}

return string(bytePassword), nil
}
Loading

0 comments on commit 71ae5be

Please sign in to comment.