Skip to content

Commit 254fa49

Browse files
authored
chore: add support for errchkjson (#4066)
1 parent fa08795 commit 254fa49

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ linters:
1616
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
1717
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
1818
- 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]
19+
- 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]
1920
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
2021
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
2122
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
2223
- gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false]
2324
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
25+
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
2426
- 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]
2527
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
28+
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
2629
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
2730
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
2831
- 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]

internal/namespaces/mnq/v1beta1/custom_nats_helpers.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ func FileExists(filePath string) bool {
3939
return !os.IsNotExist(err)
4040
}
4141

42-
func natsContextFrom(account *mnq.NatsAccount, credsPath string) []byte {
42+
func natsContextFrom(account *mnq.NatsAccount, credsPath string) ([]byte, error) {
4343
ctx := &natsContext{
4444
Description: "Nats context created by Scaleway CLI",
4545
URL: account.Endpoint,
4646
CredentialsPath: credsPath,
4747
}
48-
b, _ := json.Marshal(ctx)
49-
return b
48+
b, err := json.Marshal(ctx)
49+
if err != nil {
50+
return nil, err
51+
}
52+
return b, nil
5053
}
5154

5255
func writeFile(ctx context.Context, dir string, entity *NatsEntity, extension string) (string, error) {
@@ -97,9 +100,14 @@ func saveNATSCredentials(ctx context.Context, creds *mnq.NatsCredentials, natsAc
97100
return "", err
98101
}
99102

103+
natsContent, err := natsContextFrom(natsAccount, credsPath)
104+
if err != nil {
105+
return "", err
106+
}
107+
100108
contextEntity := &NatsEntity{
101109
Name: natsAccount.Name,
102-
Content: natsContextFrom(natsAccount, credsPath),
110+
Content: natsContent,
103111
}
104112

105113
contextPath, err := writeFile(ctx, natsContextDir, contextEntity, "json")

0 commit comments

Comments
 (0)