Skip to content

Commit c8c49b8

Browse files
committed
Hide some defers and tests from linter
1 parent 778c944 commit c8c49b8

File tree

7 files changed

+30
-26
lines changed

7 files changed

+30
-26
lines changed

internal/callgraph/language/java/callgraph.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (cg *Callgraph) javaVersion(path string) (string, error) {
7979
if len(match) > 1 {
8080
return match[1], nil
8181
}
82+
8283
return "", err
8384
}
8485

internal/callgraph/language/java/cmd_factory_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10+
const jarPath = "jarpath"
11+
1012
func TestMakeMvnCopyDependenciesCmd(t *testing.T) {
1113
targetDir := "target"
1214
ctx, _ := ctxTestdata.NewContextMock()
@@ -21,7 +23,6 @@ func TestMakeMvnCopyDependenciesCmd(t *testing.T) {
2123
}
2224

2325
func TestMakeCallGraphGenerationCmd(t *testing.T) {
24-
jarPath := "jarpath"
2526
targetClasses := []string{"targetclasses"}
2627
dependencyClasses := "dependencypath"
2728
outputName := ".outputName"
@@ -40,7 +41,6 @@ func TestMakeCallGraphGenerationCmd(t *testing.T) {
4041
}
4142

4243
func TestMakeBuildMavenCmd(t *testing.T) {
43-
jarPath := "jarpath"
4444
ctx, _ := ctxTestdata.NewContextMock()
4545
cmd, err := CmdFactory{}.MakeBuildMavenCmd(jarPath, ctx)
4646

@@ -54,7 +54,6 @@ func TestMakeBuildMavenCmd(t *testing.T) {
5454
}
5555

5656
func TestMakeJavaVersionCmd(t *testing.T) {
57-
jarPath := "jarpath"
5857
ctx, _ := ctxTestdata.NewContextMock()
5958
cmd, err := CmdFactory{}.MakeJavaVersionCmd(jarPath, ctx)
6059

internal/callgraph/language/java/soot_handler.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ func downloadSootWrapper(arc ioFs.IArchive, fs ioFs.IFileSystem, path string, ve
5252

5353
return err
5454
}
55+
5556
zipPath := dir + "/soot_wrapper.zip"
5657
zipFile, err := fs.Create(zipPath)
57-
defer zipFile.Close()
5858
if err != nil {
5959

6060
return err
6161
}
62+
defer zipFile.Close()
63+
6264
err = downloadCompressedSootWrapper(fs, zipFile, version)
6365
if err != nil {
6466

@@ -78,6 +80,7 @@ func downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile *os.File, versio
7880
client := http.Client{
7981
CheckRedirect: func(r *http.Request, via []*http.Request) error {
8082
r.URL.Opaque = r.URL.Path
83+
8184
return nil
8285
},
8386
}
@@ -89,8 +92,8 @@ func downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile *os.File, versio
8992
defer resp.Body.Close()
9093

9194
_, err = fs.Copy(zipFile, resp.Body)
92-
return err
9395

96+
return err
9497
}
9598

9699
func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc ioFs.IArchive) (string, error) {
@@ -110,6 +113,7 @@ func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc io
110113
}
111114
path, err := filepath.Abs(path.Join(debrickedDir, "soot-wrapper.jar"))
112115
if err != nil {
116+
113117
return "", err
114118
}
115119
if _, err := fs.Stat(path); fs.IsNotExist(err) {
@@ -121,6 +125,7 @@ func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc io
121125
} else {
122126
version = "11"
123127
} // Handling correct jar to install
128+
124129
return path, downloadSootWrapper(arc, fs, path, version)
125130
}
126131

internal/callgraph/language/java/soot_handler_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestInitializeSootWrapper(t *testing.T) {
2121

2222
func TestInitializeSootWrapperOpenEmbedError(t *testing.T) {
2323
errString := "fs open embed error"
24-
fsMock := ioTestData.FileSystemMock{FsOpenEmbedError: fmt.Errorf(errString)}
24+
fsMock := ioTestData.FileSystemMock{FsOpenEmbedError: fmt.Errorf(errString)} //nolint
2525
tempDir, err := fsMock.MkdirTemp(".tmp")
2626
assert.NoError(t, err)
2727
_, err = initializeSootWrapper(fsMock, tempDir)
@@ -31,7 +31,7 @@ func TestInitializeSootWrapperOpenEmbedError(t *testing.T) {
3131

3232
func TestInitializeSootWrapperFsReadAllError(t *testing.T) {
3333
errString := "fs read all error"
34-
fsMock := ioTestData.FileSystemMock{FsReadAllError: fmt.Errorf(errString)}
34+
fsMock := ioTestData.FileSystemMock{FsReadAllError: fmt.Errorf(errString)} //nolint
3535
tempDir, err := fsMock.MkdirTemp(".tmp")
3636
assert.NoError(t, err)
3737
_, err = initializeSootWrapper(fsMock, tempDir)
@@ -41,7 +41,7 @@ func TestInitializeSootWrapperFsReadAllError(t *testing.T) {
4141

4242
func TestInitializeSootWrapperFsWriteFileError(t *testing.T) {
4343
errString := "fs write file error"
44-
fsMock := ioTestData.FileSystemMock{FsWriteFileError: fmt.Errorf(errString)}
44+
fsMock := ioTestData.FileSystemMock{FsWriteFileError: fmt.Errorf(errString)} //nolint
4545
tempDir, err := fsMock.MkdirTemp(".tmp")
4646
assert.NoError(t, err)
4747
_, err = initializeSootWrapper(fsMock, tempDir)
@@ -58,7 +58,7 @@ func TestDownloadSootWrapper(t *testing.T) {
5858

5959
func TestDownloadSootWrapperMkdirTempError(t *testing.T) {
6060
errString := "mkdir temp error"
61-
fsMock := ioTestData.FileSystemMock{MkdirTempError: fmt.Errorf(errString)}
61+
fsMock := ioTestData.FileSystemMock{MkdirTempError: fmt.Errorf(errString)} //nolint
6262
arcMock := ioTestData.ArchiveMock{}
6363
err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11")
6464
assert.Error(t, err)
@@ -67,7 +67,7 @@ func TestDownloadSootWrapperMkdirTempError(t *testing.T) {
6767

6868
func TestDownloadSootWrapperCreateError(t *testing.T) {
6969
errString := "create error"
70-
fsMock := ioTestData.FileSystemMock{CreateError: fmt.Errorf(errString)}
70+
fsMock := ioTestData.FileSystemMock{CreateError: fmt.Errorf(errString)} //nolint
7171
arcMock := ioTestData.ArchiveMock{}
7272
err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11")
7373
assert.Error(t, err)
@@ -77,7 +77,7 @@ func TestDownloadSootWrapperCreateError(t *testing.T) {
7777
func TestDownloadSootWrapperUnzipError(t *testing.T) {
7878
errString := "create error"
7979
fsMock := ioTestData.FileSystemMock{}
80-
arcMock := ioTestData.ArchiveMock{UnzipFileError: fmt.Errorf(errString)}
80+
arcMock := ioTestData.ArchiveMock{UnzipFileError: fmt.Errorf(errString)} //nolint
8181
err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11")
8282
assert.Error(t, err)
8383
assert.Equal(t, err.Error(), errString)
@@ -165,7 +165,7 @@ func TestGetSootWrapperInitialize(t *testing.T) {
165165

166166
func TestGetSootWrapperMkdirError(t *testing.T) {
167167
errString := "mkdir error"
168-
fsMock := ioTestData.FileSystemMock{MkdirError: fmt.Errorf(errString), StatError: fmt.Errorf(""), IsNotExistBool: true}
168+
fsMock := ioTestData.FileSystemMock{MkdirError: fmt.Errorf(errString), StatError: fmt.Errorf(""), IsNotExistBool: true} //nolint
169169
arcMock := ioTestData.ArchiveMock{}
170170
sootHandler := SootHandler{}
171171
_, err := sootHandler.GetSootWrapper("11", fsMock, arcMock)

internal/io/archive.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package io
22

33
import (
44
"encoding/base64"
5-
"fmt"
65
"path"
76
)
87

@@ -87,23 +86,23 @@ func (arc *Archive) UnzipFile(sourcePath string, targetPath string) error {
8786

8887
return err
8988
}
90-
defer arc.zip.CloseReader(r)
89+
defer arc.zip.CloseReader(r) //nolint
9190

9291
f := r.File[1] //TODO: Change to first file and error-check for multiple once sootwrapper builds only one
93-
fmt.Println("94")
9492
outFile, err := arc.fs.Create(targetPath)
9593
if err != nil {
9694
return err
9795
}
98-
defer outFile.Close()
96+
defer outFile.Close() //nolint
9997

10098
rc, err := arc.zip.Open(f)
10199
if err != nil {
102100
return err
103101
}
104-
defer arc.zip.Close(rc)
102+
defer arc.zip.Close(rc) //nolint
105103

106104
_, err = arc.fs.Copy(outFile, rc)
105+
107106
return err
108107
}
109108

internal/io/archive_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestUnzipFileCreateError(t *testing.T) {
208208
reader := zip.Reader{
209209
File: []*zip.File{nil, nil},
210210
}
211-
readCloser := zip.ReadCloser{Reader: reader}
211+
readCloser := zip.ReadCloser{Reader: reader} //nolint
212212
fsMock := ioTestData.FileSystemMock{CreateError: fmt.Errorf("%s", t.Name())}
213213
zipMock := ioTestData.ZipMock{ReaderCloser: &readCloser}
214214
a := Archive{
@@ -225,7 +225,7 @@ func TestUnzipFileOpenError(t *testing.T) {
225225
reader := zip.Reader{
226226
File: []*zip.File{nil, nil},
227227
}
228-
readCloser := zip.ReadCloser{Reader: reader}
228+
readCloser := zip.ReadCloser{Reader: reader} //nolint
229229
fsMock := ioTestData.FileSystemMock{}
230230
zipMock := ioTestData.ZipMock{ReaderCloser: &readCloser, OpenError: fmt.Errorf("%s", t.Name())}
231231
a := Archive{
@@ -242,7 +242,7 @@ func TestUnzipFileCopyError(t *testing.T) {
242242
r, err := zipStruct.OpenReader("testdata/text.zip")
243243
r.File = append(r.File, r.File[0]) // Hack solution (:
244244
assert.NoError(t, err)
245-
defer zipStruct.CloseReader(r)
245+
defer zipStruct.CloseReader(r) //nolint
246246

247247
fsMock := ioTestData.FileSystemMock{CopyError: fmt.Errorf("%s", t.Name())}
248248
zipMock := ioTestData.ZipMock{ReaderCloser: r}

internal/io/zip_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const fileNameZip = "debricked-test.zip"
1212

1313
func TestNewWriter(t *testing.T) {
1414
testFile, err := filesystem.Create(fileNameZip)
15-
defer deleteFile(t, testFile)
15+
defer deleteFile(t, testFile) //nolint
1616
assert.NoError(t, err)
1717

1818
writer := zipStruct.NewWriter(testFile)
@@ -26,7 +26,7 @@ func TestFileInfoHeader(t *testing.T) {
2626
assert.NoError(t, err)
2727

2828
writer := zipStruct.NewWriter(testFile)
29-
defer zipStruct.CloseWriter(writer)
29+
defer zipStruct.CloseWriter(writer) //nolint
3030

3131
info, _ := filesystem.StatFile(testFile)
3232
_, err = zipStruct.FileInfoHeader(info)
@@ -36,11 +36,11 @@ func TestFileInfoHeader(t *testing.T) {
3636

3737
func TestCreateHeader(t *testing.T) {
3838
testFile, err := filesystem.Create(fileNameZip)
39-
defer deleteFile(t, testFile)
39+
defer deleteFile(t, testFile) //nolint
4040
assert.NoError(t, err)
4141

4242
writer := zipStruct.NewWriter(testFile)
43-
defer zipStruct.CloseWriter(writer)
43+
defer zipStruct.CloseWriter(writer) //nolint
4444

4545
info, _ := filesystem.StatFile(testFile)
4646
header, _ := zipStruct.FileInfoHeader(info)
@@ -57,7 +57,7 @@ func TestDeflate(t *testing.T) {
5757
func TestOpenZip(t *testing.T) {
5858
r, err := zipStruct.OpenReader("testdata/text.zip")
5959
assert.NoError(t, err)
60-
defer zipStruct.CloseReader(r)
60+
defer zipStruct.CloseReader(r) //nolint
6161

6262
assert.NotNil(t, r, "reader not opened properly")
6363
_, err = zipStruct.Open(r.File[0])
@@ -67,7 +67,7 @@ func TestOpenZip(t *testing.T) {
6767
func TestCloseZip(t *testing.T) {
6868
r, err := zipStruct.OpenReader("testdata/text.zip")
6969
assert.NoError(t, err)
70-
defer zipStruct.CloseReader(r)
70+
defer zipStruct.CloseReader(r) //nolint
7171

7272
assert.NotNil(t, r, "reader not opened properly")
7373
rc, err := zipStruct.Open(r.File[0])

0 commit comments

Comments
 (0)