Skip to content

Commit 638ed65

Browse files
committed
chore: fix lint violations
Signed-off-by: Mark Sagi-Kazar <[email protected]>
1 parent 3fa25f7 commit 638ed65

20 files changed

+247
-58
lines changed

.golangci.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ linters:
77
enable:
88
- govet
99
- ineffassign
10-
# - misspell
10+
- misspell
1111
- nolintlint
1212
# - revive
13+
- staticcheck
1314
- unused
1415

1516
disable:
1617
- errcheck
17-
- staticcheck
18+
# - staticcheck
1819

1920
settings:
2021
misspell:
@@ -31,9 +32,9 @@ formatters:
3132
enable:
3233
- gci
3334
- gofmt
34-
# - gofumpt
35+
- gofumpt
3536
- goimports
36-
# - golines
37+
- golines
3738

3839
settings:
3940
gci:

afero_test.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ func TestRead0(t *testing.T) {
6060
for _, fs := range Fss {
6161
f := tmpFile(fs)
6262
defer f.Close()
63-
f.WriteString("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
63+
f.WriteString(
64+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
65+
)
6466

6567
var b []byte
6668
// b := make([]byte, 0)
@@ -103,7 +105,12 @@ func TestOpenFile(t *testing.T) {
103105
contents, _ := io.ReadAll(f)
104106
expectedContents := "initial|append"
105107
if string(contents) != expectedContents {
106-
t.Errorf("%v: appending, expected '%v', got: '%v'", fs.Name(), expectedContents, string(contents))
108+
t.Errorf(
109+
"%v: appending, expected '%v', got: '%v'",
110+
fs.Name(),
111+
expectedContents,
112+
string(contents),
113+
)
107114
}
108115
f.Close()
109116

@@ -158,7 +165,11 @@ func TestCreate(t *testing.T) {
158165
continue
159166
}
160167
if string(buf) != secondContent {
161-
t.Error(fs.Name(), "Content should be", "\""+secondContent+"\" but is \""+string(buf)+"\"")
168+
t.Error(
169+
fs.Name(),
170+
"Content should be",
171+
"\""+secondContent+"\" but is \""+string(buf)+"\"",
172+
)
162173
f.Close()
163174
continue
164175
}
@@ -351,7 +362,15 @@ func TestSeek(t *testing.T) {
351362
// http://code.google.com/p/go/issues/detail?id=91
352363
break
353364
}
354-
t.Errorf("#%d: Seek(%v, %v) = %v, %v want %v, nil", i, tt.in, tt.whence, off, err, tt.out)
365+
t.Errorf(
366+
"#%d: Seek(%v, %v) = %v, %v want %v, nil",
367+
i,
368+
tt.in,
369+
tt.whence,
370+
off,
371+
err,
372+
tt.out,
373+
)
355374
}
356375
}
357376
}

basepath_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ func TestNestedBasePaths(t *testing.T) {
123123
t.Errorf("Got error %s", err.Error())
124124
}
125125

126-
if s.BaseFs == level3Fs {
126+
switch s.BaseFs {
127+
case level3Fs:
127128
pathToExist := filepath.Join(ds.Dir3, s.FileName)
128129
if _, err := level2Fs.Stat(pathToExist); err != nil {
129130
t.Errorf("Got error %s (path %s)", err.Error(), pathToExist)
130131
}
131-
} else if s.BaseFs == level2Fs {
132+
133+
case level2Fs:
132134
pathToExist := filepath.Join(ds.Dir2, ds.Dir3, s.FileName)
133135
if _, err := level1Fs.Stat(pathToExist); err != nil {
134136
t.Errorf("Got error %s (path %s)", err.Error(), pathToExist)

copyOnWriteFs.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func (u *CopyOnWriteFs) isBaseFile(name string) (bool, error) {
3434
_, err := u.base.Stat(name)
3535
if err != nil {
3636
if oerr, ok := err.(*os.PathError); ok {
37-
if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT || oerr.Err == syscall.ENOTDIR {
37+
if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT ||
38+
oerr.Err == syscall.ENOTDIR {
3839
return false, nil
3940
}
4041
}
@@ -237,7 +238,11 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File,
237238
return u.layer.OpenFile(name, flag, perm)
238239
}
239240

240-
return nil, &os.PathError{Op: "open", Path: name, Err: syscall.ENOTDIR} // ...or os.ErrNotExist?
241+
return nil, &os.PathError{
242+
Op: "open",
243+
Path: name,
244+
Err: syscall.ENOTDIR,
245+
} // ...or os.ErrNotExist?
241246
}
242247
if b {
243248
return u.base.OpenFile(name, flag, perm)

gcsfs/file.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ func (o *GcsFile) Seek(newOffset int64, whence int) (int64, error) {
108108
if (whence == 0 && newOffset == o.fhOffset) || (whence == 1 && newOffset == 0) {
109109
return o.fhOffset, nil
110110
}
111-
log.Printf("WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n", o.fhOffset)
111+
log.Printf(
112+
"WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n",
113+
o.fhOffset,
114+
)
112115

113116
// Fore the reader/writers to be reopened (at correct offset)
114117
err := o.Sync()

gcsfs/fs.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ func (fs *Fs) Create(name string) (*GcsFile, error) {
158158
}
159159

160160
func (fs *Fs) Mkdir(name string, _ os.FileMode) error {
161-
name = fs.ensureNoLeadingSeparator(fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(name))))
161+
name = fs.ensureNoLeadingSeparator(
162+
fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(name))),
163+
)
162164
if err := validateName(name); err != nil {
163165
return err
164166
}
@@ -181,7 +183,9 @@ func (fs *Fs) Mkdir(name string, _ os.FileMode) error {
181183
}
182184

183185
func (fs *Fs) MkdirAll(path string, perm os.FileMode) error {
184-
path = fs.ensureNoLeadingSeparator(fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(path))))
186+
path = fs.ensureNoLeadingSeparator(
187+
fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(path))),
188+
)
185189
if err := validateName(path); err != nil {
186190
return err
187191
}
@@ -404,7 +408,9 @@ func (fs *Fs) Chmod(_ string, _ os.FileMode) error {
404408
}
405409

406410
func (fs *Fs) Chtimes(_ string, _, _ time.Time) error {
407-
return errors.New("method Chtimes is not implemented. Create, Delete, Updated times are read only fields in GCS and set implicitly")
411+
return errors.New(
412+
"method Chtimes is not implemented. Create, Delete, Updated times are read only fields in GCS and set implicitly",
413+
)
408414
}
409415

410416
func (fs *Fs) Chown(_ string, _, _ int) error {

gcsfs/gcs.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ func NewGcsFS(ctx context.Context, opts ...option.ClientOption) (afero.Fs, error
4848
}
4949

5050
// NewGcsFSWithSeparator is the same as NewGcsFS, but the files system will use the provided folder separator.
51-
func NewGcsFSWithSeparator(ctx context.Context, folderSeparator string, opts ...option.ClientOption) (afero.Fs, error) {
51+
func NewGcsFSWithSeparator(
52+
ctx context.Context,
53+
folderSeparator string,
54+
opts ...option.ClientOption,
55+
) (afero.Fs, error) {
5256
client, err := storage.NewClient(ctx, opts...)
5357
if err != nil {
5458
return nil, err
@@ -65,7 +69,11 @@ func NewGcsFSFromClient(ctx context.Context, client *storage.Client) (afero.Fs,
6569
}
6670

6771
// NewGcsFSFromClientWithSeparator is the same as NewGcsFSFromClient, but the file system will use the provided folder separator.
68-
func NewGcsFSFromClientWithSeparator(ctx context.Context, client *storage.Client, folderSeparator string) (afero.Fs, error) {
72+
func NewGcsFSFromClientWithSeparator(
73+
ctx context.Context,
74+
client *storage.Client,
75+
folderSeparator string,
76+
) (afero.Fs, error) {
6977
c := stiface.AdaptClient(client)
7078

7179
return &GcsFs{NewGcsFsWithSeparator(ctx, c, folderSeparator)}, nil

gcsfs/gcs_mocks.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ func (o *objectMock) NewWriter(_ context.Context) stiface.Writer {
7373
return &writerMock{name: o.name, fs: o.fs}
7474
}
7575

76-
func (o *objectMock) NewRangeReader(_ context.Context, offset, length int64) (stiface.Reader, error) {
76+
func (o *objectMock) NewRangeReader(
77+
_ context.Context,
78+
offset, length int64,
79+
) (stiface.Reader, error) {
7780
if o.name == "" {
7881
return nil, ErrEmptyObjectName
7982
}
@@ -126,7 +129,11 @@ func (o *objectMock) Attrs(_ context.Context) (*storage.ObjectAttrs, error) {
126129
return nil, err
127130
}
128131

129-
res := &storage.ObjectAttrs{Name: normSeparators(o.name), Size: info.Size(), Updated: info.ModTime()}
132+
res := &storage.ObjectAttrs{
133+
Name: normSeparators(o.name),
134+
Size: info.Size(),
135+
Updated: info.ModTime(),
136+
}
130137

131138
if info.IsDir() {
132139
// we have to mock it here, because of FileInfo logic
@@ -240,7 +247,14 @@ func (it *objectItMock) Next() (*storage.ObjectAttrs, error) {
240247
if err != nil {
241248
return nil, err
242249
}
243-
it.infos = append(it.infos, &storage.ObjectAttrs{Name: normSeparators(info.Name()), Size: info.Size(), Updated: info.ModTime()})
250+
it.infos = append(
251+
it.infos,
252+
&storage.ObjectAttrs{
253+
Name: normSeparators(info.Name()),
254+
Size: info.Size(),
255+
Updated: info.ModTime(),
256+
},
257+
)
244258
} else {
245259
var fInfos []os.FileInfo
246260
fInfos, err = it.dir.Readdir(0)

gcsfs/gcs_test.go

+31-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ var dirs = []struct {
5555
name string
5656
children []string
5757
}{
58-
{"", []string{"sub", "testDir1", "testFile"}}, // in this case it will be prepended with bucket name
58+
{
59+
"",
60+
[]string{"sub", "testDir1", "testFile"},
61+
}, // in this case it will be prepended with bucket name
5962
{"sub", []string{"testDir2"}},
6063
{"sub/testDir2", []string{"testFile"}},
6164
{"testDir1", []string{"testFile"}},
@@ -365,7 +368,14 @@ func TestGcsSeek(t *testing.T) {
365368
}
366369

367370
if n != s.offOut {
368-
t.Errorf("%v: (off: %v, whence: %v): got %v, expected %v", f.name, s.offIn, s.whence, n, s.offOut)
371+
t.Errorf(
372+
"%v: (off: %v, whence: %v): got %v, expected %v",
373+
f.name,
374+
s.offIn,
375+
s.whence,
376+
n,
377+
s.offOut,
378+
)
369379
}
370380
}
371381
}
@@ -693,7 +703,10 @@ func TestGcsGlob(t *testing.T) {
693703
prefixedEntries := [][]string{{}, {}}
694704
for _, entry := range s.entries {
695705
prefixedEntries[0] = append(prefixedEntries[0], filepath.Join(bucketName, entry))
696-
prefixedEntries[1] = append(prefixedEntries[1], string(os.PathSeparator)+filepath.Join(bucketName, entry))
706+
prefixedEntries[1] = append(
707+
prefixedEntries[1],
708+
string(os.PathSeparator)+filepath.Join(bucketName, entry),
709+
)
697710
}
698711

699712
for i, prefixedGlob := range prefixedGlobs {
@@ -775,7 +788,11 @@ func TestGcsMkdirAll(t *testing.T) {
775788
t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a"))
776789
}
777790
if info.Mode() != os.ModeDir|0o755 {
778-
t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a"), info.Mode())
791+
t.Errorf(
792+
"%s: wrong permissions, expected drwxr-xr-x, got %s",
793+
filepath.Join(bucketName, "a"),
794+
info.Mode(),
795+
)
779796
}
780797
info, err = gcsAfs.Stat(filepath.Join(bucketName, "a/b"))
781798
if err != nil {
@@ -785,7 +802,11 @@ func TestGcsMkdirAll(t *testing.T) {
785802
t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a/b"))
786803
}
787804
if info.Mode() != os.ModeDir|0o755 {
788-
t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a/b"), info.Mode())
805+
t.Errorf(
806+
"%s: wrong permissions, expected drwxr-xr-x, got %s",
807+
filepath.Join(bucketName, "a/b"),
808+
info.Mode(),
809+
)
789810
}
790811
info, err = gcsAfs.Stat(dirName)
791812
if err != nil {
@@ -800,7 +821,11 @@ func TestGcsMkdirAll(t *testing.T) {
800821

801822
err = gcsAfs.RemoveAll(filepath.Join(bucketName, "a"))
802823
if err != nil {
803-
t.Fatalf("failed to remove the folder %s with error: %s", filepath.Join(bucketName, "a"), err)
824+
t.Fatalf(
825+
"failed to remove the folder %s with error: %s",
826+
filepath.Join(bucketName, "a"),
827+
err,
828+
)
804829
}
805830
})
806831
}

iofs.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ type readDirFile struct {
137137
var _ fs.ReadDirFile = readDirFile{}
138138

139139
func (r readDirFile) ReadDir(n int) ([]fs.DirEntry, error) {
140-
items, err := r.File.Readdir(n)
140+
items, err := r.Readdir(n)
141141
if err != nil {
142142
return nil, err
143143
}
@@ -161,7 +161,12 @@ var _ Fs = FromIOFS{}
161161

162162
func (f FromIOFS) Create(name string) (File, error) { return nil, notImplemented("create", name) }
163163

164-
func (f FromIOFS) Mkdir(name string, perm os.FileMode) error { return notImplemented("mkdir", name) }
164+
func (f FromIOFS) Mkdir(
165+
name string,
166+
perm os.FileMode,
167+
) error {
168+
return notImplemented("mkdir", name)
169+
}
165170

166171
func (f FromIOFS) MkdirAll(path string, perm os.FileMode) error {
167172
return notImplemented("mkdirall", path)

0 commit comments

Comments
 (0)