Skip to content

Conversation

@kannon92
Copy link
Contributor

@kannon92 kannon92 commented Oct 25, 2025

Fixes #23

Implements a new linter that checks for common typos and syntax issues in marker comments, addressing the requirements from issue #23:

  • Detects common typos in marker identifiers (kubebuidler → kubebuilder, optinal → optional, requied → required, etc.)
  • Validates spacing after '+' symbol (+kubebuilder not + kubebuilder)
  • Includes comprehensive test cases with valid and invalid marker examples
  • Add detection for //+ (space missing between comment and +)

The linter follows established patterns in the codebase and integrates with the existing marker analysis framework. Test coverage includes spacing issues, typo detection, syntax validation, and complex multi-issue scenarios.

🤖 Generated with Claude Code

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kannon92
Once this PR has been reviewed and has the lgtm label, please assign jpbetz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 25, 2025
@kannon92 kannon92 force-pushed the new-linter-markertypos branch 3 times, most recently from 18e64e9 to 9a5e699 Compare October 25, 2025 03:09

fieldMarkers := markersAccess.FieldMarkers(field)
for _, marker := range fieldMarkers.UnsortedList() {
checkMarkerSyntax(pass, marker)
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 are passing the actual Marker{} type from the markersAccess set here, I don't think that we need to validate the spacing issues.

It wouldn't have been successfully parsed if it didn't implement the correct marker semantics.


typeMarkers := markersAccess.TypeMarkers(typeSpec)
for _, marker := range typeMarkers.UnsortedList() {
checkMarkerSyntax(pass, marker)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto re: not needing to also validation spacing issues here.

Comment on lines +170 to +186
commonTypos := map[string]string{
"kubebuidler": "kubebuilder",
"kubebuiler": "kubebuilder",
"kubebulider": "kubebuilder",
"kubbuilder": "kubebuilder",
"kubebulder": "kubebuilder",
"optinal": "optional",
"requied": "required",
"requird": "required",
"nullabel": "nullable",
"validaton": "validation",
"valdiation": "validation",
"defualt": "default", //nolint:misspell
"defult": "default",
"exampl": "example",
"examle": "example",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@JoelSpeed Is this what you had in mind for "common typos"? This seems like something that could get unruly fairly quickly and I'd advocate we avoid handling common misspellings of markers.

I wonder if something more along the lines of "is the parsed set of markers one that is a known marker?" would effectively achieve the same result while staying relatively maintainable?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if something more along the lines of "is the parsed set of markers one that is a known marker?"

We can't claim to be complete in this regards though, so we do need to be able to handle unknown markers.

What is done here does align with the misspell marker, so I'm happy to keep this.

I was more thinking about the malformation stuff but this also seems valuable.

Additional things to think about

  • := vs =, the former only being relevant to kubebuilder markers
  • The value of the markers, e.g. is it a number, or string, should it have a value at all
  • For markers that have required arguments (e.g. XValidation with rule), are those arguments present
  • Case sensitivity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Claude had some troubles with the first one so I reverted its attempt at fixing that one.

It could be worth iterating on these linters.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as we capture from this conversation anything that doesn't merge in this PR and keep the issue open to contribute the rest later I think that's ok

Does mean that those enabling this will get a surprise when later new things pop up though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea that is not a great experience.

One option could be including configurations on new changes. Essentially we could release new functionality into the linters via configurations so we could roll this out without breaking existing users.

I worry that this PR is already pretty large so not sure if we want to include all the items.

I don't really know how to solve all of these right now and I hope I can find time to get back to it.

But not sure the best path here.

Comment on lines +317 to +372
- **Space after '+' symbol**: Markers should not have space after the `+` symbol
- **Missing space after '//' prefix**: Markers should have a space after the `//` comment prefix
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to make sure this doesn't interfere with other valid use cases. With that in mind, we need to be certain that the lines we are reporting on are intended to be one of the markers we are looking for. Starting my review on the docs so you may have handled this already


### Fixes

No automatic fixes are provided
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this conflict with the Fixed versions line on 330? Looking at the implementation, it looks like we are suggesting fixes

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 thought I dropped the suggest fixes from this PR. I couldn't find what you mean though.

I had issues with suggesting fixes and I removed that code.

Copy link
Contributor

Choose a reason for hiding this comment

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

The test suite you've added is running as if there are fixes applied 🤔

// + required // want "marker should not have space after '\\+' symbol"
type SpacingIssueNonKubebuilder string

// +kubebuilder:validation:MaxLength=256
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to do anything about case sensitivity? I believe all of the markers in K8s are case-sensitive so perhaps folks are casing them wrong?

// +kubebuilder:validation:MaxLength=256
type KubebuilderWrongSyntax string

// +kubebuilder:validation:MinLength=1
Copy link
Contributor

Choose a reason for hiding this comment

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

In the long term, do we want to make this marker understand the types that various markers should handle? E.g. if this isn't a number, return an error?

Comment on lines +41 to +42
// +default:value:="test"
type NonKubebuilderWrongSyntax string
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be an error?

Comment on lines +44 to +45
// +required:=true
// +optional:=false
Copy link
Contributor

Choose a reason for hiding this comment

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

Expecting errors here no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to explore some markers that aren't ones we care about, e.g. does this pick up markdown tables or golangci-lint nolint style markers

Copy link
Contributor

Choose a reason for hiding this comment

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

Normally you'd see the want comments in the golden files too, I assume this won't pass tests with them missing


// +kubebuilder:validation:Required
ValidField string `json:"validField"`
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit missing final new line char

Comment on lines +170 to +186
commonTypos := map[string]string{
"kubebuidler": "kubebuilder",
"kubebuiler": "kubebuilder",
"kubebulider": "kubebuilder",
"kubbuilder": "kubebuilder",
"kubebulder": "kubebuilder",
"optinal": "optional",
"requied": "required",
"requird": "required",
"nullabel": "nullable",
"validaton": "validation",
"valdiation": "validation",
"defualt": "default", //nolint:misspell
"defult": "default",
"exampl": "example",
"examle": "example",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if something more along the lines of "is the parsed set of markers one that is a known marker?"

We can't claim to be complete in this regards though, so we do need to be able to handle unknown markers.

What is done here does align with the misspell marker, so I'm happy to keep this.

I was more thinking about the malformation stuff but this also seems valuable.

Additional things to think about

  • := vs =, the former only being relevant to kubebuilder markers
  • The value of the markers, e.g. is it a number, or string, should it have a value at all
  • For markers that have required arguments (e.g. XValidation with rule), are those arguments present
  • Case sensitivity

kannon92 and others added 2 commits October 29, 2025 16:34
Implements a new linter that checks for common typos and syntax issues in
marker comments, addressing the requirements from issue kubernetes-sigs#23:

- Detects common typos in marker identifiers (kubebuidler → kubebuilder,
  optinal → optional, requied → required, etc.)
- Validates spacing after '+' symbol (+kubebuilder not + kubebuilder)
- Checks marker syntax conventions (kubebuilder markers use ':=',
  non-kubebuilder markers use '=')
- Provides automatic fixes for all detected issues
- Includes comprehensive test cases with valid and invalid marker examples

The linter follows established patterns in the codebase and integrates with
the existing marker analysis framework. Test coverage includes spacing
issues, typo detection, syntax validation, and complex multi-issue scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kannon92 kannon92 force-pushed the new-linter-markertypos branch from 9a5e699 to 5ed3db3 Compare October 30, 2025 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Linter: markertypos

4 participants