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

Merged
merged 5 commits into from
May 14, 2025
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
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Canonical reference for changes, improvements, and bugfixes for mql.
* feat: add support for table column mapping by @dlclark in [[PR](https://github.com/hashicorp/mql/pull/45)]
* feat: add support for table column name from struct tags @terminalfi in [[PR](https://github.com/hashicorp/mql/pull/50)]
* chore: update deps by @jimlambrt in [[PR](https://github.com/hashicorp/mql/pull/54)]
* ci: run linter during PR build in [[PR](https://github.com/hashicorp/mql/pull/52)]
* chore: fix various lint issues in [[PR](https://github.com/hashicorp/mql/pull/52)]

## 0.1.4 (2024/05/14)

Expand Down
3 changes: 1 addition & 2 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ 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 {
// intentionally not checking raw, since can be an empty string
case lExpr == nil:
if lExpr == nil {
return nil, fmt.Errorf("%s: %w (missing expression)", op, ErrInvalidParameter)
}
logicalOp := lExpr.logicalOp
Expand Down
18 changes: 9 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
finalDelimiter = true
break WriteToBuf
default: // otherwise, write the rune into the keyword buffer
Expand All @@ -160,7 +160,7 @@ WriteToBuf:
// orToken, andToken, containsToken
func lexSymbolState(l *lexer) (lexStateFunc, error) {
const op = "mql.lexSymbolState"
panicIfNil(l, "lexSymbolState", "lexer")
panicIfNil(l, op, "lexer")
defer l.current.clear()

ReadRunes:
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:
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
if m.Kind() != reflect.Struct {
m = model.Elem()
}
Expand Down
Loading