Skip to content

Comments

Deadcode linter#552

Merged
arbulu89 merged 5 commits intomainfrom
deadcode-linter
Feb 18, 2026
Merged

Deadcode linter#552
arbulu89 merged 5 commits intomainfrom
deadcode-linter

Conversation

@arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Feb 17, 2026

Description

Run golang deadcode process to find dead code paths and remove them.
https://pkg.go.dev/golang.org/x/tools/internal/cmd/deadcode

Here the fixed errors:
https://github.com/trento-project/agent/actions/runs/22100883779/job/63869965678?pr=552

3 things:

  • Unfortunately there is no asdf plugin for golang deadcode, so we need to install and reshim manually
  • deadcode always returns 0 return code (unless compliation errors), so we need to look for stdout to see if there are errors. That's why we have that comparison in the makefile file
  • A lot of our functions are created to make the code testable, that's why we need to add the test flag. Otherwise we would have a lot of dead code

EDIT:
When @antgamdia suggested to add deadcode to the tools.go file to track the version, I have read that golang tooling usage has envolved quite a bit since 1.24.
Now, tools can be declared and tracked without any dummy file to import them, and use them as go tool {toolname}. This gives as the chance to remove some dependencies from asdf as well, and have all golang tooling in the same place.
If you want to read a bit more: https://blog.howardjohn.info/posts/go-tools-command/

Comment on lines 53 to 56
- name: deadcode
run: |
go install golang.org/x/tools/cmd/deadcode@latest
make deadcode

Choose a reason for hiding this comment

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

comment : this way, we don't know which version of the linter we are using. While we might want to stick to the latest, it can often make our CI fail. Instead, we can define the deps in a non-compiled file, track them in our deps and install them via go install, something like:

//go:build tools

package tools

import (
	_ "golang.org/x/tools/cmd/deadcode"
)
dev-deps:
	go install \
		golang.org/x/tools/cmd/deadcode


require (
github.com/chigopher/pathlib v1.0.0 // indirect
github.com/chigopher/pathlib v0.19.1 // indirect
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this package was downversioned by the author:

go: warning: github.com/chigopher/pathlib@v1.0.0: retracted by module author: Published accidentally
go: to switch to the latest unretracted version, run:
	go get github.com/chigopher/pathlib@latest

@arbulu89 arbulu89 force-pushed the deadcode-linter branch 2 times, most recently from 8210117 to a4e193c Compare February 17, 2026 16:09
@arbulu89 arbulu89 marked this pull request as ready for review February 18, 2026 07:46
Copy link
Contributor

@gagandeepb gagandeepb left a comment

Choose a reason for hiding this comment

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

Thanks for this.This could be evolved to have a deadcode_ignore file containing either files or file-path-patterns to ignore for the purposes of deadcode analysis.

Copy link

@antgamdia antgamdia left a comment

Choose a reason for hiding this comment

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

Thanks for adding the suggestions and for looking into the go tool thing!

@arbulu89 arbulu89 merged commit 4c47bf0 into main Feb 18, 2026
12 checks passed
@arbulu89 arbulu89 deleted the deadcode-linter branch February 18, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants