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

Remove unused prameters #13504

Merged
merged 72 commits into from
Jun 4, 2024
Merged

Remove unused prameters #13504

merged 72 commits into from
Jun 4, 2024

Conversation

simondeziel
Copy link
Member

@simondeziel simondeziel commented May 26, 2024

@simondeziel simondeziel force-pushed the misc-fixes branch 2 times, most recently from b0cd4fe to 44b1365 Compare May 28, 2024 20:48
…smask

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
…rkdns

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
…face()

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
…ool()

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
…ey()

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
@simondeziel simondeziel marked this pull request as ready for review June 3, 2024 20:46
@simondeziel
Copy link
Member Author

golangci is still unhappy but I don't think I would know how to address all the complains it has:

run-parts: executing test/lint/golangci.sh
Checking for golangci-lint errors between HEAD and main (eb251a928463ec96590c110aca8303ad3669f865)...
Error: lxc/file.go:406:4: defer: prefer not to defer inside loops (revive)
			defer func() { _ = f.Close() }()
			^
Error: lxc/list.go:760:1: exported: exported method cmdList.IP4ColumnData should have comment or be unexported (revive)
func (c *cmdList) IP4ColumnData(cInfo api.InstanceFull) string {
^
Error: lxc/file.go:615:3: defer: prefer not to defer inside loops (revive)
		defer func() { _ = file.Close() }()
		^
Error: lxc/list.go:786:1: exported: exported method cmdList.IP6ColumnData should have comment or be unexported (revive)
func (c *cmdList) IP6ColumnData(cInfo api.InstanceFull) string {
^
Error: lxc/list.go:881:1: exported: exported method cmdList.PIDColumnData should have comment or be unexported (revive)
func (c *cmdList) PIDColumnData(cInfo api.InstanceFull) string {
^
Error: lxc/file.go:53:3: datarace: potential datarace: return value buf is captured (by-reference) in goroutine (revive)
		buf, resp, err = server.GetInstanceFile(inst, path)
		^
Error: lxd-agent/main_agent.go:54:3: deep-exit: calls to os.Exit only in main() or init() functions (revive)
		os.Exit(1)
		^
Error: lxd-agent/main_agent.go:199:2: deep-exit: calls to os.Exit only in main() or init() functions (revive)
	os.Exit(exitStatus)
	^
Error: lxc-to-lxd/main_migrate.go:67:3: deep-exit: calls to os.Exit only in main() or init() functions (revive)
		os.Exit(1)
		^
Error: lxd/instance_file.go:179:8: unchecked-type-assertion: type cast result is unchecked in stat.Sys().(*sftp.FileStat) - type assertion will panic if not matched (revive)
	fs := stat.Sys().(*sftp.FileStat)
	      ^
Error: lxd/instance_file.go:342:8: unchecked-type-assertion: type cast result is unchecked in stat.Sys().(*sftp.FileStat) - type assertion will panic if not matched (revive)
	fs := stat.Sys().(*sftp.FileStat)
	      ^
run-parts: test/lint/golangci.sh exited with return code 1
make: *** [Makefile:288: static-analysis] Error 1
Error: Process completed with exit code 2.

The exported method X should have comment or be unexported left in lxc/file.go are due to functions needing to start with a capital letter (IPv4, IPv6 and PID). Should I write them in lowercase or is there a way to tell Go to not export despite the capital letter?

@roosterfish
Copy link
Contributor

Should I write them in lowercase or is there a way to tell Go to not export despite the capital letter?

If they start with an uppercase they are exported so the linter requires a // FuncName does something comment. In some cases it can make sense to unexport them (use lowercase funcName instead) but depending on it's usage this might not work out of the box if the function is used outside of its own package.

@tomponline
Copy link
Member

Yes, in general we should seek to reduce our exported API as much as possible so it is easier to reason about how changes may affect external callers.

@markylaing
Copy link
Contributor

Should I write them in lowercase or is there a way to tell Go to not export despite the capital letter?

If they start with an uppercase they are exported so the linter requires a // FuncName does something comment. In some cases it can make sense to unexport them (use lowercase funcName instead) but depending on it's usage this might not work out of the box if the function is used outside of its own package.

I've recently run into this rabbit hole in the lxc package about exported functions. The structure we have for defining lxc commands is to have an unexported struct with Command and Run methods. In the end, rather than refactoring the entire CLI I decided to just turn off the rule (6235b22). Perhaps that's not a good idea.

@markylaing
Copy link
Contributor

Should I write them in lowercase or is there a way to tell Go to not export despite the capital letter?

If they start with an uppercase they are exported so the linter requires a // FuncName does something comment. In some cases it can make sense to unexport them (use lowercase funcName instead) but depending on it's usage this might not work out of the box if the function is used outside of its own package.

I've recently run into this rabbit hole in the lxc package about exported functions. The structure we have for defining lxc commands is to have an unexported struct with Command and Run methods. In the end, rather than refactoring the entire CLI I decided to just turn off the rule (6235b22). Perhaps that's not a good idea.

@simondeziel I've unexported most of the methods in the lxc package here #13543. Let me know if there any other lint errors once you've rebased and I'll help with those :)

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

Thanks!

@tomponline tomponline merged commit 1bde882 into canonical:main Jun 4, 2024
27 of 28 checks passed
@simondeziel simondeziel deleted the misc-fixes branch June 4, 2024 12:39
hamistao pushed a commit to hamistao/lxd that referenced this pull request Jun 4, 2024
Remove unused prameters

Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants