Skip to content

chore: update linter #4643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
514e859
chore(deps): bump golang.org/x/text from 0.22.0 to 0.23.0 (#4567)
dependabot[bot] Mar 6, 2025
4867638
feat(secret_manager): display restore methods (#4597)
scaleway-bot Mar 19, 2025
aaa6290
chore(deps): bump golang.org/x/text from 0.22.0 to 0.23.0 (#4567)
dependabot[bot] Mar 6, 2025
626d44b
feat(secret_manager): display restore methods (#4597)
scaleway-bot Mar 19, 2025
e59c142
chore(deps): bump golang.org/x/text from 0.22.0 to 0.23.0 (#4567)
dependabot[bot] Mar 6, 2025
6181cde
feat(secret_manager): display restore methods (#4597)
scaleway-bot Mar 19, 2025
292c3ce
chore(deps): bump golang.org/x/text from 0.22.0 to 0.23.0 (#4567)
dependabot[bot] Mar 6, 2025
f96b804
feat(secret_manager): display restore methods (#4597)
scaleway-bot Mar 19, 2025
9eb84c6
feat: update generated APIs
scaleway-bot Apr 8, 2025
afbf2c7
chore: fix linter configuration
Mar 25, 2025
0da3feb
FIx linters
remyleone Mar 27, 2025
3f85179
Fix
remyleone Apr 1, 2025
b8b818f
feat(vpcgw) support v2 (#4615)
yfodil Mar 26, 2025
3fd25eb
feat(core): support positional args as dynamic args as well (#4621)
kindermoumoute Mar 31, 2025
8c1515b
docs: add section for command namespaces (#4620)
remyleone Mar 31, 2025
b5d64bf
fix(arg-spec): revert multi positional arg definition (#4627)
kindermoumoute Apr 1, 2025
1e31fca
FIx linters
remyleone Mar 27, 2025
bc9f449
delete .DS_Store
Laure-di Apr 3, 2025
3ce99a9
generate doc
Laure-di Apr 3, 2025
38ae56f
fix regex issue
Laure-di Apr 4, 2025
6547f3c
fix linter
Laure-di Apr 4, 2025
c952850
update doc vpcgw
Laure-di Apr 9, 2025
45b3861
fix codesql
Laure-di Apr 9, 2025
e597594
fix linter
Laure-di Apr 9, 2025
998e820
fix generation
Laure-di Apr 9, 2025
2175cf2
fix edge service
Laure-di Apr 10, 2025
ec14be5
fix import
Laure-di Apr 10, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
Expand Down
72 changes: 28 additions & 44 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
# Golang CI pipeline configuration
#
# To execute linters in local the ./scripts/lint.sh script can be used.
version: "2"

formatters:
enable:
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- golines

linters:
default: none
# Run golangci-lint linters to see the list of all linters
# Please keep them sorted alphabetically
enable:
Expand All @@ -16,25 +26,18 @@ linters:
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix]
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
- gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false]
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false]
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
- gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false]
- gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
- govet #(vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
Expand All @@ -59,14 +62,11 @@ linters:
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false]
- staticcheck
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true]
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
- unparam # Reports unused function parameters [fast: false, auto-fix: false]
- unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
Expand All @@ -76,42 +76,22 @@ linters:
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false]

disable:
- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
- forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]
- funlen # Tool for detection of long functions [fast: true, auto-fix: false]
- gochecknoglobals # check that no global variables exist [fast: true, auto-fix: false]
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
- godot # Check if comments end in a period [fast: true, auto-fix: true]
- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
- err113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
- lll # Reports long lines [fast: true, auto-fix: false]
- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]
settings:
goconst:
min-len: 5
gosec:
excludes:
- G115
revive:
rules:
- name: exported
disabled: true

linters-settings:
goconst:
min-len: 5
gosec:
excludes:
- G115
exclusions:
paths:
- internal/pkg

issues:
exclude-dirs:
- internal/pkg

max-issues-per-linter: 0
max-same-issues: 0

exclude-rules:
rules:
- path: _test\.go
linters:
- stylecheck
Expand Down Expand Up @@ -156,3 +136,7 @@ issues:
- path: internal/namespaces/k8s/v1/types/types.go
linters:
- tagalign

issues:
max-issues-per-linter: 0
max-same-issues: 0
3 changes: 1 addition & 2 deletions cmd/scw-wasm-tester/human.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
package main

import (
"syscall/js"

"github.com/hashicorp/go-version"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/core/human"
"syscall/js"
)

func wasmTestMarshalBuildInfo(_ js.Value, _ []js.Value) any {
Expand Down
3 changes: 1 addition & 2 deletions cmd/scw-wasm-tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
package main

import (
"syscall/js"

"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
"syscall/js"
)

type jsFunction func(js.Value, []js.Value) any
Expand Down
3 changes: 1 addition & 2 deletions cmd/scw-wasm-tester/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
package main

import (
"syscall/js"

"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
"syscall/js"
)

func wasmTestFromSlice(_ js.Value, _ []js.Value) any {
Expand Down
7 changes: 5 additions & 2 deletions cmd/scw-wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package main
import (
"runtime"
"runtime/debug"
"syscall/js"

"github.com/hashicorp/go-version"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
"github.com/scaleway/scaleway-cli/v2/internal/wasm"
"syscall/js"
)

var (
Expand Down Expand Up @@ -62,7 +62,10 @@ func main() {
if args.targetObject != "" {
cliPackage := js.ValueOf(map[string]any{})
cliPackage.Set("run", js.FuncOf(jshelpers.AsPromise(wasm.RunWithBuildInfo(buildInfo))))
cliPackage.Set("complete", js.FuncOf(jshelpers.AsPromise(wasm.AutocompleteWithBuildInfo(buildInfo))))
cliPackage.Set(
"complete",
js.FuncOf(jshelpers.AsPromise(wasm.AutocompleteWithBuildInfo(buildInfo))),
)
cliPackage.Set("configureOutput", js.FuncOf(jshelpers.AsPromise(wasm.ConfigureOutput)))
cliPackage.Set("stop", js.FuncOf(jshelpers.AsyncJsFunc(stop)))
js.Global().Set(args.targetObject, cliPackage)
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw-wasm/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package main

import (
"fmt"
"syscall/js"

"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
"github.com/scaleway/scaleway-cli/v2/internal/wasm"
"syscall/js"
)

func wasmRun(this js.Value, args []js.Value) (any, error) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func main() {

func mainNoExit() int {
buildInfo := &core.BuildInfo{
Version: version.Must(version.NewSemver(buildVersion())), // panic when version does not respect semantic versioning
Version: version.Must(
version.NewSemver(buildVersion()),
), // panic when version does not respect semantic versioning
BuildDate: BuildDate,
GoVersion: GoVersion,
GitBranch: GitBranch,
Expand Down
5 changes: 4 additions & 1 deletion core/arg_file_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func loadArgsFileContent(cmd *Command, cmdArgs interface{}) error {
}

fieldName := strcase.ToPublicGoName(argSpec.Name)
fieldValues, err := GetValuesForFieldByName(reflect.ValueOf(cmdArgs), strings.Split(fieldName, "."))
fieldValues, err := GetValuesForFieldByName(
reflect.ValueOf(cmdArgs),
strings.Split(fieldName, "."),
)
if err != nil {
continue
}
Expand Down
8 changes: 7 additions & 1 deletion core/arg_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ func (s ArgSpecs) GetPositionalArg() *ArgSpec {
for _, argSpec := range s {
if argSpec.Positional {
if positionalArg != nil {
panic(fmt.Errorf("more than one positional parameter detected: %s and %s are flagged as positional arg", positionalArg.Name, argSpec.Name))
panic(
fmt.Errorf(
"more than one positional parameter detected: %s and %s are flagged as positional arg",
positionalArg.Name,
argSpec.Name,
),
)
}
positionalArg = argSpec
}
Expand Down
38 changes: 32 additions & 6 deletions core/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ func NewAutoCompleteFlagNode(parent *AutoCompleteNode, flagSpec *FlagSpec) *Auto
// GetChildOrCreate search a child node by name,
// and either returns it if found
// or create new children with the given name and aliases, and returns it.
func (node *AutoCompleteNode) GetChildOrCreate(name string, aliases []string, flags []FlagSpec) *AutoCompleteNode {
func (node *AutoCompleteNode) GetChildOrCreate(
name string,
aliases []string,
flags []FlagSpec,
) *AutoCompleteNode {
if _, exist := node.Children[name]; !exist {
childNode := NewAutoCompleteCommandNode(flags)
node.Children[name] = childNode
Expand Down Expand Up @@ -234,7 +238,12 @@ func BuildAutoCompleteTree(ctx context.Context, commands *Commands) *AutoComplet
//
// command <flag name>=<flag value beginning><tab> gives no suggestion for now
// eg: scw test flower create name=p -o=jso
func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string, rightWords []string) *AutocompleteResponse {
func AutoComplete(
ctx context.Context,
leftWords []string,
wordToComplete string,
rightWords []string,
) *AutocompleteResponse {
commands := ExtractCommands(ctx)

// Create AutoComplete Tree
Expand Down Expand Up @@ -310,7 +319,13 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
// We try to complete the value of an unknown arg
return &AutocompleteResponse{}
}
suggestions := AutoCompleteArgValue(ctx, argNode.Command, argNode.ArgSpec, argValuePrefix, completedArgs)
suggestions := AutoCompleteArgValue(
ctx,
argNode.Command,
argNode.ArgSpec,
argValuePrefix,
completedArgs,
)

// We need to prefix suggestions with the argName to enable the arg value auto-completion.
for k, s := range suggestions {
Expand Down Expand Up @@ -368,12 +383,22 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
// AutoCompleteArgValue returns suggestions for a (argument name, argument value prefix) pair.
// Priority is given to the AutoCompleteFunc from the ArgSpec, if it is set.
// Otherwise, we use EnumValues from the ArgSpec.
func AutoCompleteArgValue(ctx context.Context, cmd *Command, argSpec *ArgSpec, argValuePrefix string, completedArgs map[string]string) []string {
func AutoCompleteArgValue(
ctx context.Context,
cmd *Command,
argSpec *ArgSpec,
argValuePrefix string,
completedArgs map[string]string,
) []string {
if argSpec == nil {
return nil
}
if argSpec.AutoCompleteFunc != nil {
return argSpec.AutoCompleteFunc(ctx, argValuePrefix, requestFromCompletedArgs(cmd, completedArgs))
return argSpec.AutoCompleteFunc(
ctx,
argValuePrefix,
requestFromCompletedArgs(cmd, completedArgs),
)
}

possibleValues := []string(nil)
Expand Down Expand Up @@ -475,7 +500,8 @@ func keySuggestion(key string, completedArg map[string]string, wordToComplete st
if i >= len(splitWordToComplete) {
continue
}
if k != splitWordToComplete[i] && (k == sliceSchema || k == mapSchema) && splitWordToComplete[i] != "" {
if k != splitWordToComplete[i] && (k == sliceSchema || k == mapSchema) &&
splitWordToComplete[i] != "" {
splitKey[i] = splitWordToComplete[i]
}
}
Expand Down
Loading
Loading