-
-
Notifications
You must be signed in to change notification settings - Fork 234
feat: add linting to go backend #845
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| version: "2" | ||
| linters: | ||
| settings: | ||
| errcheck: | ||
| exclude-functions: | ||
| - (http.ResponseWriter).Write | ||
| - (http.ResponseWriter).WriteString | ||
| - (github.com/gin-gonic/gin.ResponseWriter).Write | ||
| - (github.com/gin-gonic/gin.ResponseWriter).WriteString | ||
| exclusions: | ||
| rules: | ||
| - linters: | ||
| - errcheck | ||
| text: "//nolint:errcheck" | ||
| - linters: | ||
| - staticcheck | ||
| text: "//nolint:staticcheck" | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -292,7 +292,7 @@ func (app *BootstrapApp) heartbeatRoutine() { | |||||
| continue | ||||||
| } | ||||||
|
|
||||||
| res.Body.Close() | ||||||
| res.Body.Close() //nolint:errcheck | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Missing The 🐛 Proposed fix- res.Body.Close() //nolint:errcheck
+ defer res.Body.Close() //nolint:errcheck📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| if res.StatusCode != 200 && res.StatusCode != 201 { | ||||||
| tlog.App.Debug().Str("status", res.Status).Msg("Heartbeat returned non-200/201 status") | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ func TestReadFile(t *testing.T) { | |
|
|
||
| err = file.Close() | ||
| require.NoError(t, err) | ||
| defer os.Remove("/tmp/tinyauth_test_file") | ||
| defer os.Remove("/tmp/tinyauth_test_file") //nolint:errcheck | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid fixed Line 21 uses cleanup for a hardcoded path, which can conflict with parallel test execution. Use 🤖 Prompt for AI Agents |
||
|
|
||
| // Normal case | ||
| content, err := ReadFile("/tmp/tinyauth_test_file") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ func TestGetSecret(t *testing.T) { | |
|
|
||
| err = file.Close() | ||
| require.NoError(t, err) | ||
| defer os.Remove("/tmp/tinyauth_test_secret") | ||
| defer os.Remove("/tmp/tinyauth_test_secret") //nolint:errcheck | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use test-scoped temp files instead of a fixed Line 22 still cleans up a globally fixed file path, which can collide across concurrent test runs and cause flakes. Prefer Suggested change- file, err := os.Create("/tmp/tinyauth_test_secret")
+ tmpDir := t.TempDir()
+ secretPath := tmpDir + "/tinyauth_test_secret"
+ file, err := os.Create(secretPath)
require.NoError(t, err)
// ...
- defer os.Remove("/tmp/tinyauth_test_secret") //nolint:errcheck
+ defer os.Remove(secretPath) //nolint:errcheck
- assert.Equal(t, "secret", utils.GetSecret("", "/tmp/tinyauth_test_secret"))
+ assert.Equal(t, "secret", utils.GetSecret("", secretPath))🤖 Prompt for AI Agents |
||
|
|
||
| // Get from config | ||
| assert.Equal(t, "mysecret", utils.GetSecret("mysecret", "")) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: tinyauthapp/tinyauth
Length of output: 125
🌐 Web query:
golangci-lint v2 configuration format exclusions rules documentation💡 Result:
golangci-lint v2 uses YAML, TOML, or JSON configuration files (.golangci.yml,.golangci.yaml,.golangci.toml,.golangci.json) with version: "2" at the top.[1][2] Exclusions are configured under the top-level linters.exclusions section.[1][3][4] Key exclusion options: - generated: Controls exclusion of generated files (strict, lax, auto, disable). Default: lax.[1] - warn-unused: Log warning if exclusion rule unused. Default: false.[1] - presets: Predefined exclusion sets like comments, std-error-handling, common-false-positives, legacy.[1][5] - rules: Array of fine-grained exclusion rules matching by path, path-except, text, source, and/or linters (regex patterns).[1][3][4] Example excluding specific linters on test files:
linters: exclusions: rules: - path: _test\\.go linters: - gocyclo - errcheck - dupl - gosec[1][4] Example excluding by text and source:- linters: [lll] source: "^//go:generate "[1][4] Example path-except (exclude everywhere except tests):- path-except: _test\\.go linters: [forbidigo][1] - paths: File/directory paths to exclude issues from (regex, OS separator normalized). Default: [].[1] - paths-except: Paths not to exclude.[1] Patterns use regex (not globs); escape dots like \. in _test\.go. Paths can use placeholders like ${base-path}, ${config-path}.[6][1] Separate exclusions exist for formatters.formatters.exclusions.[5] See official docs for full details: https://golangci-lint.run/docs/configuration/file/ [1][2], false positives: https://golangci-lint.run/docs/linters/false-positives/ [3][4], migration from v1: https://golangci-lint.run/docs/product/migration-guide/ [7]. Reference config: https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml [8].Citations:
🌐 Web query:
golangci-lint //nolint directive native support how it works💡 Result:
golangci-lint has native support for //nolint directives. It works by parsing “directive comments” in Go source files and then filtering/removing reported issues that match the directive’s scope (line, block, or file) and the specified linter list. 1) The supported //nolint syntaxes and scopes - Directives are not arbitrary comments; golangci-lint treats them as machine-readable “directive comments” matching the Go directive/comment syntax [1]. - Use exact machine syntax with no spaces in the critical positions, e.g. //nolint:xxx (not // nolint:xxx) [1]. - Excluding all linters: //nolint:all. If used inline (on the same line as the code), it suppresses issues only for that line [1]. Example: var bad_name int //nolint:all [1] - Excluding specific linters: //nolint:, (comma-separated). Example: //nolint:wsl,unused [1]. - Excluding a whole block: place the directive at the beginning of a line, e.g. at the start of a function or before a var block [1]. Example: //nolint:all func... {... } [1] and //nolint:govet var (...) [1] - Excluding whole files: place //nolint: at the beginning of the file, e.g. before the package declaration [1]. Example: //nolint:unparam package pkg [1] 2) How golangci-lint applies the directive to reported issues (how it “works”) - golangci-lint includes a dedicated processing stage for nolint directives (a “nolint filter”), which removes issues from the final results when an issue’s FromLinter and position match a nolint directive in scope. This is tested in the nolint filter unit tests, which construct a nolint filter and assert that issues are removed from results when a directive applies [2]. 3) Validation / correctness of directives (nolintlint) - There is also a “nolintlint” linter that checks that //nolint directives are well-formed and (optionally) properly explained. - The nolintlint package README describes its purpose: ensuring nolint exceptions have explanations and enforcing machine-readable formatting like //nolint:all and specifying which linter is suppressed (e.g. //nolint:gosec) [3]. Practical takeaway - If your goal is to suppress a specific set of warnings, prefer //nolint: (or //nolint:all) rather than disabling via configuration; and place it inline for single-line suppression, at the beginning of a line for block/file suppression [1]. If you want, paste a small code example (where the directive is placed) and I’ll explain exactly which issues it should suppress according to these rules.
Citations:
🏁 Script executed:
Repository: tinyauthapp/tinyauth
Length of output: 635
Remove the
exclusionssection—it's misconfigured and won't work.The
exclusions.rulesconfiguration uses thetextfield to match against lint error message text, not source code comments. The literal string"//nolint:errcheck"will never appear in actual lint error messages, so these rules won't exclude anything.More importantly, golangci-lint natively supports
//nolint:<linter>directives in your source code, which already suppress warnings without requiring exclusion rules. Delete the entireexclusionssection (lines 10–17).🤖 Prompt for AI Agents