Skip to content
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

Linters: Bring back removed linters: wastedassign #1672

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ linters:
- unused
- usestdlibvars
- varcheck
# - wastedassign
- wastedassign
- whitespace
- wsl
# - exhaustivestruct
# - gochecknoglobals
# - gochecknoinits
# - godot
Expand Down
2 changes: 1 addition & 1 deletion e2e/dractions/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func getTargetCluster(client client.Client, namespace, placementName string, drp
return "", err
}

targetCluster := ""
var targetCluster string
if currentCluster == drpolicy.Spec.DRClusters[0] {
targetCluster = drpolicy.Spec.DRClusters[1]
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func GetDRClusters(ctx context.Context, client client.Client, drPolicy *rmn.DRPo
func (r DRPlacementControlReconciler) updateObjectMetadata(ctx context.Context,
drpc *rmn.DRPlacementControl, placementObj client.Object, log logr.Logger,
) error {
update := false
var update bool
Copy link
Member

Choose a reason for hiding this comment

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

What is the issue with the previous code? Both are valid Go code and should compile to the same thing. If not this should be a Go compiler bug.

Maybe we need to report a golangci-lint bug for this, the linter should not requiring changing such code.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a wasted assignment as it is overwritten right after. The linter is for a code practice not a code error afaict. I do not see an issue with the same.

Copy link
Member

Choose a reason for hiding this comment

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

There is already an issue this:
sanposhiho/wastedassign#39

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I did visit that issue, once addressed it may help. For now it is better to have the linter than not, so I suggest we do not wait for a resolution of that issue (which seems to be 2+ years old).


update = rmnutil.AddLabel(drpc, rmnutil.OCMBackupLabelKey, rmnutil.OCMBackupLabelValue)
update = rmnutil.AddFinalizer(drpc, DRPCFinalizer) || update
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/util/secrets_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ func (sutil *SecretsUtil) policyObject(
format TargetSecretFormat,
veleroNS string,
) *runtime.RawExtension {
var object *runtime.RawExtension

s3SecretRef := corev1.SecretReference{Name: secretName, Namespace: secretNS}
object := &runtime.RawExtension{}
Copy link
Member

Choose a reason for hiding this comment

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

Here we replace pointer to object with nil - this makes sense if the intent of the code is to initialize the pointer only in some cases, so a good change.


switch format {
case SecretFormatRamen:
Expand Down
Loading