Skip to content

linters: add stringlint custom linter#195

Merged
yanyi-wego merged 5 commits intomainfrom
custom-linters
Jan 22, 2026
Merged

linters: add stringlint custom linter#195
yanyi-wego merged 5 commits intomainfrom
custom-linters

Conversation

@yanyi-wego
Copy link
Contributor

@yanyi-wego yanyi-wego commented Jan 20, 2026

Context

  • introduce our first custom golangci-lint linter: stringlint
  • flag direct empty-string and len checks, and suggest wegostrings helpers

Why

  • standardize string-emptiness checks across the codebase
  • enable auto-fixable guidance instead of ad‑hoc comparisons
  • make it easy to roll out via golangci‑lint custom plugin flow

What it does

  • detects patterns like s == "", s != "", len(s) == 0, len(s) > 0, and pointer deref forms
  • suggests using wegostrings.IsEmpty/IsNotEmpty and IsEmptyP/IsNotEmptyP
  • provides suggested fixes for --fix usage

How to use (golangci‑lint custom build)

  1. Add to .custom-gcl.yml:
    • module: github.com/wego/pkg/linters/stringlint
  2. Enable in .golangci.yml with stringlint
  3. Run ./custom-gcl run ./...

Standardizes empty-string checks on wego/pkg/strings helpers and
verifies autofix output via analysistest fixtures.
Golangci-lint module plugins must self-register with the
plugin-module-register package, so add registration and dependency.
Reverse literal-first comparisons like 1 <= len(s) previously
slipped through, so add normalization and a test to cover it.
Document supported len patterns and reversed forms.
@yanyi-wego yanyi-wego changed the title stringlint: handle reversed len >= 1 checks linters: add stringlint to recommend using our strings package Jan 20, 2026
@yanyi-wego yanyi-wego changed the title linters: add stringlint to recommend using our strings package linters: add stringlint custom linter Jan 20, 2026
Revive flags the plugin constructor's unused config argument; rename
it to '_' to indicate it's intentionally ignored.
@yanyi-wego yanyi-wego merged commit 7bde23a into main Jan 22, 2026
2 checks passed
@yanyi-wego yanyi-wego deleted the custom-linters branch January 22, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants