Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ jobs:

- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-version: '1.26'
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.10
version: v2.11
only-new-issues: true
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-version: '1.26'

- uses: actions/checkout@v6
with:
Expand Down
206 changes: 206 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# https://golangci-lint.run/usage/configuration/

# options for analysis running
# https://golangci-lint.run/usage/configuration/#run-configuration
version: "2"

run:
# include test files or not, default is true
tests: true

# by default isn't set. If set we pass it to "go list -mod={option}". From "go
# help modules": If invoked with -mod=readonly, the go command is disallowed
# from the implicit automatic updating of go.mod described above. Instead, it
# fails when any changes to go.mod are needed. This setting is most useful to
# check that go.mod does not need updates, such as in a continuous integration
# and testing system. If invoked with -mod=vendor, the go command assumes that
# the vendor directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: vendor

# Allow multiple parallel golangci-lint instances running. If false,
# golangci-lint acquires file lock on start.
allow-parallel-runners: true

# Number of operating system threads (`GOMAXPROCS`) that can execute
# golangci-lint simultaneously. If it is explicitly set to 0 (i.e. not the
# default) then golangci-lint will automatically set the value to match Linux
# container CPU quota.
concurrency: 2

linters:
# Default set of linters.
# The value can be: `standard`, `all`, `none`, or `fast`.
# Default: standard
default: standard

# Enable specific linters.
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- govet
- revive
- unused
- errcheck
- staticcheck
- ineffassign
- unconvert
- misspell
- lll
- nakedret
- gocritic
- nolintlint
- gocyclo
- copyloopvar
- usestdlibvars

# all available settings of specific linters
settings:
# https://golangci-lint.run/usage/linters/#lll
lll:
# max line length, lines longer will be reported. Default is 120. '\t' is
# counted as 1 character by default and can be changed with the tab-width
# option
line-length: 120

# Tab width in spaces.
tab-width: 2

# https://golangci-lint.run/usage/linters/#gocyclo
gocyclo:
# Using a high number for now only to cover the existing codebase. We
# already have a plan to target a lower number. The value was chosen from
# the following command execution:
#
# gocyclo -top 1 .
min-complexity: 65

# https://golangci-lint.run/usage/linters/#revive
revive:
# Maximum number of open files at the same time.
max-open-files: 1024

# Run `GL_DEBUG=revive golangci-lint run --enable-only=revive` to see default, all available rules, and enabled rules.
rules:
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#constant-logical-expr
- name: constant-logical-expr
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#datarace
- name: datarace
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#exported
- name: exported
arguments:
- disableStutteringCheck
- disableChecksOnTypes
- disableChecksOnVariables
- disableChecksOnConstants
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#if-return
- name: if-return
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#redundant-import-alias
- name: redundant-import-alias
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#superfluous-else
- name: superfluous-else
arguments:
- preserveScope
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unreachable-code
- name: unreachable-code
severity: warning
disabled: false
exclude:
- ""

# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
arguments:
- allowRegex: ^_
severity: warning
disabled: false
exclude:
- ""

# https://golangci-lint.run/usage/linters/#unused
unused:
# Mark all struct fields that have been written to as used.
# Setting it to 'false' will report fields with writes but no reads (it might have false positives)
# Default: true
field-writes-are-uses: true
# Mark all exported fields as used.
# default: true
exported-fields-are-used: false
# Mark all local variables as used.
# default: true
local-variables-are-used: false

# Defines a set of rules to ignore issues.
# It does not skip the analysis, and so does not ignore "typecheck" errors.
exclusions:
# Mode of the generated files analysis.
#
# - `strict`: sources are excluded by strictly following the Go generated file convention.
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
# This line must appear before the first non-comment, non-blank text in the file.
# https://go.dev/s/generatedcode
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
# - `disable`: disable the generated files exclusion.
#
# Default: lax
generated: lax

# Log a warning if an exclusion rule is unused.
# Default: false
warn-unused: true

issues:
# Maximum count of issues with the same text. Setting this to zero will disable
# any limits, meaning all errors will be reported. This is useful if a linter
# always produces the same error message, or else some errors might be filtered
max-same-issues: 0

formatters:
# Enable specific formatter.
# Default: [] (uses standard Go formatting)
enable:
- goimports

# Defines a set of rules to ignore issues.
# It does not skip the analysis, and so does not ignore "typecheck" errors.
exclusions:
# Mode of the generated files analysis.
#
# - `strict`: sources are excluded by strictly following the Go generated file convention.
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
# This line must appear before the first non-comment, non-blank text in the file.
# https://go.dev/s/generatedcode
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
# - `disable`: disable the generated files exclusion.
#
# Default: lax
generated: lax
14 changes: 7 additions & 7 deletions docparse/docparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,18 @@ type Ref struct {
// Main reason to store as a string (and Refs as a map) for now is so that
// it looks pretties in the pretty.Print() output. May not want to keep
// this.
Reference string //*Reference
Reference string // *Reference
}

