Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): Lint improvement #439

Merged
merged 4 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- main
- chore/lint-*
pull_request:

permissions:
Expand Down
13 changes: 12 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ linters-settings:
allow-trailing-comment: false
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0

depguard:
rules:
prevent_unmaintained_packages:
list-mode: lax # allow unless explicitely denied
files:
- $all
- "!$test"
allow:
- $gostd
deny:
- pkg: io/ioutil
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
linters:
disable-all: true
enable:
Expand Down
4 changes: 2 additions & 2 deletions asciiconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
} else {
data, _, err = c.reader.ReadLine()
if err != nil {
return
return n, err
}
}

Expand All @@ -64,7 +64,7 @@
// client transfers it in ASCII mode
err = c.reader.UnreadByte()
if err != nil {
return
return n, err

Check warning on line 67 in asciiconverter.go

View check run for this annotation

Codecov / codecov/patch

asciiconverter.go#L67

Added line #L67 was not covered by tests
}

lastByte, err := c.reader.ReadByte()
Expand Down
2 changes: 1 addition & 1 deletion client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (c *clientHandler) writeLine(line string) {
c.logger.Debug("Sending answer", "line", line)
}

if _, err := c.writer.WriteString(fmt.Sprintf("%s\r\n", line)); err != nil {
if _, err := fmt.Fprintf(c.writer, "%s\r\n", line); err != nil {
c.logger.Warn(
"Answer couldn't be sent",
"line", line,
Expand Down
11 changes: 6 additions & 5 deletions client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func TestClientContextConcurrency(t *testing.T) {
for counter < 100 {
_, err := c.Getwd()
assert.NoError(t, err)

counter++
}

Expand Down Expand Up @@ -350,11 +351,11 @@ type testNetConn struct {
remoteAddr net.Addr
}

func (*testNetConn) Read(b []byte) (n int, err error) {
func (*testNetConn) Read(_ []byte) (n int, err error) {
return
}

func (*testNetConn) Write(b []byte) (n int, err error) {
func (*testNetConn) Write(_ []byte) (n int, err error) {
return
}

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

func (*testNetConn) SetDeadline(t time.Time) error {
func (*testNetConn) SetDeadline(_ time.Time) error {
return nil
}

func (*testNetConn) SetReadDeadline(t time.Time) error {
func (*testNetConn) SetReadDeadline(_ time.Time) error {
return nil
}

func (*testNetConn) SetWriteDeadline(t time.Time) error {
func (*testNetConn) SetWriteDeadline(_ time.Time) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion control_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)

// Control defines the function to use as dialer Control to reuse the same port/address
func Control(network, address string, c syscall.RawConn) error {
func Control(_, _ string, c syscall.RawConn) error {

Check warning on line 13 in control_unix.go

View check run for this annotation

Codecov / codecov/patch

control_unix.go#L13

Added line #L13 was not covered by tests
var errSetOpts error

err := c.Control(func(fd uintptr) {
Expand Down
7 changes: 4 additions & 3 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewTestServerWithDriver(t *testing.T, driver *TestServerDriver) *FtpServer
if err := os.MkdirAll(dir, 0750); err != nil {
panic(err)
}

driver.fs = afero.NewBasePathFs(afero.NewOsFs(), dir)
}

Expand Down Expand Up @@ -342,12 +343,12 @@ func (driver *TestServerDriver) GetTLSConfig() (*tls.Config, error) {
return nil, errNoTLS
}

func (driver *TestServerDriver) PreAuthUser(cc ClientContext, user string) error {
func (driver *TestServerDriver) PreAuthUser(cc ClientContext, _ string) error {
return cc.SetTLSRequirement(driver.TLSRequirement)
}

func (driver *TestServerDriver) VerifyConnection(cc ClientContext, user string,
tlsConn *tls.Conn) (ClientDriver, error) {
func (driver *TestServerDriver) VerifyConnection(_ ClientContext, _ string,
_ *tls.Conn) (ClientDriver, error) {
switch driver.TLSVerificationReply {
case tlsVerificationFailed:
return nil, errInvalidTLSCertificate
Expand Down
2 changes: 1 addition & 1 deletion handle_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *clientHandler) handlePASS(param string) error {

c.writeMessage(StatusNotLoggedIn, msg)
c.disconnect()
case err == nil:
default: // err == nil && c.driver != nil
if msg == "" {
msg = "Password ok, continue"
}
Expand Down
4 changes: 2 additions & 2 deletions handle_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *clientHandler) handleRMDIR(params string) {
}
}

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

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

return nil
Expand Down
3 changes: 3 additions & 0 deletions handle_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (c *clientHandler) doFileTransfer(tr net.Conn, file io.ReadWriter, write bo
"Stream copy finished",
"writtenBytes", written,
)

if written == 0 {
_, err = out.Write([]byte{})
}
Expand Down Expand Up @@ -293,6 +294,7 @@ func (c *clientHandler) handleCHOWN(params string) {
{
usergroup := strings.Split(spl[0], ":")
userName := usergroup[0]

if id, err := strconv.ParseInt(userName, 10, 32); err == nil {
userID = int(id)
} else {
Expand Down Expand Up @@ -432,6 +434,7 @@ func (c *clientHandler) handleSTATFile(param string) error {

return nil
}

files, errList = directory.Readdir(-1)
c.closeDirectory(directoryPath, directory)
}
Expand Down
10 changes: 5 additions & 5 deletions handle_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func (c *clientHandler) handlePROT(param string) error {
return nil
}

func (c *clientHandler) handlePBSZ(param string) error {
func (c *clientHandler) handlePBSZ(_ string) error {
c.writeMessage(StatusOK, "Whatever")

return nil
}

func (c *clientHandler) handleSYST(param string) error {
func (c *clientHandler) handleSYST(_ string) error {
if c.server.settings.DisableSYST {
c.writeMessage(StatusCommandNotImplemented, "SYST is disabled")

Expand Down Expand Up @@ -177,7 +177,7 @@ func (c *clientHandler) handleOPTS(param string) error {
return nil
}

func (c *clientHandler) handleNOOP(param string) error {
func (c *clientHandler) handleNOOP(_ string) error {
c.writeMessage(StatusOK, "OK")

return nil
Expand All @@ -190,7 +190,7 @@ func (c *clientHandler) handleCLNT(param string) error {
return nil
}

func (c *clientHandler) handleFEAT(param string) error {
func (c *clientHandler) handleFEAT(_ string) error {
c.writeLine(fmt.Sprintf("%d- These are my features", StatusSystemStatus))
defer c.writeMessage(StatusSystemStatus, "end")

Expand Down Expand Up @@ -272,7 +272,7 @@ func (c *clientHandler) handleTYPE(param string) error {
return nil
}

func (c *clientHandler) handleQUIT(param string) error {
func (c *clientHandler) handleQUIT(_ string) error {
c.transferWg.Wait()

var msg string
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (server *FtpServer) Listen() error {

return err
}

if server.settings.TLSRequired == ImplicitEncryption {
// implicit TLS
var tlsConfig *tls.Config
Expand All @@ -184,6 +185,7 @@ func (server *FtpServer) Listen() error {

return err
}

server.listener = tls.NewListener(server.listener, tlsConfig)
}
}
Expand Down
2 changes: 1 addition & 1 deletion transfer_pasv.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *clientHandler) findListenerWithinPortRange(portRange *PortRange) (*net.
return nil, ErrNoAvailableListeningPort
}

func (c *clientHandler) handlePASV(param string) error {
func (c *clientHandler) handlePASV(_ string) error {
command := c.GetLastCommand()
addr, _ := net.ResolveTCPAddr("tcp", ":0")
var tcpListener *net.TCPListener
Expand Down
5 changes: 3 additions & 2 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func ftpUpload(t *testing.T, ftp *goftp.Client, file io.ReadSeeker, filename str
if strings.HasSuffix(stats.Name(), filename) {
found = true
}

if !found {
t.Fatal("STAT: Couldn't find file !")
}
Expand Down Expand Up @@ -959,7 +960,7 @@ func TestPASVPublicIPResolver(t *testing.T) {
require.NoError(t, err, "Couldn't open raw connection")

s.settings.PublicHost = ""
s.settings.PublicIPResolver = func(cc ClientContext) (string, error) {
s.settings.PublicIPResolver = func(_ ClientContext) (string, error) {
return "127.0.0", nil
}
// we crash if the PublicIPResolver returns an invalid IP, this must be fixed outside the lib
Expand All @@ -968,7 +969,7 @@ func TestPASVPublicIPResolver(t *testing.T) {
require.Equal(t, StatusServiceNotAvailable, rc)
require.Contains(t, resp, "invalid passive IP")

s.settings.PublicIPResolver = func(cc ClientContext) (string, error) {
s.settings.PublicIPResolver = func(_ ClientContext) (string, error) {
return "", errConnectionNotAllowed
}

Expand Down
Loading