Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 8 additions & 146 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion internal/cmd/account/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/hardware/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/model/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/prediction/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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()
Expand Down
30 changes: 15 additions & 15 deletions internal/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
Expand All @@ -64,45 +64,45 @@ 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
}

// 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
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/training/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions internal/util/optparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func GetPipedArgs() (string, error) {
}

return string(output), nil
} else {
return "", nil
}

return "", nil
}
4 changes: 2 additions & 2 deletions internal/util/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down