// Param is a path, query, or form parameter.
type Param struct {
Name string // Parameter name
//Info string // Detailed description
//Required bool // Is this required to always be sent?
//Kind string // Type information
//KindEnum []string // Enum fields, only when Kind=enum.
//Format string // Format, such as "email", "date", etc.
//Ref string // Reference something else; for Kind=struct and Kind=array.
// Info string // Detailed description
// Required bool // Is this required to always be sent?
// Kind string // Type information
// KindEnum []string // Enum fields, only when Kind=enum.
// Format string // Format, such as "email", "date", etc.
// Ref string // Reference something else; for Kind=struct and Kind=array.

KindField *ast.Field // Type information from struct field.
}
Expand Down
2 changes: 1 addition & 1 deletion docparse/docparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Response 400 (w00t): {empty}
}},
},

//{"err-double-code", `
// {"err-double-code", `
// POST /path

// Response 200: {empty}
Expand Down
2 changes: 1 addition & 1 deletion docparse/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func GetReference(prog *Program, context string, isEmbed bool, lookup, filePath
split := strings.Split(p.Reference, ".")
lookupStruct := strings.Join(split[:len(split)-1], ".")
if lookupStruct != "" {
lookupStruct = lookupStruct + "."
lookupStruct += "."
}

for i, f := range ref.Fields {
Expand Down
16 changes: 14 additions & 2 deletions docparse/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package docparse
import (
"io"
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"

"github.com/teamwork/test"
Expand Down Expand Up @@ -47,7 +48,7 @@ func TestFindType(t *testing.T) {
if pkg != "net/http" {
t.Fatalf("pkg == %v", pkg)
}
if path != filepath.Join(runtime.GOROOT(), "src", "net", "http", "header.go") {
if path != filepath.Join(goroot(t), "src", "net", "http", "header.go") {
t.Fatalf("path == %v", path)
}

Expand Down Expand Up @@ -126,3 +127,14 @@ func TestFindType(t *testing.T) {
}
})
}

// goroot is a small helper to get the GOROOT environment variable.
func goroot(t *testing.T) string {
t.Helper()

out, err := exec.Command("go", "env", "GOROOT").Output()
if err != nil {
t.Fatalf("go env GOROOT: %v", err)
}
return strings.TrimSpace(string(out))
}
11 changes: 5 additions & 6 deletions docparse/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,10 @@ start:
pkg = importPath
}

switch resolvType := ts.Type.(type) {
case *ast.ArrayType:
if resolvType, ok := ts.Type.(*ast.ArrayType); ok {
isEnum := p.Type == "enum"
p.Type = "array"
err := resolveArray(prog, ref, pkg, &p, resolvType.Elt, isEnum, generics)
if err != nil {
if err = resolveArray(prog, ref, pkg, &p, resolvType.Elt, isEnum, generics); err != nil {
return nil, err
}

Expand Down Expand Up @@ -489,7 +487,8 @@ start:
default:
return nil, fmt.Errorf("unknown generic type: %T", typ.X)
}
if err := fillGenericsSchema(prog, &p, tagName, ref, genericsPkg, genericsIdent, generics, typ.Indices...); err != nil {
err = fillGenericsSchema(prog, &p, tagName, ref, genericsPkg, genericsIdent, generics, typ.Indices...)
if err != nil {
return nil, fmt.Errorf("generic fieldToSchema: %v", err)
}
return &p, nil
Expand Down Expand Up @@ -527,7 +526,7 @@ start:

// fillGenericsSchema fills the schema with the generic type information. As the
// types can be different for every generics declaration they will need to be a
// anonymos object in the schema output instead of a reusable reference.
// anonymous object in the schema output instead of a reusable reference.
func fillGenericsSchema(
prog *Program,
p *Schema,
Expand Down
3 changes: 2 additions & 1 deletion docparse/test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// nolint
package docparse

// For tests. We don't parse test files.

// testObject general documentation.
//
//nolint:unused
type testObject struct {
// ID documentation {required}.
ID int
Expand Down
3 changes: 1 addition & 2 deletions docparse/testdata/src/a/a.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// nolint
package a

import "net/mail"
Expand Down Expand Up @@ -38,7 +37,7 @@ type foo struct {
// {enum: one two three
// four five six seven}
docs string
//m map[string]int
// m map[string]int
}

type nested struct {
Expand Down
2 changes: 1 addition & 1 deletion example/example.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint
//nolint:unused,revive
package example

import (
Expand Down
2 changes: 1 addition & 1 deletion example/unified.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint
//nolint:unused,revive
package example

// Single entity response.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/teamwork/kommentaar

go 1.25.0
go 1.26

require (
github.com/imdario/mergo v0.3.13
Expand Down
Loading
Loading