-
Notifications
You must be signed in to change notification settings - Fork 16
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
check for interface inheritance #15
Conversation
This issue is currently awaiting triage. If logtools contributors determine this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
The same check also makes sense for |
I added logr.Marshaler checking and proposed klog.Format. That PR needs to get merged first. /hold |
/hold cancel klog.Format got merged. |
/assign @serathius |
logcheck/pkg/logcheck.go
Outdated
@@ -561,6 +565,14 @@ func kvCheck(keyValues []ast.Expr, fun ast.Expr, pass *analysis.Pass, funName st | |||
|
|||
for index, arg := range keyValues { | |||
if index%2 != 0 { | |||
// Check 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.
Oh, this makes this loop even harder to read. Could we separate key and value validation by using a dedicated functions? For example
func kvCheck(keyValues []ast.Expr, fun ast.Expr, pass *analysis.Pass, funName string, keyCheckEnabled, parametersCheckEnabled, valueCheckEnabled bool) {
...
for index, arg := range keyValues {
if index%2 == 0 {
checkKey(keyValues []ast.Expr, fun ast.Expr, pass *analysis.Pass, funName string, keyCheckEnabled)
checkParameters(keyValues []ast.Expr, fun ast.Expr, pass *analysis.Pass, funName string, parametersCheckEnabled)
}
checkValue(keyValues []ast.Expr, fun ast.Expr, pass *analysis.Pass, funName string, valueCheckEnabled)
}
}
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, let's split it up.
I think a switch statement with two cases works best here because it puts both check calls at the same indention. Indenting one but not the other as in an if+continue looks weird.
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.
Yes, switch is great idea. I hate golang aversion for else
.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pohly, serathius 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 |
/hold golangci-lint is unhappy. |
The two flavors of key checking (plain ASCII and the stricter Kubernetes guidelines) are now done in the same function. This is a first step towards also checking values in that same function. While at it, a small bug for format specifier checking of klog calls gets fixed: it was done twice, once without honoring the enable flag for it.
If a type inherits String from some embedded field, then the klog text output will only print the result of that function call, which then includes only information about the embedded field (example: kubernetes/kubernetes#115950). The right solution for this problem is TBD.
/lgtm |
/hold cancel |
/hold |
/hold cancel Tide seems to have missed the label change... let's do it again. |
This is a static analysis check for the problem reported in kubernetes/kubernetes#115950: converting unstructured logging of the form
"%v", someObj
to"obj", someObj
produces undesirable output in the klog text format whensomeObj
is of a type which has an incompletefmt.Stringer
implementation because it inherits that from an embedded field.In Kubernetes, this currently finds: