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(lint): Increasing lint difficulty level #370

Merged
merged 31 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b82b51a
chore(lint): Adding linters for future code
fclairamb Sep 24, 2022
b80e0f5
other files
fclairamb Sep 24, 2022
1b74dcd
Merge branch 'main' into chore/lint
fclairamb Sep 25, 2022
05fe03c
this should allow to see diff
fclairamb Sep 25, 2022
7fa3f50
Merge branch 'chore/lint' of https://github.com/fclairamb/ftpserverli…
fclairamb Sep 25, 2022
ef41e2a
chore(lint): Wrapping all errors
fclairamb Sep 25, 2022
36fd659
fix
fclairamb Sep 25, 2022
93dd3a1
fixing test
fclairamb Sep 25, 2022
26f04e4
few changes
fclairamb Sep 25, 2022
6540c4a
backup commit
fclairamb May 31, 2023
30eaa09
Merge branch 'main' into chore/lint
fclairamb May 31, 2023
e202f9e
Merge branch 'main' of https://github.com/fclairamb/ftpserverlib into…
fclairamb Mar 2, 2024
4e934cb
Fixed all lint errors
fclairamb Mar 2, 2024
35dae8c
re-enabling tests
fclairamb Mar 2, 2024
4d7c663
Adding gosimple
fclairamb Mar 2, 2024
b8e8124
Moving some code to reduce cyclomatic complexity
fclairamb Mar 3, 2024
fb67573
dupword
fclairamb Mar 3, 2024
f018bb5
various changes
fclairamb Mar 3, 2024
a4627d3
progress
fclairamb Mar 3, 2024
1dfdf82
temporaryError simplification
fclairamb Mar 3, 2024
7ca9755
More linting code improvements
fclairamb Mar 3, 2024
bae3ef9
updates
fclairamb Mar 3, 2024
577081d
Merge branch 'main' into chore/lint
fclairamb Mar 4, 2024
b29a671
update
fclairamb Mar 9, 2024
7757ae8
progress
fclairamb Mar 10, 2024
d60471d
handleUSER reorg
fclairamb Mar 10, 2024
1152f8f
progress
fclairamb Mar 10, 2024
b48ecad
progress
fclairamb Mar 10, 2024
f5571b7
progress
fclairamb Mar 10, 2024
58e4978
progress 😅😅😅
fclairamb Mar 10, 2024
ffcde43
progress
fclairamb Mar 10, 2024
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
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
push:
branches:
- main
- chore/lint-*
- chore/lint*
pull_request:

permissions:
Expand All @@ -26,7 +26,7 @@ jobs:

strategy:
matrix:
go: [ '1.22', '1.21', '1.20' ]
go: [ '1.22', '1.21' ]
include:
- go: '1.22'
lint: true
Expand Down Expand Up @@ -54,11 +54,7 @@ jobs:
run: go build -v ./...

