-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add internal test exports and improve golangci-lint configuration #31
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
c2610bb
663fb3c
c63f274
f479d28
165ba42
7683c18
9699cd8
5b9bccc
2118ac0
dece3c8
3d9c549
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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # Copyright the dmorph contributors. | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| # Configuration file for golangci-lint | ||
| # See https://golangci-lint.run/usage/configuration/ for more information | ||
|
|
||
|
|
@@ -9,25 +12,85 @@ run: | |
|
|
||
| linters: | ||
| default: all | ||
| #enable: | ||
| # # Default linters | ||
| # - errcheck | ||
| # - govet | ||
| # - ineffassign | ||
| # - staticcheck | ||
| # - unused | ||
| # # Additional linters | ||
| # - gosec | ||
| # - misspell | ||
| # - revive | ||
| # - bodyclose | ||
| # - noctx | ||
|
|
||
| disable: | ||
| - exhaustruct | ||
| - forbidigo | ||
| - noinlineerr | ||
| - nonamedreturns | ||
| - wsl | ||
| - wsl_v5 | ||
|
|
||
| exclusions: | ||
| warn-unused: true | ||
|
|
||
| rules: | ||
| - path: main_test.go | ||
| - path: _test\.go | ||
| linters: | ||
| - gosec | ||
| - cyclop | ||
| - dupl | ||
| - dupword | ||
| - err113 | ||
| - funlen | ||
| - gocognit | ||
| - maintidx | ||
| - nestif | ||
|
|
||
| - path: examples/ | ||
| linters: | ||
| - err113 | ||
|
|
||
|
Comment on lines
24
to
+42
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. 💡 Verification agent 🧩 Analysis chainMisplaced and non-standard: move “exclusions” under issues.exclude-rules The “exclusions” block and “warn-unused” aren’t valid under linters. Path- and linter-specific rules belong under issues.exclude-rules. “warn-unused” is not a recognized top-level option. Proposed structure: - exclusions:
- warn-unused: true
-
- rules:
- - path: _test\.go
- linters:
- - cyclop
- - dupl
- - dupword
- - err113
- - funlen
- - gocognit
- - maintidx
- - nestif
-
- - path: examples/
- linters:
- - err113
+issues:
+ max-issues-per-linter: 0
+ max-same-issues: 0
+ exclude-rules:
+ # Example: ignore gochecknoglobals in internal test-exports file
+ - path: ^exports_internal_test\.go$
+ linters:
+ - gochecknoglobals
+ # Example: restrict heavy complexity checks to tests only by excluding them elsewhere
+ - path: ^(?!.*_test\.go).*$ # non-test files
+ linters:
+ - cyclop
+ - dupl
+ - dupword
+ - funlen
+ - gocognit
+ - maintidx
+ - nestif
+ # Only run err113 in examples by excluding it elsewhere, or vice versa per intent
+ - path: ^examples/
+ linters:
+ - $allNote: golangci-lint doesn’t support “only run these linters for this path”. The approach is to exclude linters in paths where they shouldn’t run. Please confirm against the official schema; if desired, I can tailor a precise exclude-rules matrix for your intent. 🌐 Web query: 💡 Result: "exclusions" is not a valid top-level option in GolangCI-Lint's configuration. Details and Evidence
Additional context
ConclusionFor all issue/path/linter-specific exclusions, use Citations:
Move “exclusions” and “warn-unused” into issues.exclude-rules GolangCI-Lint does not recognize a top-level Please update - exclusions:
- warn-unused: true
-
- rules:
- - path: _test\.go
- linters:
- - cyclop
- - dupl
- - dupword
- - err113
- - funlen
- - gocognit
- - maintidx
- - nestif
-
- - path: examples/
- linters:
- - err113
+issues:
+ # Prevent any unused warnings; configure via the “unused” linter instead
+ max-issues-per-linter: 0
+ max-same-issues: 0
+ exclude-rules:
+ # Don’t run complexity checks on non-test files
+ - path: ^(?!.*_test\.go).*$ # all files except *_test.go
+ linters:
+ - cyclop
+ - dupl
+ - dupword
+ - funlen
+ - gocognit
+ - maintidx
+ - nestif
+
+ # Only ignore err113 in examples/
+ - path: ^examples/
+ linters:
+ - err113Tags:
🤖 Prompt for AI Agents |
||
| settings: | ||
| cyclop: | ||
| max-complexity: 25 | ||
|
|
||
| depguard: | ||
| rules: | ||
| main: | ||
| files: | ||
| - $all | ||
| - "!$test" | ||
| - "!**/examples/**/*" | ||
| allow: | ||
| - $gostd | ||
| test: | ||
| files: | ||
| - $test | ||
| - "**/examples/**/*" | ||
| allow: | ||
| - $gostd | ||
| - github.com/stretchr/testify/assert | ||
| - github.com/stretchr/testify/require | ||
| - github.com/AlphaOne1/dmorph | ||
| - modernc.org/sqlite | ||
|
|
||
| exhaustive: | ||
| default-signifies-exhaustive: true | ||
|
|
||
| mnd: | ||
| ignored-numbers: | ||
| - "2" | ||
|
|
||
| paralleltest: | ||
| ignore-missing: true | ||
|
|
||
| perfsprint: | ||
| errorf: false | ||
|
|
||
| testpackage: | ||
| skip-regexp: internal_test\.go | ||
|
|
||
| varnamelen: | ||
| max-distance: 10 | ||
| ignore-names: | ||
| - ctx | ||
| - db | ||
| - err | ||
| - tx | ||
|
|
||
| whitespace: | ||
| multi-if: true | ||
| multi-func: true | ||
|
|
||
| issues: | ||
| max-issues-per-linter: 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package dmorph | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| ) | ||
|
|
||
| // The exported names in this file are only used for internal testing and are not part of the public API. | ||
|
|
||
| var ( | ||
| TapplyStepsStream = applyStepsStream | ||
| TmigrationFromFileFS = migrationFromFileFS | ||
| TmigrationOrder = migrationOrder | ||
| ) | ||
|
Comment on lines
+10
to
+14
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. 🛠️ Refactor suggestion Replace global var aliases with thin wrapper functions to satisfy gochecknoglobals Global variables trigger gochecknoglobals. Use wrappers instead; behavior unchanged and constrained to _test.go files. Apply this diff: -package dmorph
-
-import "database/sql"
-
-// The exported names in this file are only used for internal testing and are not part of the public API.
-
-var (
- TapplyStepsStream = applyStepsStream
- TmigrationFromFileFS = migrationFromFileFS
- TmigrationOrder = migrationOrder
-)
-
-func (m *Morpher) TapplyMigrations(db *sql.DB, lastMigration string) error {
- return m.applyMigrations(db, lastMigration)
-}
+package dmorph
+
+import (
+ "database/sql"
+ "io"
+ "io/fs"
+ "log/slog"
+)
+
+// The exported names in this file are only used for internal testing and are not part of the public API.
+
+func TapplyStepsStream(tx *sql.Tx, r io.Reader, id string, log *slog.Logger) error {
+ return applyStepsStream(tx, r, id, log)
+}
+
+func TmigrationFromFileFS(name string, dir fs.FS, log *slog.Logger) FileMigration {
+ return migrationFromFileFS(name, dir, log)
+}
+
+func TmigrationOrder(m, n Migration) int {
+ return migrationOrder(m, n)
+}
+
+func (m *Morpher) TapplyMigrations(db *sql.DB, lastMigration string) error {
+ return m.applyMigrations(db, lastMigration)
+}🧰 Tools🪛 golangci-lint (2.2.2)8-8: TapplyStepsStream is a global variable (gochecknoglobals) 9-9: TmigrationFromFileFS is a global variable (gochecknoglobals) 10-10: TmigrationOrder is a global variable (gochecknoglobals) 🤖 Prompt for AI Agents |
||
|
|
||
| func (m *Morpher) TapplyMigrations(ctx context.Context, db *sql.DB, lastMigration string) error { | ||
| return m.applyMigrations(ctx, db, lastMigration) | ||
| } | ||
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.
Invalid key: use linters.enable-all instead of linters.default
golangci-lint doesn’t support linters.default: all. To enable all and selectively disable, use enable-all: true.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents