Skip to content

Commit f093753

Browse files
committed
Bump golangci-lint to 1.47.2 and fix issues
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent c51e1ac commit f093753

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ issues:
124124
- unparam
125125
- goconst
126126

127+
# G306: Expect WriteFile permissions to be 0600 or less
128+
# mainly seen in internal/cli/wrtier.go
129+
- text: "G306:"
130+
linters:
131+
- gosec
132+
127133
# - text: "should have a package comment"
128134
# linters:
129135
# - golint

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DOCKER_IMAGE := quay.io/$(PROJECT_OWNER)/$(PROJECT_NAME)
3838
DOCKER_TAG ?= $(DEFAULT_TAG)
3939

4040
# Binary versions
41-
GOLANGCI_VERSION := v1.38.0
41+
GOLANGCI_VERSION := v1.47.2
4242

4343
.PHONY: all
4444
all: clean verify checkfmt lint test build

format/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (g *generator) Render(tpl string) (string, error) {
209209
})
210210
tt.CustomFunc(gotemplate.FuncMap{
211211
"include": func(s string) string {
212-
content, err := os.ReadFile(filepath.Join(g.path, s))
212+
content, err := os.ReadFile(filepath.Join(g.path, filepath.Clean(s)))
213213
if err != nil {
214214
panic(err)
215215
}

internal/cli/writer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type stdoutWriter struct{}
2828

2929
// Write content to Stdout
3030
func (sw *stdoutWriter) Write(p []byte) (int, error) {
31-
return os.Stdout.Write([]byte(string(p) + "\n"))
31+
return os.Stdout.WriteString(string(p) + "\n")
3232
}
3333

3434
// fileWriter writes content to file.
@@ -82,7 +82,7 @@ func (fw *fileWriter) Write(p []byte) (int, error) {
8282
return fw.write(filename, buf.Bytes())
8383
}
8484

85-
content, err := os.ReadFile(filename)
85+
content, err := os.ReadFile(filepath.Clean(filename))
8686
if err != nil {
8787
// In mode 'inject', if target file not found:
8888
// create it and save the generated output into it.
@@ -161,7 +161,7 @@ func (fw *fileWriter) inject(filename string, content string, generated string)
161161
func (fw *fileWriter) write(filename string, p []byte) (int, error) {
162162
// if run in check mode return exit 1
163163
if fw.check {
164-
f, err := os.ReadFile(filename)
164+
f, err := os.ReadFile(filepath.Clean(filename))
165165
if err != nil {
166166
return 0, err
167167
}

internal/reader/lines_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ the root directory of this source tree.
1111
package reader
1212

1313
import (
14-
"path/filepath"
1514
"strings"
1615
"testing"
1716

@@ -122,7 +121,7 @@ func TestReadLinesFromFile(t *testing.T) {
122121
t.Run(tt.name, func(t *testing.T) {
123122
assert := assert.New(t)
124123
lines := Lines{
125-
FileName: filepath.Join(tt.fileName),
124+
FileName: tt.fileName,
126125
LineNum: tt.lineNumber,
127126
Condition: func(line string) bool {
128127
line = strings.TrimSpace(line)

internal/testutil/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ func getExampleFolder(folder string) (string, error) {
6565
}
6666

6767
func testDataPath() string {
68-
return filepath.Join("testdata")
68+
return "testdata"
6969
}

scripts/docs/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ func generate(cmd *cobra.Command, weight int, basename string) error {
7070
}
7171

7272
filename := filepath.Join("docs", "reference", basename+".md")
73-
f, err := os.Create(filename)
73+
f, err := os.Create(filepath.Clean(filename))
7474
if err != nil {
7575
return err
7676
}
7777
defer f.Close() //nolint:errcheck,gosec
7878

79-
if _, err := io.WriteString(f, ""); err != nil {
79+
if _, err := f.WriteString(""); err != nil {
8080
return err
8181
}
8282
if err := generateMarkdown(cmd, weight, f); err != nil {

0 commit comments

Comments
 (0)