- name: Test
# We need GCC because of the "go test -race"
# env:
# CGO_ENABLED: 0
run: |
apt-get update && apt-get install gcc -y
go test -parallel 20 -v -race -coverprofile=coverage.txt -covermode=atomic ./...
bash <(curl -s https://codecov.io/bash)

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ ftpserver
.idea
.vscode
debug
__debug_bin
__debug_bin*
*.toml
79 changes: 75 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,61 +160,128 @@ linters-settings:
linters:
disable-all: true
enable:
# https://golangci-lint.run/usage/linters/
- asciicheck
- asasalint
- bidichk
- bodyclose
# - deadcode -> unused
- containedctx
# - contextcheck -> creates an odd error here: https://github.com/fclairamb/ftpserverlib/blob/4d7c663e9e0b2650673fc2e0fcdb443895f2a1b9/server.go#L234
# - copyloopvar -> unknown in v1.56.2 ???
# - cyclop -> Delaying it for now (too much work)
- decorder
- depguard
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- exhaustive
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
# - exhaustruct --> Not convinced it's useful
# - exhaustivestruct
- exportloopref
- funlen
# - gci
- forbidigo
- forcetypeassert
- gci
- ginkgolinter
- gochecknoinits
# - gochecknoglobals
- gochecksumtype
- gochecknoglobals
- gocognit
- goconst
- gocritic
- gocyclo
# - godot --> lots of not so useful changes
- godox
- goerr113
- gofmt
# - gofumpt -> conflicts with wsl
- goimports
- gosimple
# - golint --> revive
- revive
# - gomnd
# - gomnd --> too much work
# - gomoddirectives
# - gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- gosimple
- govet
- grouper
- ineffassign
- importas
- inamedparam
# - intrange --> upcoming
# - interfacebloat
# - interfacer --> (deprecated)
# - ireturn --> I can't even see how to fix those like ClientHandler::getFileHandle
- lll
- loggercheck
- maintidx
- makezero
- mirror
# - maligned --> govet:fieldalignment
- megacheck
- misspell
- musttag
- nakedret
# - nestif
- nlreturn
- prealloc
- nestif
- nilerr
- nilnil
- nolintlint
- nlreturn
- rowserrcheck
- noctx
- nonamedreturns
# - scopelint --> exportloopref
- nosprintfhostport
- exportloopref
- staticcheck
# - structcheck -> unused
- stylecheck
# - paralleltest -> buggy, doesn't work with subtests
- typecheck
- perfsprint
- prealloc
- predeclared
- reassign
- promlinter
- protogetter
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
# - testpackage -> too late for that
- thelper
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- varnamelen
- wastedassign
# - varcheck -> unused
- whitespace
# - wrapcheck
# - wrapcheck -> too much effort for now
- wsl
# - zerologlint -> Will most probably never use it
fast: false

issues:
Expand All @@ -224,3 +291,7 @@ issues:
# Default value for this option is true.
exclude-use-default: false

exclude-rules:
- path: _test\.go
linters:
- gochecknoglobals
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ If you're interested in a fully featured FTP server, you should use [sftpgo](htt
The easiest way to test this library is to use [ftpserver](https://github.com/fclairamb/ftpserver).

## The driver
The simplest way to get a good understanding of how the driver shall be implemented, you can have a look at the [tests driver](https://github.com/fclairamb/ftpserverlib/blob/master/driver_test.go).
The simplest way to get a good understanding of how the driver shall be implemented is to look at the [tests driver](https://github.com/fclairamb/ftpserverlib/blob/master/driver_test.go).

### The base API

Expand Down
36 changes: 20 additions & 16 deletions asciiconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
const (
convertModeToCRLF convertMode = iota
convertModeToLF

bufferSize = 4096
)

type asciiConverter struct {
Expand All @@ -19,7 +21,7 @@
}

func newASCIIConverter(r io.Reader, mode convertMode) *asciiConverter {
reader := bufio.NewReaderSize(r, 4096)
reader := bufio.NewReaderSize(r, bufferSize)

return &asciiConverter{
reader: reader,
Expand All @@ -28,30 +30,32 @@
}
}

func (c *asciiConverter) Read(p []byte) (n int, err error) {
func (c *asciiConverter) Read(bytes []byte) (int, error) {
var data []byte
var readBytes int
var err error

if len(c.remaining) > 0 {
data = c.remaining
c.remaining = nil
} else {
data, _, err = c.reader.ReadLine()
if err != nil {
return n, err
return readBytes, err
}
}

n = len(data)
if n > 0 {
maxSize := len(p) - 2
if n > maxSize {
copy(p, data[:maxSize])
readBytes = len(data)
if readBytes > 0 {
maxSize := len(bytes) - 2
if readBytes > maxSize {
copy(bytes, data[:maxSize])
c.remaining = data[maxSize:]

return maxSize, nil
}

copy(p[:n], data[:n])
copy(bytes[:readBytes], data[:readBytes])
}

// we can have a partial read if the line is too long
Expand All @@ -64,22 +68,22 @@
// client transfers it in ASCII mode
err = c.reader.UnreadByte()
if err != nil {
return n, err
return readBytes, err

Check warning on line 71 in asciiconverter.go

View check run for this annotation

Codecov / codecov/patch

asciiconverter.go#L71

Added line #L71 was not covered by tests
}

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

if err == nil && lastByte == '\n' {
switch c.mode {
case convertModeToCRLF:
p[n] = '\r'
p[n+1] = '\n'
n += 2
bytes[readBytes] = '\r'
bytes[readBytes+1] = '\n'
readBytes += 2
case convertModeToLF:
p[n] = '\n'
n++
bytes[readBytes] = '\n'
readBytes++
}
}

return n, err
return readBytes, err //nolint:wrapcheck // here wrapping errors brings nothing
}
12 changes: 6 additions & 6 deletions asciiconverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ func TestASCIIConvert(t *testing.T) {
lines := []byte("line1\r\nline2\r\n\r\nline4")
src := bytes.NewBuffer(lines)
dst := bytes.NewBuffer(nil)
c := newASCIIConverter(src, convertModeToLF)
_, err := io.Copy(dst, c)
converter := newASCIIConverter(src, convertModeToLF)
_, err := io.Copy(dst, converter)
require.NoError(t, err)
require.Equal(t, []byte("line1\nline2\n\nline4"), dst.Bytes())

lines = []byte("line1\nline2\n\nline4")
dst = bytes.NewBuffer(nil)
c = newASCIIConverter(bytes.NewBuffer(lines), convertModeToCRLF)
_, err = io.Copy(dst, c)
converter = newASCIIConverter(bytes.NewBuffer(lines), convertModeToCRLF)
_, err = io.Copy(dst, converter)
require.NoError(t, err)
require.Equal(t, []byte("line1\r\nline2\r\n\r\nline4"), dst.Bytes())

Expand All @@ -31,8 +31,8 @@ func TestASCIIConvert(t *testing.T) {
}

dst = bytes.NewBuffer(nil)
c = newASCIIConverter(bytes.NewBuffer(buf), convertModeToCRLF)
_, err = io.Copy(dst, c)
converter = newASCIIConverter(bytes.NewBuffer(buf), convertModeToCRLF)
_, err = io.Copy(dst, converter)
require.NoError(t, err)
require.Equal(t, buf, dst.Bytes())
}
Expand Down
Loading
Loading