feat(linters): add stringsindexhasprefix analyzer for strings.Index(... ) == 0/!= 0#48049
stringsindexhasprefix analyzer for strings.Index(... ) == 0/!= 0#48049Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
stringsindexhasprefix analyzer for strings.Index(... ) == 0/!= 0
🤖 PR Triage
Rationale: Adds a new focused linter () with tests and golden files. Well-scoped, low-risk change. Good description and tests included. Suitable for batch review with other linter additions.
|
|
Great work on this linter! 🎉 This PR adds a well-focused and clearly useful analyzer that closes a real gap — the pattern of comparing ✅ What looks good:
Summary: This PR looks ready for review and merge. The implementation follows the project's patterns, the tests are solid, and the motivation is clear. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "patchdiff.githubusercontent.com"See Network Configuration for more information.
|
This adds a focused linter to close the gap between existing
strings.Indexcontainment checks and prefix checks. It flagsstrings.Index(s, sub) == 0/!= 0(including yoda-order variants) and suggestsstrings.HasPrefix-based replacements.New analyzer:
stringsindexhasprefixpkg/linters/stringsindexhasprefix/stringsindexhasprefix.go.strings.Index(s, sub) == 0strings.Index(s, sub) != 00 == strings.Index(s, sub)0 != strings.Index(s, sub)strings.HasPrefix(s, sub)!strings.HasPrefix(s, sub)Analyzer tests and golden fixtures
analysistestcoverage inpkg/linters/stringsindexhasprefix/stringsindexhasprefix_test.go.pkg/linters/stringsindexhasprefix/testdata/src/stringsindexhasprefix/stringsindexhasprefix.gopkg/linters/stringsindexhasprefix/testdata/src/stringsindexhasprefix/stringsindexhasprefix.go.goldenRegistry and spec/docs integration
pkg/linters/registry.go(All()).pkg/linters/doc.gopkg/linters/README.mdpkg/linters/spec_test.goto include the new analyzer in documented subpackages.