Repository navigation
[linter-miner] Add reflect-deepequal-usage linter #66239
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,13 @@ | |
| package reflectdeepequalusage | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "go/ast" | ||
|
|
||
| "golang.org/x/tools/go/analysis" | ||
|
|
||
| "github.com/github/gh-aw/pkg/linters/internal/analyzerutil" | ||
| "github.com/github/gh-aw/pkg/linters/internal/astutil" | ||
| "github.com/github/gh-aw/pkg/linters/internal/coverage" | ||
| "github.com/github/gh-aw/pkg/linters/internal/filecheck" | ||
| "github.com/github/gh-aw/pkg/linters/internal/nolint" | ||
| "github.com/github/gh-aw/pkg/logger" | ||
|
|
@@ -26,6 +26,12 @@ var Analyzer = analyzerutil.New( | |
| run, | ||
| ) | ||
|
|
||
| var hotThreshold *int | ||
|
|
||
| func init() { | ||
| hotThreshold = coverage.RegisterHotThresholdFlag(Analyzer) | ||
| } | ||
|
|
||
| // URL points to documentation for this linter. | ||
| var _ = func() struct{} { | ||
| Analyzer.URL = "https://github.com/github/gh-aw/tree/main/pkg/linters/reflect-deepequal-usage" | ||
|
|
@@ -68,12 +74,14 @@ func analyzeCall(pass *analysis.Pass, n ast.Node, generatedFiles filecheck.Gener | |
| return | ||
| } | ||
|
|
||
| if !coverage.ShouldApply(pass, call.Pos(), *hotThreshold) { | ||
| return | ||
| } | ||
|
|
||
| pkgLog.Printf("flagging reflect.DeepEqual() call at %s:%d", pos.Filename, pos.Line) | ||
|
Contributor
Author
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. [/codebase-design] 💡 Suggested simplificationpass.Report(analysis.Diagnostic{
Pos: call.Pos(),
End: call.End(),
Message: "reflect.DeepEqual() is inefficient and should not be used in conditionals; prefer typed equality operators or type-specific comparison functions",
})This also lets you drop the @copilot please address this. |
||
| pass.Report(analysis.Diagnostic{ | ||
|
Comment on lines
+81
to
+82
|
||
| Pos: call.Pos(), | ||
| End: call.End(), | ||
| Message: fmt.Sprintf( | ||
| "reflect.DeepEqual() is inefficient and should not be used in conditionals; prefer typed equality operators or type-specific comparison functions", | ||
| ), | ||
| Pos: call.Pos(), | ||
| End: call.End(), | ||
| Message: "reflect.DeepEqual() is inefficient and should not be used in conditionals; prefer typed equality operators or type-specific comparison functions", | ||
| }) | ||
| } | ||
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.
[/codebase-design] Don't hand-roll the
Analyzer.URLpatch with an IIFE; use the existinganalyzerutil.NewAtPathhelper, which is built exactly for dash-named package directories (seepanic-in-library-code.go).💡 Suggested fix
This removes the need for the awkward package-scope
var _ = func() struct{} { ... }()block entirely and matches the conventionpanicinlibrarycode.Analyzeralready establishes for the same directory-naming mismatch.@copilot please address this.