Skip to content

Commit

Permalink
make: set up makefile, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Mar 24, 2024
1 parent 6e7d055 commit 39131c2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage.out
52 changes: 52 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
linters:
presets:
- bugs
- comment
- complexity
- error
- format
- import
- metalinter
- module
- performance
- sql
- style
- test
- unused
disable:
- godox # We allow TODO lines.
- tagliatelle # As we're dealing with third parties we must accept snake case.
- wsl # We don't agree with wsl's style rules
- exhaustruct
- lll
- varnamelen
- nlreturn
- gomnd
- goerr113
- wrapcheck # TODO: we should probably enable this one (at least for new code).
- testpackage
- nolintlint # see https://github.com/golangci/golangci-lint/issues/3228.
- depguard # disabling temporarily
- ireturn # disabling temporarily

linters-settings:
cyclop:
max-complexity: 12
funlen:
lines: 120
depguard:
list-type: denylist
packages:
- github.com/samber/lo # Use exp packages or internal utilities instead.
additional-guards:
- list-type: denylist
include-go-root: false
packages:
- github.com/stretchr/testify
# Specify rules by which the linter ignores certain files for consideration.
ignore-file-rules:
- "**/*_test.go"
- "**/mock/**/*.go"
run:
skip-dirs:
- 'exp'
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file contains convenience targets for the project.
# It is not intended to be used as a build system.
# See the README for more information.

.PHONY: test
test:
go test ./...

.PHONY: lint
lint: lint-deps
golangci-lint run --color=always --sort-results ./...

.PHONY: lint-fix
lint-fix:
golangci-lint run --fix --skip-dirs=./exp ./...

.PHONY: test-race
test-race:
go run test -race ./...

.PHONY: test-cover
test-cover:
go run test -cover ./...

.PHONY: lint-deps
lint-deps:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo >&2 "golangci-lint not found. Installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1; \
}

6 changes: 4 additions & 2 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func ExampleMessageGraph() {
return append(state,
llms.TextParts(schema.ChatMessageTypeAI, r.Choices[0].Content),
), nil

})
g.AddNode(graph.END, func(ctx context.Context, state []llms.MessageContent) ([]llms.MessageContent, error) {
return state, nil
Expand Down Expand Up @@ -58,6 +57,7 @@ func ExampleMessageGraph() {
}

func TestMessageGraph(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
buildGraph func() *graph.MessageGraph
Expand Down Expand Up @@ -140,7 +140,9 @@ func TestMessageGraph(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
g := tc.buildGraph()
runnable, err := g.Compile()
if err != nil {
Expand All @@ -152,7 +154,7 @@ func TestMessageGraph(t *testing.T) {

output, err := runnable.Invoke(context.Background(), tc.inputMessages)
if err != nil {
if tc.expectedError == nil || fmt.Sprint(err) != fmt.Sprint(tc.expectedError) {
if tc.expectedError == nil || err.Error() != tc.expectedError.Error() {
t.Fatalf("unexpected invoke error: '%v', expected '%v'", err, tc.expectedError)
}
return
Expand Down

0 comments on commit 39131c2

Please sign in to comment.