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 code, add staticcheck to TravisCI #2465

Merged
merged 2 commits into from
Jun 2, 2020

Conversation

sparrc
Copy link
Contributor

@sparrc sparrc commented May 29, 2020

Summary

This PR mostly removes unused code found using the staticcheck tool (plus a couple other static analysis fixups). It also adds this tool to our static-check make target so that it runs on every PR in Travis.

There will be PRs following up that will fix more static analysis issues and adding these checks to CI.

Testing

New tests cover the changes:

staticcheck tool was added to our Travis CI static-check make target. Currently only running the unused code check (U1000).

Description for the changelog

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sparrc sparrc force-pushed the static-analyser-fixes branch 5 times, most recently from 010ee89 to 5a39be7 Compare June 1, 2020 17:59
@sparrc sparrc added the bot/test label Jun 1, 2020
@sparrc sparrc added the bot/test label Jun 1, 2020
@sparrc sparrc changed the title [wip] Static analyser fixes Remove unused code, add staticcheck to TravisCI Jun 1, 2020
Makefile Outdated
@@ -263,6 +263,12 @@ gocyclo:
# Run gocyclo over all .go files
gocyclo -over 15 ${GOFILES}

.PHONY: staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/aws/amazon-ecs-agent/blob/master/Makefile#L330 we have static-check already, can we name this differently? unused-check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer staticcheck because it's the name of the tool we're using (https://github.com/dominikh/go-tools). We can't use unused-check because staticcheck does other checks that we will be adding soon.

If you'd prefer maybe I could do go-tools-staticcheck ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it as a command under the static-check target

Comment on lines -39 to -52
func TestIsNetworkStatsError(t *testing.T) {
isNetStatsErr := isNetworkStatsError(fmt.Errorf("no such file or directory"))
if isNetStatsErr {
// Expect it to not be a net stats error
t.Error("Error incorrectly reported as network stats error")
}

isNetStatsErr = isNetworkStatsError(fmt.Errorf("open /sys/class/net/veth2f5f3e4/statistics/tx_bytes: no such file or directory"))
if !isNetStatsErr {
// Expect this to be a net stats error
t.Error("Error incorrectly reported as non network stats error")
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this test removed?

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 was removed because the function it's testing was removed (isNetworkStatsError)

@sparrc sparrc added the bot/test label Jun 1, 2020
@sparrc sparrc added this to the 1.41.0 milestone Jun 2, 2020
@sparrc sparrc merged commit 2fbbb3a into aws:dev Jun 2, 2020
@sparrc sparrc deleted the static-analyser-fixes branch June 2, 2020 18:10
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