Skip to content

Conversation

@yongruilin
Copy link
Contributor

Updates the conflictingmarkers analyzer to include the struct name in the error message, changing the output from:

"field has conflicting markers..."

to:

"field . has conflicting markers..."

This provides more precise context, making it easier for developers to locate the source of the error, especially in complex types. The struct name is reliably determined by inspecting the AST stack during analysis.

This is for addressing the exception confusion: kubernetes/kubernetes#134229 (comment)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 21, 2025
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 21, 2025
Updates the `conflictingmarkers` analyzer to include the struct name in the error message, changing the output from:

"field <fieldName> has conflicting markers..."

to:

"field <structName>.<fieldName> has conflicting markers..."

This provides more precise context, making it easier for developers to locate the source of the error, especially in complex types. The struct name is reliably determined by inspecting the AST stack during analysis.
@yongruilin
Copy link
Contributor Author

/assign @JoelSpeed

Comment on lines 72 to 80
// Find the struct name from the stack
for i := len(stack) - 2; i >= 0; i-- {
if typeSpec, ok := stack[i].(*ast.TypeSpec); ok {
if _, ok := typeSpec.Type.(*ast.StructType); ok {
structName = typeSpec.Name.Name
break
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we find that this is a valuable addition to the messages output by the linting checks, this should probably be a sweeping change across all the linting checks.

What do you think about turning this into a generic utility that can be used by existing and new linting checks that should be providing this additional granularity?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this seems like something we should agree to change globally (e.g. we already have something similar in conditions, but different) and maybe even make a standard utility that looks up the name from the pass rather than passing it all through

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a generic util func using pass and field to get the structname.

}

func checkConflict(pass *analysis.Pass, field *ast.Field, markers markers.MarkerSet, conflictSet ConflictSet) {
func checkConflict(pass *analysis.Pass, field *ast.Field, structName string, markers markers.MarkerSet, conflictSet ConflictSet) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this handle conflicting tags when applied to a tyoe definition (e.g. a string alias)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it will.

Copy link

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an improvement to me.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 21, 2025
Adds a new utility function, `GetStructNameForField`, to determine the
parent struct name for a given field by inspecting the analysis pass.

Refactors the `conflictingmarkers` analyzer to use this new utility,
simplifying the analyzer and improving the detail in its reports.
Adds a new test case for the `GetStructNameForField` utility function.
This test uses the `analysistest` package to run a dedicated analyzer
over a test data file, ensuring the function correctly identifies the
parent struct for a given field.
@yongruilin yongruilin force-pushed the conflictmarkers-more-detail branch from b8463cf to b09f061 Compare October 21, 2025 21:11
@JoelSpeed
Copy link
Contributor

/approve
/lgtm

Thanks for the update @yongruilin, I'll create an issue so that we follow up and make this consistent among all the analyzers in the future

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoelSpeed, yongruilin

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 Oct 22, 2025
@k8s-ci-robot k8s-ci-robot merged commit 1dea13b into kubernetes-sigs:main Oct 22, 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.

5 participants