Skip to content

Conversation

Karthik-K-N
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 8, 2025
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 8, 2025
Copy link
Contributor

@JoelSpeed JoelSpeed left a 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

Comment on lines 42 to 54
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")
}
})
Copy link
Contributor

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

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)
})

Copy link
Contributor Author

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")
		}
  1. with using inspect.InspectTypeSpec I can't get the node object to report node.Pos()
  2. Trying to find way to iterate over struct fields in case of *ast.StructType

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@JoelSpeed
Copy link
Contributor

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?

@Karthik-K-N
Copy link
Contributor Author

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?

Done, Thank you for the help.

@JoelSpeed
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 8, 2025
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2025
@k8s-ci-robot k8s-ci-robot merged commit 65a570b into kubernetes-sigs:main Sep 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Linter: nodurations

3 participants