Skip to content

Commit aa21ad9

Browse files
authored
chore(ci): Lint improvement (#439)
1 parent e57293e commit aa21ad9

14 files changed

Lines changed: 44 additions & 24 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
branches:
88
- main
9+
- chore/lint-*
910
pull_request:
1011

1112
permissions:

.golangci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,18 @@ linters-settings:
145145
allow-trailing-comment: false
146146
# Force newlines in end of case at this limit (0 = never).
147147
force-case-trailing-whitespace: 0
148-
148+
depguard:
149+
rules:
150+
prevent_unmaintained_packages:
151+
list-mode: lax # allow unless explicitely denied
152+
files:
153+
- $all
154+
- "!$test"
155+
allow:
156+
- $gostd
157+
deny:
158+
- pkg: io/ioutil
159+
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
149160
linters:
150161
disable-all: true
151162
enable:

asciiconverter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *asciiConverter) Read(p []byte) (n int, err error) {
3737
} else {
3838
data, _, err = c.reader.ReadLine()
3939
if err != nil {
40-
return
40+
return n, err
4141
}
4242
}
4343

@@ -64,7 +64,7 @@ func (c *asciiConverter) Read(p []byte) (n int, err error) {
6464
// client transfers it in ASCII mode
6565
err = c.reader.UnreadByte()
6666
if err != nil {
67-
return
67+
return n, err
6868
}
6969

7070
lastByte, err := c.reader.ReadByte()

client_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func (c *clientHandler) writeLine(line string) {
574574
c.logger.Debug("Sending answer", "line", line)
575575
}
576576

577-
if _, err := c.writer.WriteString(fmt.Sprintf("%s\r\n", line)); err != nil {
577+
if _, err := fmt.Fprintf(c.writer, "%s\r\n", line); err != nil {
578578
c.logger.Warn(
579579
"Answer couldn't be sent",
580580
"line", line,

client_handler_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ func TestClientContextConcurrency(t *testing.T) {
239239
for counter < 100 {
240240
_, err := c.Getwd()
241241
assert.NoError(t, err)
242+
242243
counter++
243244
}
244245

@@ -350,11 +351,11 @@ type testNetConn struct {
350351
remoteAddr net.Addr
351352
}
352353

353-
func (*testNetConn) Read(b []byte) (n int, err error) {
354+
func (*testNetConn) Read(_ []byte) (n int, err error) {
354355
return
355356
}
356357

357-
func (*testNetConn) Write(b []byte) (n int, err error) {
358+
func (*testNetConn) Write(_ []byte) (n int, err error) {
358359
return
359360
}
360361

@@ -370,15 +371,15 @@ func (c *testNetConn) RemoteAddr() net.Addr {
370371
return c.remoteAddr
371372
}
372373

373-
func (*testNetConn) SetDeadline(t time.Time) error {
374+
func (*testNetConn) SetDeadline(_ time.Time) error {
374375
return nil
375376
}
376377

377-
func (*testNetConn) SetReadDeadline(t time.Time) error {
378+
func (*testNetConn) SetReadDeadline(_ time.Time) error {
378379
return nil
379380
}
380381

381-
func (*testNetConn) SetWriteDeadline(t time.Time) error {
382+
func (*testNetConn) SetWriteDeadline(_ time.Time) error {
382383
return nil
383384
}
384385

control_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
// Control defines the function to use as dialer Control to reuse the same port/address
13-
func Control(network, address string, c syscall.RawConn) error {
13+
func Control(_, _ string, c syscall.RawConn) error {
1414
var errSetOpts error
1515

1616
err := c.Control(func(fd uintptr) {

driver_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func NewTestServerWithDriver(t *testing.T, driver *TestServerDriver) *FtpServer
6060
if err := os.MkdirAll(dir, 0750); err != nil {
6161
panic(err)
6262
}
63+
6364
driver.fs = afero.NewBasePathFs(afero.NewOsFs(), dir)
6465
}
6566

@@ -342,12 +343,12 @@ func (driver *TestServerDriver) GetTLSConfig() (*tls.Config, error) {
342343
return nil, errNoTLS
343344
}
344345

345-
func (driver *TestServerDriver) PreAuthUser(cc ClientContext, user string) error {
346+
func (driver *TestServerDriver) PreAuthUser(cc ClientContext, _ string) error {
346347
return cc.SetTLSRequirement(driver.TLSRequirement)
347348
}
348349

349-
func (driver *TestServerDriver) VerifyConnection(cc ClientContext, user string,
350-
tlsConn *tls.Conn) (ClientDriver, error) {
350+
func (driver *TestServerDriver) VerifyConnection(_ ClientContext, _ string,
351+
_ *tls.Conn) (ClientDriver, error) {
351352
switch driver.TLSVerificationReply {
352353
case tlsVerificationFailed:
353354
return nil, errInvalidTLSCertificate

handle_auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *clientHandler) handlePASS(param string) error {
7676

7777
c.writeMessage(StatusNotLoggedIn, msg)
7878
c.disconnect()
79-
case err == nil:
79+
default: // err == nil && c.driver != nil
8080
if msg == "" {
8181
msg = "Password ok, continue"
8282
}

handle_dirs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (c *clientHandler) handleRMDIR(params string) {
140140
}
141141
}
142142

143-
func (c *clientHandler) handleCDUP(param string) error {
143+
func (c *clientHandler) handleCDUP(_ string) error {
144144
parent, _ := path.Split(c.Path())
145145
if parent != "/" && strings.HasSuffix(parent, "/") {
146146
parent = parent[0 : len(parent)-1]
@@ -156,7 +156,7 @@ func (c *clientHandler) handleCDUP(param string) error {
156156
return nil
157157
}
158158

159-
func (c *clientHandler) handlePWD(param string) error {
159+
func (c *clientHandler) handlePWD(_ string) error {
160160
c.writeMessage(StatusPathCreated, fmt.Sprintf(`"%s" is the current directory`, quoteDoubling(c.Path())))
161161

162162
return nil

handle_files.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func (c *clientHandler) doFileTransfer(tr net.Conn, file io.ReadWriter, write bo
154154
"Stream copy finished",
155155
"writtenBytes", written,
156156
)
157+
157158
if written == 0 {
158159
_, err = out.Write([]byte{})
159160
}
@@ -293,6 +294,7 @@ func (c *clientHandler) handleCHOWN(params string) {
293294
{
294295
usergroup := strings.Split(spl[0], ":")
295296
userName := usergroup[0]
297+
296298
if id, err := strconv.ParseInt(userName, 10, 32); err == nil {
297299
userID = int(id)
298300
} else {
@@ -432,6 +434,7 @@ func (c *clientHandler) handleSTATFile(param string) error {
432434

433435
return nil
434436
}
437+
435438
files, errList = directory.Readdir(-1)
436439
c.closeDirectory(directoryPath, directory)
437440
}

0 commit comments

Comments
 (0)