diff --git a/.golangci.yaml b/.golangci.yaml index ac42855..d90d8a3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,160 +1,22 @@ -# Based on https://github.com/istio/common-files/blob/master/files/common/config/.golangci.yml - -run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 20m - - build-tags: [] - - # which dirs to skip: they won't be analyzed; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but next dirs are always skipped independently - # from this option's value: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs: [] - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - skip-files: [] - linters: - disable-all: true enable: - - errcheck + # Note that these are *additional* linters beyond the defaults: + # + # https://golangci-lint.run/usage/linters/#enabled-by-default - exportloopref - gocritic - - gosec - - govet - - ineffassign - - misspell - revive - - staticcheck - # - stylecheck - - typecheck + - misspell - unconvert - - unused - fast: false + - bodyclose linters-settings: - errcheck: - # report about not checking of errors in type assetions: `a := b.(MyStruct)`; - # default is false: such cases aren't reported by default. - check-type-assertions: false - - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: false - gosec: - excludes: - - G306 # Expect WriteFile permissions to be 0600 or less - govet: - # report about shadowed variables - check-shadowing: false misspell: - # Correct spellings using locale preferences for US or UK. - # Default is to use a neutral variety of English. - # Setting locale to US will correct the British spelling of 'colour' to 'color'. locale: US - revive: - rules: - - name: unused-parameter - disabled: true - unused: - # treat code as a program (not a library) and report unused exported identifiers; default is false. - # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find funcs usages. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: false - gocritic: - disabled-checks: - - singleCaseSwitch - enabled-checks: - - appendCombine - - argOrder - - assignOp - - badCond - - boolExprSimplify - - builtinShadow - - captLocal - - caseOrder - - codegenComment - - commentedOutCode - - commentedOutImport - - defaultCaseOrder - - deprecatedComment - - docStub - - dupArg - - dupBranchBody - - dupCase - - dupSubExpr - - elseif - - emptyFallthrough - - equalFold - - flagDeref - - flagName - - hexLiteral - - indexAlloc - - initClause - - methodExprCall - - nilValReturn - - octalLiteral - - offBy1 - - rangeExprCopy - - regexpMust - - sloppyLen - - stringXbytes - - switchTrue - - typeAssertChain - - typeSwitchVar - - typeUnparen - - underef - - unlambda - - unnecessaryBlock - - unslice - - valSwap - - weakCond - # Unused - # - yodaStyleExpr - # - appendAssign - # - commentFormatting - # - emptyStringTest - # - exitAfterDefer - # - ifElseChain - # - hugeParam - # - importShadow - # - nestingReduce - # - paramTypeCombine - # - ptrToRefParam - # - rangeValCopy - # - singleCaseSwitch - # - sloppyReassign - # - unlabelStmt - # - unnamedResult - # - wrapperFunc - issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - # exclude: [] - exclude-rules: - # Exclude some linters from running on test files. - - path: _test\.go$|^tests/|^samples/ + - path: _test\.go$ linters: - errcheck - - # Independently from option `exclude` we use default exclude patterns, - # it can be disabled by this option. To list all - # excluded by default patterns execute `golangci-lint run --help`. - # Default value for this option is true. - exclude-use-default: true - - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. - max-per-linter: 0 - - # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. - max-same-issues: 0 + - bodyclose + - revive diff --git a/internal/cmd/account/current.go b/internal/cmd/account/current.go index 49a9da5..431f85b 100644 --- a/internal/cmd/account/current.go +++ b/internal/cmd/account/current.go @@ -15,7 +15,7 @@ import ( var CurrentCmd = &cobra.Command{ Use: "current", Short: "Show the current account", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() r8, err := client.NewClient() diff --git a/internal/cmd/auth/login.go b/internal/cmd/auth/login.go index e795371..9e585a0 100644 --- a/internal/cmd/auth/login.go +++ b/internal/cmd/auth/login.go @@ -25,7 +25,7 @@ You can find your Replicate API token at https://replicate.com/account`, # Log in with token file $ replicate auth login --token-stdin < path/to/token`, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() tokenStdin, err := cmd.Flags().GetBool("token-stdin") diff --git a/internal/cmd/hardware/list.go b/internal/cmd/hardware/list.go index 5059494..b1eb379 100644 --- a/internal/cmd/hardware/list.go +++ b/internal/cmd/hardware/list.go @@ -15,7 +15,7 @@ import ( var listCmd = &cobra.Command{ Use: "list", Short: "List hardware", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() if cmd.Flags().Changed("web") { diff --git a/internal/cmd/model/list.go b/internal/cmd/model/list.go index eb0bc9e..110ba73 100644 --- a/internal/cmd/model/list.go +++ b/internal/cmd/model/list.go @@ -27,7 +27,7 @@ func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd - switch msg := msg.(type) { + switch msg := msg.(type) { //nolint:gocritic case tea.KeyMsg: switch msg.String() { case "esc": @@ -58,7 +58,7 @@ func (m model) View() string { var listCmd = &cobra.Command{ Use: "list", Short: "List models", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() r8, err := client.NewClient() diff --git a/internal/cmd/prediction/list.go b/internal/cmd/prediction/list.go index 62d9941..c4afd1b 100644 --- a/internal/cmd/prediction/list.go +++ b/internal/cmd/prediction/list.go @@ -27,7 +27,7 @@ func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd - switch msg := msg.(type) { + switch msg := msg.(type) { //nolint:gocritic case tea.KeyMsg: switch msg.String() { case "esc": @@ -58,7 +58,7 @@ func (m model) View() string { var listCmd = &cobra.Command{ Use: "list", Short: "List predictions", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() r8, err := client.NewClient() diff --git a/internal/cmd/scaffold.go b/internal/cmd/scaffold.go index a13839a..5576710 100644 --- a/internal/cmd/scaffold.go +++ b/internal/cmd/scaffold.go @@ -30,11 +30,11 @@ var ScaffoldCmd = &cobra.Command{ return err } - predictionId, err := parsePredictionId(args[0]) + predictionID, err := parsePredictionID(args[0]) if err != nil { return fmt.Errorf("failed to parse prediction ID: %w", err) } - prediction, err := client.GetPrediction(ctx, predictionId) + prediction, err := client.GetPrediction(ctx, predictionID) if prediction == nil || err != nil { return fmt.Errorf("failed to get prediction: %w", err) } @@ -43,7 +43,7 @@ var ScaffoldCmd = &cobra.Command{ if len(args) == 2 { directory = args[1] } else { - directory = predictionId + directory = predictionID } template, _ := cmd.Flags().GetString("template") @@ -64,7 +64,7 @@ func init() { } // Parse the prediction id from a url, or return the prediction id if it's not a url -func parsePredictionId(value string) (string, error) { +func parsePredictionID(value string) (string, error) { // Case 1: A prediction ID if !strings.Contains(value, "/") { return value, nil @@ -72,37 +72,37 @@ func parsePredictionId(value string) (string, error) { // Case 2: A URL in the form https://replicate.com/p/{id} if strings.HasPrefix(value, "replicate.com/p/") || strings.HasPrefix(value, "https://replicate.com/p/") { - splitUrl := strings.Split(value, "/") - if len(splitUrl) == 0 { + splitURL := strings.Split(value, "/") + if len(splitURL) == 0 { return "", fmt.Errorf("invalid URL format") } - return splitUrl[len(splitUrl)-1], nil + return splitURL[len(splitURL)-1], nil } // Case 3: A URL in the form https://api.replicate.com/v1/predictions/{id} if strings.HasPrefix(value, "api.replicate.com/v1/predictions/") || strings.HasPrefix(value, "https://api.replicate.com/v1/predictions/") { - splitUrl := strings.Split(value, "/") - if len(splitUrl) == 0 { + splitURL := strings.Split(value, "/") + if len(splitURL) == 0 { return "", fmt.Errorf("invalid URL format") } - return splitUrl[len(splitUrl)-1], nil + return splitURL[len(splitURL)-1], nil } // Case 4: A URL in the form "https://replicate.com/*?prediction={id}" if strings.Contains(value, "replicate.com") || strings.Contains(value, "https://replicate.com") { - parsedUrl, err := url.Parse(value) + parsedURL, err := url.Parse(value) if err != nil { return "", fmt.Errorf("failed to parse URL: %w", err) } - queryParams, err := url.ParseQuery(parsedUrl.RawQuery) + queryParams, err := url.ParseQuery(parsedURL.RawQuery) if err != nil { return "", fmt.Errorf("failed to parse query parameters: %w", err) } - predictionId := queryParams.Get("prediction") - if predictionId == "" { + predictionID := queryParams.Get("prediction") + if predictionID == "" { return "", fmt.Errorf("no prediction ID found in URL") } - return predictionId, nil + return predictionID, nil } // If none of the above cases match, return an error diff --git a/internal/cmd/training/list.go b/internal/cmd/training/list.go index cf6565d..d5a03b7 100644 --- a/internal/cmd/training/list.go +++ b/internal/cmd/training/list.go @@ -26,7 +26,7 @@ func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd - switch msg := msg.(type) { + switch msg := msg.(type) { //nolint:gocritic case tea.KeyMsg: switch msg.String() { case "esc": @@ -57,7 +57,7 @@ func (m model) View() string { var listCmd = &cobra.Command{ Use: "list", Short: "List trainings", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() r8, err := client.NewClient() diff --git a/internal/util/optparse.go b/internal/util/optparse.go index 76c4828..acf6ca3 100644 --- a/internal/util/optparse.go +++ b/internal/util/optparse.go @@ -95,7 +95,7 @@ func GetPipedArgs() (string, error) { } return string(output), nil - } else { - return "", nil } + + return "", nil } diff --git a/internal/util/schema.go b/internal/util/schema.go index ba36ed9..2b00b52 100644 --- a/internal/util/schema.go +++ b/internal/util/schema.go @@ -23,8 +23,8 @@ func GetSchemas(version replicate.ModelVersion) (input *openapi3.Schema, output } schemas := spec.Components.Schemas - inputSchemaRef, _ := schemas["Input"] - outputSchemaRef, _ := schemas["Output"] + inputSchemaRef := schemas["Input"] + outputSchemaRef := schemas["Output"] if inputSchemaRef != nil { input = inputSchemaRef.Value