-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
🌱 Enable jsontags lint of KAL #11890
Conversation
.golangci-kal.yml
Outdated
@@ -26,7 +26,7 @@ linters-settings: | |||
# Linters below this line are disabled, pending conversation on how and when to enable them. | |||
# - "commentstart" # Ensure comments start with the serialized version of the field name. | |||
# - "integers" # Ensure only int32 and int64 are used for integers. | |||
# - "jsontags" # Ensure every field has a json tag. | |||
- "jsontags" # Ensure every field has a json tag. |
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.
Please move this up below conditions. This is the section for the disabled linters
.golangci-kal.yml
Outdated
@@ -61,7 +61,36 @@ issues: | |||
- path-except: "api/*" | |||
linters: | |||
- kal | |||
# apiwarnings contains a `api` characters in the path, but it's not an API folder. | |||
- path: "util/apiwarnings/*" |
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 don't follow why apiwarnings/ is apparently matching api/*
@JoelSpeed Am I missing something? :)
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.
Hmm, it doesn't appear to match with the path exception so I'm not sure why this package would be picked up, the pattern is api/*
Line 61 in 15ce36f
- path-except: "api/*" |
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.
Definitely shows these findings if I drop this exclude
util/apiwarnings/handler.go:33:2: jsontags: field Logger is missing json tag (kal)
Logger logr.Logger
^
util/apiwarnings/handler.go:37:2: jsontags: field Expressions is missing json tag (kal)
Expressions []regexp.Regexp
^
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.
Works fine with this
# KAL should only run on API folders.
- path-except: "api//*"
linters:
- kal
Not sure if I want to know why, @sivchari can you drop this exclude and adjust the path-except above please? Thx! :)
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 should probably also change all the other /
into //
in other path values
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.
Not sure if I want to know why
How interesting 🤔
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.
Very unintuitive
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.
Thx!
How confusing :(
.golangci-kal.yml
Outdated
- path: "api/v1beta1/*" | ||
text: "field XPreserveUnknownFields json tag does not match pattern" | ||
linters: | ||
- kal | ||
- path: "api/v1beta1/*" | ||
text: "field XValidations json tag does not match pattern" | ||
linters: | ||
- kal | ||
- path: "api/v1beta1/*" | ||
text: "field XMetadata json tag does not match pattern" | ||
linters: | ||
- kal | ||
- path: "api/v1beta1/*" | ||
text: "field XIntOrString json tag does not match pattern" | ||
linters: | ||
- kal |
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.
Let's merge them all into one regex match
Let's also ignore them in general and not only for v1beta1
Let's add a comment that we intentionally align these fields to the corresponding fields in CustomResourceDefinitions
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.
+1 this makes sense to me
.golangci-kal.yml
Outdated
linters: | ||
- kal | ||
- path: "api/v1beta1/*|api/v1alpha1/*" | ||
- path: "api//*" |
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.
This one still wants to be v1beta1 so that when we introduce new v1beta2 APIs this is enforced
.golangci-kal.yml
Outdated
- kal | ||
- path: "api/v1beta1/*" | ||
text: "field XIntOrString json tag does not match pattern" | ||
source: "X.*" |
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 think this is too broad, can we be specific about the field names we are excepting here please
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.
Absolutely. We have something like this in our main .golangci.yml. This here should be similar
text: "SA1019: (bootstrapv1.ClusterStatus|KubeadmConfigSpec.UseExperimentalRetryJoin|scope.Config.Spec.UseExperimentalRetryJoin|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|dockerMachine.Spec.Backend.Docker.Bootstrapped|devMachine.Spec.Backend.Docker.Bootstrapped|c.TopologyPlan|clusterv1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition).Metadata) is deprecated"
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.
Exactly. fixed.
.golangci-kal.yml
Outdated
linters: | ||
- kal | ||
# These reporting are false positives. | ||
# When the following issue is fixed, remove the exclusion. | ||
# https://github.com/JoelSpeed/kal/issues/43 |
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 don't actually understand what that issue is? The PR merged to fix this 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.
Could it be that we just didn't bump KAL since the fix was merged?
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 use the 1ad4d048de47e0fa31c48e8f5d2ebe9eded0f4e4 in e48fa3c.
I expect this rule is removed since the extractjsontags analyzer is fixed, but this report are still be existing.
Am I missing something ?
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.
Ok I see, we fixed the comments linter, but not the json tags linter itself, will need a small fix there too
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 open the pr (this is wip, yet) to fix jsontags linter.
.golangci-kal.yml
Outdated
jsonTags: | ||
jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. |
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.
Do we want to uncomment this, or shall we just leave it commented so that if the default configuration changes over time we continue to use the default?
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.
The CI will be failed if KAL changes default configuration. Then we'll end up adding the this configuration to manage the compability.
So I think it's better to keep this configuration.
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.
CI will only fail if we bump KAL on the PR where we bump KAL
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.
@JoelSpeed How do we keep the documented default values here up-to-date if they change in KAL?
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.
(In general I'm in favor of using the default value here from KAL)
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.
@JoelSpeed How do we keep the documented default values here up-to-date if they change in KAL?
Open to suggestions, I don't know at the moment.
I'm expecting in the not too distant future to move the project to kube-sigs. Once it's moved, and we've had agreement from sig-apimachinery that we are happy with the structure and defaults etc, that we probably will start treating the project like a v1 and therefore breaking changes won't be possible.
So I guess, as we update kal, we add the new sections in to show what the new config might be, but I don't have a great/automatic suggestion at the moment
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.
All good. We can just sync the defaults once we reach "v1"
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.
Agreed. thx!
e48fa3c
to
4ebf4c1
Compare
.golangci-kal.yml
Outdated
@@ -39,13 +39,11 @@ linters-settings: | |||
isFirstField: Warn # Require conditions to be the first field in the status struct. | |||
usePatchStrategy: Forbid # Conditions should not use the patch strategy on CRDs. | |||
useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required. | |||
# jsonTags: |
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 think we should leave this section commented out so that we can easily see what configuration is available to us, rather than removing the comments. It may help us in the future when trying to work out why something isn't behaving in the way we might expect
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.
Fixed!
.golangci-kal.yml
Outdated
# jsontags: | ||
# jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. | ||
# optionalOrRequired: | ||
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. | ||
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. | ||
# requiredFields: | ||
# pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers. |
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.
This section has all moved, can we unmove it so that it's at the original indentation level prior to this PR?
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.
Sorry, fixed.
Could we squash some of the fixup style commits please so that we have a set of logical, atomic commits to merge? |
6cf1f25
to
165ed56
Compare
You might have better luck with the rebases if we were to order the list of enabled linters alphabetically again 🤔 |
165ed56
to
d80cc3d
Compare
@JoelSpeed seems like KAL is also looking at interfaces |
@sbueringer Yes, it appears there was a regression (see JoelSpeed/kal#48) and then I'm fixing that in JoelSpeed/kal#49 Lets hold this one until 49 is merged please |
The KAL fix is merged, so if we can get this updated with the latest KAL, I think we can move forward to get this merged |
d80cc3d
to
aa61dbd
Compare
Signed-off-by: sivchari <[email protected]>
aa61dbd
to
06e86de
Compare
/lgtm Thanks @sivchari |
LGTM label has been added. Git tree hash: 0ada23263c0b3c55a95a0d82bdb24e0f345436dc
|
Thx! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sbueringer 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 |
What this PR does / why we need it:
This is part of #11834
Enabled jsontags linter
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #