Skip to content

Commit 87ff500

Browse files
committed
Other linter warnings fixed
1 parent dbbced5 commit 87ff500

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

internal/command/modify/modify.go

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/arduino/libraries-repository-engine/internal/libraries/archive"
3838
"github.com/arduino/libraries-repository-engine/internal/libraries/db"
3939
"github.com/arduino/libraries-repository-engine/internal/libraries/metadata"
40-
4140
"github.com/spf13/cobra"
4241
"github.com/spf13/pflag"
4342
)

internal/command/remove/remove.go

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/arduino/libraries-repository-engine/internal/libraries/archive"
3838
"github.com/arduino/libraries-repository-engine/internal/libraries/db"
3939
"github.com/arduino/libraries-repository-engine/internal/libraries/metadata"
40-
4140
"github.com/spf13/cobra"
4241
)
4342

internal/command/sync/sync.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ package sync
2727
import (
2828
"bytes"
2929
"encoding/json"
30+
"errors"
3031
"fmt"
31-
"io/ioutil"
3232
"log"
3333
"os"
3434
"path/filepath"
@@ -61,7 +61,7 @@ func Run(command *cobra.Command, cliArguments []string) {
6161
}
6262

6363
if len(cliArguments) > 1 {
64-
feedback.LogError(fmt.Errorf("Multiple arguments are not supported"))
64+
feedback.LogError(errors.New("multiple arguments are not supported"))
6565
os.Exit(1)
6666
}
6767

@@ -102,7 +102,7 @@ func syncLibraries(reposFile string) {
102102
syncLibrary(logger, repo, libraryDb)
103103

104104
// Output log to file
105-
if err := outputLogFile(logger, repo, buffer); err != nil {
105+
if err := outputLogFile(repo, buffer); err != nil {
106106
logger.Printf("Error writing log file: %s", err.Error())
107107
}
108108

@@ -200,13 +200,13 @@ func syncLibraryTaggedRelease(logger *log.Logger, repo *libraries.Repository, ta
200200
// Checkout desired tag
201201
logger.Printf("Checking out tag: %s", tag.Name().Short())
202202
if err := gitutils.CheckoutTag(repo.Repository, tag); err != nil {
203-
return fmt.Errorf("Error checking out repo: %s", err)
203+
return fmt.Errorf("error checking out repo: %s", err)
204204
}
205205

206206
// Create library metadata from library.properties
207207
library, err := libraries.GenerateLibraryFromRepo(repo)
208208
if err != nil {
209-
return fmt.Errorf("Error generating library from repo: %s", err)
209+
return fmt.Errorf("error generating library from repo: %s", err)
210210
}
211211
library.Types = repoMeta.Types
212212

@@ -257,10 +257,10 @@ func syncLibraryTaggedRelease(logger *log.Logger, repo *libraries.Repository, ta
257257

258258
archiveData, err := archive.New(repo, library, config)
259259
if err != nil {
260-
return fmt.Errorf("Error while configuring library release archive: %s", err)
260+
return fmt.Errorf("error while configuring library release archive: %s", err)
261261
}
262262
if err := archiveData.Create(); err != nil {
263-
return fmt.Errorf("Error while zipping library: %s", err)
263+
return fmt.Errorf("error while zipping library: %s", err)
264264
}
265265

266266
release := db.FromLibraryToRelease(library)
@@ -271,13 +271,13 @@ func syncLibraryTaggedRelease(logger *log.Logger, repo *libraries.Repository, ta
271271
release.Log = releaseLog
272272

273273
if err := libraries.UpdateLibrary(release, repo.URL, libraryDb); err != nil {
274-
return fmt.Errorf("Error while updating library DB: %s", err)
274+
return fmt.Errorf("error while updating library DB: %s", err)
275275
}
276276

277277
return nil
278278
}
279279

280-
func outputLogFile(logger *log.Logger, repoMetadata *libraries.Repo, buffer *bytes.Buffer) error {
280+
func outputLogFile(repoMetadata *libraries.Repo, buffer *bytes.Buffer) error {
281281
if config.LogsFolder == "" {
282282
return nil
283283
}
@@ -294,7 +294,7 @@ func outputLogFile(logger *log.Logger, repoMetadata *libraries.Repo, buffer *byt
294294
}
295295
logFile := filepath.Join(logFolder, "index.html")
296296
output := "<pre>\n" + buffer.String() + "\n</pre>"
297-
if err := ioutil.WriteFile(logFile, []byte(output), 0644); err != nil {
297+
if err := os.WriteFile(logFile, []byte(output), 0644); err != nil {
298298
return fmt.Errorf("write log to file: %s", err.Error())
299299
}
300300
return nil

internal/libraries/git_integration_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package libraries_test
2525

2626
import (
27-
"io/ioutil"
2827
"os"
2928
"path/filepath"
3029
"testing"
@@ -43,7 +42,7 @@ func TestUpdateLibraryJson(t *testing.T) {
4342
require.NoError(t, err)
4443
require.NotNil(t, repos)
4544

46-
librariesRepo, err := ioutil.TempDir("", "libraries")
45+
librariesRepo, err := os.MkdirTemp("", "libraries")
4746
require.NoError(t, err)
4847
defer os.RemoveAll(librariesRepo)
4948

internal/libraries/zip/ziphelper.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ package zip
2525

2626
import (
2727
"fmt"
28-
"io/ioutil"
2928
"os"
3029
"os/exec"
3130
"path/filepath"
@@ -37,15 +36,12 @@ import (
3736
// Inside the archive "rootFolder" will be renamed to "zipRootFolderName".
3837
func Directory(rootFolder string, zipRootFolderName string, zipFile string) error {
3938
checks := func(path string, info os.FileInfo, err error) error {
40-
info, err = os.Lstat(path)
41-
if err != nil {
39+
if lstat, err := os.Lstat(path); err != nil { // TODO: is calling Lstat here necessary? we already have the FileInfo from the function args
4240
return err
43-
}
44-
if (info.Mode() & os.ModeSymlink) != 0 {
41+
} else if (lstat.Mode() & os.ModeSymlink) != 0 {
4542
dest, _ := os.Readlink(path)
46-
return fmt.Errorf("Symlink not allowed: %s -> %s", path, dest)
47-
}
48-
if file.IsSCCS(info.Name()) {
43+
return fmt.Errorf("symlink not allowed: %s -> %s", path, dest)
44+
} else if file.IsSCCS(lstat.Name()) {
4945
return filepath.SkipDir
5046
}
5147
return nil
@@ -60,7 +56,7 @@ func Directory(rootFolder string, zipRootFolderName string, zipFile string) erro
6056
return err
6157
}
6258

63-
tmpdir, err := ioutil.TempDir("", "ziphelper")
59+
tmpdir, err := os.MkdirTemp("", "ziphelper")
6460
if err != nil {
6561
return fmt.Errorf("creating temp dir for zip archive: %s", err)
6662
}

internal/libraries/zip/ziphelper_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ package zip
2525

2626
import (
2727
"archive/zip"
28-
"io/ioutil"
2928
"os"
3029
"testing"
3130

3231
"github.com/stretchr/testify/require"
3332
)
3433

3534
func TestZip(t *testing.T) {
36-
zipFile, err := ioutil.TempFile("", "ziphelper*.zip")
35+
zipFile, err := os.CreateTemp("", "ziphelper*.zip")
3736
require.NoError(t, err)
3837
require.NotNil(t, zipFile)
3938
zipFileName := zipFile.Name()

0 commit comments

Comments
 (0)