-
Notifications
You must be signed in to change notification settings - Fork 17
Add nodurations linter #143
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
Conversation
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.
Thanks for taking a pass at this one, I've left a few comments, pretty much all around documentation wording. If we can get those updated I think we can get this merged pretty quickly
pkg/analysis/nodurations/testdata/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go
Outdated
Show resolved
Hide resolved
pkg/analysis/nodurations/analyzer.go
Outdated
inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) | ||
if !ok { | ||
return nil, kalerrors.ErrCouldNotGetInspector | ||
} | ||
|
||
// Filter to fields so that we can look at fields within structs. | ||
// Filter typespecs so that we can look at type aliases. | ||
nodeFilter := []ast.Node{ | ||
(*ast.StructType)(nil), | ||
(*ast.TypeSpec)(nil), | ||
} | ||
|
||
inspect.Preorder(nodeFilter, func(node ast.Node) { | ||
switch n := node.(type) { | ||
case *ast.StructType: | ||
if n.Fields == nil { | ||
return | ||
} | ||
|
||
for _, field := range n.Fields.List { | ||
checkField(pass, field) | ||
} | ||
case *ast.Field: | ||
checkField(pass, n) | ||
case *ast.TypeSpec: | ||
checkTypeSpec(pass, n, node, "type") | ||
} | ||
}) |
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.
We have our own internal inspector wrapper now, we should use this instead
Can you copy the pattern in
kube-api-linter/pkg/analysis/duplicatemarkers/analyzer.go
Lines 46 to 57 in 81d935c
inspect, ok := pass.ResultOf[inspector.Analyzer].(inspector.Inspector) | |
if !ok { | |
return nil, kalerrors.ErrCouldNotGetInspector | |
} | |
inspect.InspectFields(func(field *ast.Field, _ []ast.Node, _ extractjsontags.FieldTagInfo, markersAccess markers.Markers) { | |
checkField(pass, field, markersAccess) | |
}) | |
inspect.InspectTypeSpec(func(typeSpec *ast.TypeSpec, markersAccess markers.Markers) { | |
checkTypeSpec(pass, typeSpec, markersAccess) | |
}) |
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.
Yeah, I am trying to reuse this, but finding bit confused and trying to find a way.
inspect.Preorder(nodeFilter, func(node ast.Node) {
switch n := node.(type) {
case *ast.StructType:
if n.Fields == nil {
return
}
for _, field := range n.Fields.List {
checkField(pass, field)
}
case *ast.Field:
checkField(pass, n)
case *ast.TypeSpec:
checkTypeSpec(pass, n, node, "type")
}
- with using
inspect.InspectTypeSpec
I can't get the node object to report node.Pos() - Trying to find way to iterate over struct fields in case of
*ast.StructType
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.
I can't get the node object to report node.Pos()
An *ast.TypeSpec
implements the ast.Node
interface, so you can substitute node with the typeSpec
no?
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.
Trying to find way to iterate over struct fields in case of *ast.StructType
The InspectFields handles this for you by passing in the field of any relevant struct, so you don't need to handle structs directly
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.
Got it, I just overlook few things in hurry, Just fixing final round of errors.
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.
Updated and squashed the commits.
Aside from https://github.com/kubernetes-sigs/kube-api-linter/pull/143/files#r2330102093, LGTM, can you pickup this comment and squash into a single commit please? |
5ff5e8a
to
af04de5
Compare
Done, Thank you for the help. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed, Karthik-K-N The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes: #24
This PR contains most of the changes similar to nobool linter, May be I can work on code reuse based on the feedback.