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

github checks: gometalinter structcheck/varcheck/deadcode #3085

Closed
wants to merge 29 commits into from

Conversation

lkwg82
Copy link
Contributor

@lkwg82 lkwg82 commented May 12, 2016

Purpose

static code analysis: this add checks to build.go:

deadcode - Finds unused code.
structcheck - Find unused struct fields.
varcheck - Find unused global variables and constants.

see more on https://github.com/alecthomas/gometalinter

Testing

$ go run build.go setup
$ go run build.go lint

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 12, 2016

conversation from #3084

@lkwg82

mhm, I thought these checks will be executed in jenkins and declared in build.go?

@AudriusButkevicius

Currently we just have

#!/bin/bash
set -euo pipefail

# Check for incorrectly formatted code
unformatted=$(gofmt -l $(find cmd/ lib/ -name \*.go))
if [ -z "$unformatted" ] ; then
    echo "Files formatted correctly"
    exit 0
else
    echo Files need gofmt:
    echo "$unformatted"
    exit 1
fi

which publishes stuff back into github.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 12, 2016

My understanding is, that every developer can run locally these checks. So I suggest to add these checks in the project and make them usable with e.g. ./build.sh check.

These checks should run on jenkins with ./build.sh ci-fmt-check in another job ./build.sh ci-xyz-check ... and so on. But aggregated for devs in one call.

@lkwg82 lkwg82 added the build Issues caused by or requiring changes to the build system (scripts or Docker image) label May 12, 2016
@AudriusButkevicius
Copy link
Member

Potentially, as a general blanket check yet, though in the PR's it might be nice to have detailed checks.

@calmh
Copy link
Member

calmh commented May 13, 2016

If it's structcheck we want, I think we should pull in https://github.com/opennota/check directly. I use the metalinter now and then, but find it way too noisy in the general case.

@calmh
Copy link
Member

calmh commented May 13, 2016

The checks that we want to run always are run as part of regular install (i.e. go run build.go without parameters) already - lint and vet. We should add this there as well.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 13, 2016

I see metalinter as a frontend. I just tried structcheck directly and I has inconvinient path handling. I rather prefer metalinter with a selected set of linters. Evaluate one by one.

@calmh
Copy link
Member

calmh commented May 14, 2016

That's fair. In that case I'd focus on the tool that you used for the dead code analysis for example, as that has proven itself in finding stuff that we've left behind. :) But regardless, the preferred way to me would be to hook into the place where we do the current vet and lint calls. Verify that that it (the function in build.go) correctly understands the difference between an error because the linter isn't installed and an error because the linter found something wrong - fail the build in the latter case.

I don't expect the exit code 3 check to work on metalinter not being installed, for example.

@@ -230,17 +235,26 @@ func main() {
clean()

case "vet":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we can merge vet and lint command as only lint?

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 14, 2016

Why is lint not a github check?

@lkwg82 lkwg82 changed the title github checks: gometalinter structcheck github checks: gometalinter structcheck/varcheck/deadcode May 14, 2016
@calmh
Copy link
Member

calmh commented May 15, 2016

Lint is informational and not meant to be 100% enforced. It is however run as part of the pr-build step, it just doesn't fail the build. go vet is also run there and does fail the build on issues.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 15, 2016

I'd like to see it enforced, so vetmight be the better location for that, isn't it?


func (g *gometalinter) deadline(deadlineInSeconds int) *gometalinter {
g.deadlineInSeconds = deadlineInSeconds
return g
Copy link
Member

Choose a reason for hiding this comment

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

This feels so java.
Yet if we go this way, I'd do this on a non-pointer receiver.

Copy link
Contributor Author

@lkwg82 lkwg82 May 16, 2016

Choose a reason for hiding this comment

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

This feels so java.

Do you feel bad vibrations? ;)

}
g.verifiedInstallation = true
Copy link
Member

Choose a reason for hiding this comment

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

This will still verify it multiple times, as the methods are no longer pointer receivers, and you have multiple instances of the objects anyway.

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 mixed. So this should still be valid.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand.
How is performing existence checks once before the whole song less beneficial than constructing 3 objects, chaining them multiple times and then calling run just to do nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, due to creating new instances, this is b*shit. I need to fix it. Too late yesterday.

I'd like to keep it encasulated and maybe checked multiple times. This should be a performance penalty of 200ms(?) each run. Else it become cluttered.

If it wasn't in the build tool it would have been a different thing.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 18, 2016

@calmh sometimes it feels to have too few changes to extra do a pull request. But lets have a try ;)

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 18, 2016

@calmh Thought maybe baby commits makes the diff easier. But seems you review the total diff.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 18, 2016

@st-jenkins retest plz

@AudriusButkevicius
Copy link
Member

@st-jenkins whitelist

@AudriusButkevicius
Copy link
Member

@st-jenkins retest this please

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 22, 2016

Anything left?

@AudriusButkevicius
Copy link
Member

Looks fine, but I'll leave for @calmh to merge

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 22, 2016

ok

@calmh
Copy link
Member

calmh commented May 23, 2016

Lgtm apart from being too noisy. We don't print or time any other checks so no reason to do it here either, and the "no output = no issues" property is convenient when using this as a check from other places. Remove that and merge. :)

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 23, 2016

@st-review merge

build.go: add gometalinter to lint runs

@st-review
Copy link

👌 Merged as b78bfc0. Thanks, @lkwg82!

@st-review st-review closed this May 23, 2016
st-review pushed a commit that referenced this pull request May 23, 2016
@lkwg82 lkwg82 deleted the github-checks branch May 23, 2016 21:19
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jun 16, 2017
@syncthing syncthing locked and limited conversation to collaborators Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
build Issues caused by or requiring changes to the build system (scripts or Docker image) frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants