Skip to content

Commit

Permalink
add golangci config (#27)
Browse files Browse the repository at this point in the history
* add golangci config

* upgrade golangci ci version

* fewer gh actions

* remove comment

* fix lint

* lint

* add newline

* add newline

* remove unused line in golangci config
  • Loading branch information
mfleader authored Feb 1, 2024
1 parent 4ddd4e3 commit 67623c3
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Golang Test
on:
push:
branches:
- main
pull_request:

jobs:
Expand All @@ -13,8 +15,7 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3
with:
# Hard-coding version due to this bug: https://github.com/golangci/golangci-lint-action/issues/535
version: v1.51.2
version: v1.55.2
test:
name: go test
runs-on: ubuntu-latest
Expand Down
100 changes: 100 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
run:
timeout: 5m
linters:
enable:
# region General

# Add depguard to prevent adding additional dependencies. This is a client library, we really don't want
# additional dependencies.
- depguard
# Prevent improper directives in go.mod.
- gomoddirectives
# Prevent improper nolint directives.
- nolintlint

# endregion


# region Code Quality and Comments

# Inspect source code for potential security problems. This check has a fairly high false positive rate,
# comment with // nolint:gosec where not relevant.
- gosec
# Replace golint.
- revive
# Complain about deeply nested if cases.
- nestif
# Prevent naked returns in long functions.
- nakedret
# Make Go code more readable.
# - gocritic
# Check if comments end in a period. This helps prevent incomplete comment lines, such as half-written sentences.
# - godot
# Complain about comments as these indicate incomplete code.
- godox
# Keep the cyclomatic complexity of functions to a reasonable level.
- gocyclo
# Complain about cognitive complexity of functions.
- gocognit
# Find repeated strings that could be converted into constants.
# - goconst
# Complain about unnecessary type conversions.
- unconvert
# Complain about unused parameters. These should be replaced with underscores.
- unparam
# Check for non-ASCII identifiers.
- asciicheck
# Check for HTTP response body being closed. Sometimes, you may need to disable this using // nolint:bodyclose.
- bodyclose
# Check for duplicate code. You may want to disable this with // nolint:dupl if the source code is the same, but
# legitimately exists for different reasons.
# - dupl
# Check for pointers in loops. This is a typical bug source.
- exportloopref
# Enforce a reasonable function length of 60 lines or 40 instructions. In very rare cases you may want to disable
# this with // nolint:funlen if there is absolutely no way to split the function in question.
# - funlen
# Prevent dogsledding (mass-ignoring return values). This typically indicates missing error handling.
- dogsled
# Enforce consistent import aliases across all files.
- importas
# Make code properly formatted.
- gofmt
# Prevent faulty error checks.
- nilerr
# Prevent direct error checks that won't work with wrapped errors.
- errorlint
# Find slice usage that could potentially be preallocated.
- prealloc
# Check for improper duration handling.
- durationcheck
# Enforce tests being in the _test package.
# - testpackage
# - typecheck

# endregion
linters-settings:
revive:
severity: error
depguard:
rules:
main:
list-mode: strict
allow:
- $gostd
- go.flow.arcalot.io/
- go.arcalot.io/
- gopkg.in/yaml.v3
- github.com/fxamacker/cbor
govet:
enable-all: true
check-shadowing: false
disable:
# We don't care about variable shadowing.
- shadow
- fieldalignment
stylecheck:
checks:
- all
issues:
exclude-use-default: false
2 changes: 1 addition & 1 deletion expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func New(expressionString string) (Expression, error) {
}
exprAst, err := parser.ParseExpression()
if err != nil {
return nil, fmt.Errorf("failed to parse expression: %s (%v)", expressionString, err)
return nil, fmt.Errorf("failed to parse expression: %s (%w)", expressionString, err)
}

return &expression{
Expand Down
2 changes: 1 addition & 1 deletion expression_evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c evaluateContext) evaluate(node ast.Node, data any) (any, error) {
}
}

func (c evaluateContext) evaluateFuncCall(node *ast.FunctionCall, data any) (any, error) {
func (c evaluateContext) evaluateFuncCall(node *ast.FunctionCall, data any) (any, error) { //nolint:unparam
funcID := node.FuncIdentifier
functionSchema, found := c.functions[funcID.String()]
if !found {
Expand Down
2 changes: 1 addition & 1 deletion internal/ast/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
// WildcardToken represents a wildcard token '*'.
WildcardToken TokenID = "wildcard"
// ListSeparatorToken represents a comma in a parameter list
ListSeparatorToken TokenID = "list-separator"
ListSeparatorToken TokenID = "list-separator" //nolint:gosec // not a security credential
// UnknownToken is a placeholder for when there was an error in the token.
UnknownToken TokenID = "error"
)
Expand Down

0 comments on commit 67623c3

Please sign in to comment.