Skip to content

add ci linting and fix existing lint errors #52

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
15 changes: 10 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ jobs:
- name: Test
run: |
go test ./... -race

- name: Coverage
run: |
make coverage-diff


- name: Lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
with:
args: --timeout=5m

vulncheck:
name: Vulnerability Check
runs-on: ubuntu-latest
Expand All @@ -56,12 +61,12 @@ jobs:

- name: Check out code into the Go module directory
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: go mod package cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-122-${{ hashFiles('tests/go.mod') }}

- name: govulncheck
uses: golang/govulncheck-action@7da72f730e37eeaad891fcff0a532d27ed737cd4 # v1
- name: govulncheck
uses: golang/govulncheck-action@7da72f730e37eeaad891fcff0a532d27ed737cd4 # v1
4 changes: 2 additions & 2 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func (l *logicalExpr) String() string {
// root will return the root of the expr tree
func root(lExpr *logicalExpr, raw string) (expr, error) {
const op = "mql.root"
switch {
switch lExpr {
// intentionally not checking raw, since can be an empty string
case lExpr == nil:
case nil:
Comment on lines -169 to +171
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

expr.go:169:2: QF1002: could use tagged switch on lExpr (staticcheck)
	switch {
	^

return nil, fmt.Errorf("%s: %w (missing expression)", op, ErrInvalidParameter)
}
logicalOp := lExpr.logicalOp
Expand Down
17 changes: 8 additions & 9 deletions lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,24 @@ WriteToBuf:
// keep reading runes into the buffer until we encounter eof or the final delimiter.
for {
r = l.read()
switch {
case r == eof:
switch r {
case eof:
break WriteToBuf
case r == backslash:
case backslash:
nextR := l.read()
switch {
case nextR == eof:
switch nextR {
case eof:
tokenBuf.WriteRune(r)
return nil, fmt.Errorf("%s: %w in %q", op, ErrInvalidTrailingBackslash, tokenBuf.String())
case nextR == backslash:
case backslash:
tokenBuf.WriteRune(nextR)
case nextR == delimiter:
case delimiter:
tokenBuf.WriteRune(nextR)
default:
tokenBuf.WriteRune(r)
tokenBuf.WriteRune(nextR)
}
case r == delimiter: // end of the quoted string we're scanning
case delimiter: // end of the quoted string we're scanning
Comment on lines -126 to +143
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

lex.go:126:3: QF1002: could use tagged switch on r (staticcheck)
		switch {
		^
lex.go:131:4: QF1002: could use tagged switch on nextR (staticcheck)
			switch {
			^

finalDelimiter = true
break WriteToBuf
default: // otherwise, write the rune into the keyword buffer
Expand All @@ -159,7 +159,6 @@ WriteToBuf:
// lexSymbolState scans for strings and can emit the following tokens:
// orToken, andToken, containsToken
func lexSymbolState(l *lexer) (lexStateFunc, error) {
const op = "mql.lexSymbolState"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

lex.go:162:8: const op is unused (unused)
	const op = "mql.lexSymbolState"
	      ^

Let me know if leaving this in adds any value. Other functions declare an op to be used in lexing error strings.

panicIfNil(l, "lexSymbolState", "lexer")
defer l.current.clear()

Expand Down
6 changes: 3 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func (p *parser) parseComparisonExpr() (expr, error) {
case cmpExpr.value == nil && (p.currentToken.Type != stringToken && p.currentToken.Type != numberToken && p.currentToken.Type != symbolToken):
return nil, fmt.Errorf("%s: %w %q in: %q", op, ErrUnexpectedToken, p.currentToken.Value, p.raw)
case cmpExpr.value == nil:
switch {
case p.currentToken.Type == symbolToken:
switch p.currentToken.Type {
case symbolToken:
return nil, fmt.Errorf("%s: %w %s == %s (expected: %s or %s) in %q", op, ErrInvalidComparisonValueType, p.currentToken.Type, p.currentToken.Value, stringToken, numberToken, p.raw)
case p.currentToken.Type == stringToken, p.currentToken.Type == numberToken:
case stringToken, numberToken:
Comment on lines -187 to +190
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

parser.go:187:4: QF1002: could use tagged switch on p.currentToken.Type (staticcheck)
			switch {
			^

s := p.currentToken.Value
cmpExpr.value = &s
default:
Expand Down
2 changes: 1 addition & 1 deletion validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func fieldValidators(model reflect.Value, opt ...Option) (map[string]validator,
model.Kind() == reflect.Pointer && model.Elem().Kind() != reflect.Struct:
return nil, fmt.Errorf("%s: model must be a struct or a pointer to a struct: %w", op, ErrInvalidParameter)
}
var m reflect.Value = model
m := model
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

validate.go:35:8: ST1023: should omit type reflect.Value from declaration; it will be inferred from the right-hand side (staticcheck)
	var m reflect.Value = model
	      ^

if m.Kind() != reflect.Struct {
m = model.Elem()
}
Expand Down
Loading