We want to enable golint on our codebase.
First, get golint:
go get -u github.com/golang/lint
Then run it on any package you want to lint:
# will lint entire project
golint ./...
# will lint single package in project
golint ./meta
Also, you can use this script to get an output of how many lint errors are in each package, and which packages are currently passing (thanks @Wind0r):
#!/bin/bash
#All Packages
PACKAGES=$(find . -name '*.go' -print0 | xargs -0 -n1 dirname | sort --unique)
echo 'packages needing linting'
for pkg in ${PACKAGES[@]}; do
echo $pkg $(golint $pkg | wc -l) | grep -v '\s0$'
done
echo ''
echo 'packages passing lint'
for pkg in ${PACKAGES[@]}; do
echo $pkg $(golint $pkg | wc -l) | grep '\s0$'
done
We want to do this for several reasons:
Following is the list of all github.com/influxdb/influxdb subpackages. For each we need to:
We also need to make it easy for contributors to easily give golint a local run before submitting the PR. We should probably have that script only cover a hardcoded list of packages that we can augment over time.
This PR is modeled after Dockers initiative to do the same with their project: https://github.com/docker/docker/issues/14756
one problem is that golint explicitly states that the tool shouldn’t be used in automated build processes: https://github.com/golang/lint#purpose
"do not expect or require code to be completely "lint-free". In short, this tool is not, and will never be,
trustworthy enough for its suggestions to be enforced automatically, for example as part of a build
process."
So there is no ability to specify ANY ignores for exceptions to the rules, like there is with other tools like pylint. And they reject PRs by people trying to change that...
you could always just enforce that the number of lint errors is less than the number of exceptions with a wc -l, I was doing something like that with go fmt in telegraf
Just to get things going I will start with root and client.
So far it looks like root, uuid, and cluster are merged. @corylanou could you update the todo list?
Please let me know if I should make more changes to #4173 or close it? Thanks.
I will start working on influxql and influxd
@corylanou client is merged.
Starting work on cluster/internal.
I run a little script on the codebase to count the warnings.
(Not all folders. Only that one that are ask above)
cluster/internal 28
cmd/influx 13
cmd/influx_stress 0
cmd/influxd 2
cmd/influxd/backup 0
cmd/influxd/help 0
cmd/influxd/restore 1
cmd/influxd/run 4
cmd/influx_inspect 5
importer/v8 0
influxql 28
meta 15
meta/internal 368
monitor 9
pkg/slices 3
services/admin 2
services/collectd 1
services/collectd/test_client 0
services/continuous_querier 7
services/copier 0
services/copier/internal 10
services/graphite 12
services/hh 11
services/httpd 7
services/opentsdb 3
services/precreator 1
services/retention 2
services/snapshotter 0
services/udp 7
snapshot 0
statik 0
tcp 0
tests/urlgen 3
toml 0
tsdb 100
tsdb/engine 1
tsdb/engine/b1 5
tsdb/engine/bz1 6
tsdb/engine/wal 19
tsdb/internal 24
So following packages can be marked as done and enabled in ci
cmd/influx_stress 0
cmd/influxd/backup 0
cmd/influxd/help 0
importer/v8 0
services/collectd/test_client 0
services/copier 0
services/snapshotter 0
snapshot 0
statik 0
tcp 0
toml 0
@Wind0r can you share a gist of the script then we can use it here as well and all stay on the same page. Thanks!
Sure. Need to be executed in the influxdb/influxdb folder.
Not the best but i works ;)
Combine with " | grep ' 0' " to get the finished ones.
Awesome, thanks!
@corylanou services/udp is done and passes. ref commit is 434d060
@corylanou
PR #4835 makes golint pass on these dirs
services/collectd
services/precreator
services/subscriber
cmd/influxd is done.
@corylanou: PR #5366 enables golint for influxql.
Starting tsdb/internal, but top level comment says not to edit? But am going to tackle it anyway.
@corylanou PR #5418 for enabling golint in tsdb/internal (sorry for the duplicate pull request, pushed the wrong branch).
Took care of tsdb/engine/wal.go and wal_test.go in PR#5550.
The list of packages should be updated (as some packages were added and some removed). Current status:
Generated with:
#!/bin/bash
#All Packages
PACKAGES=$(find . -name '*.go' -print0 | xargs -0 -n1 dirname | sort --unique)
for pkg in ${PACKAGES[@]}; do
if [ "$pkg" == "." ]; then
name="[root]"
else
name=${pkg:2}
fi
if [ $(golint $pkg | wc -l) -eq 0 ]; then
echo "- [x] $name"
else
echo "- [ ] $name"
fi
done
I'm tackling the rest of tsdb/engine. It looks like tsdb/internal should be taken off the list as the meta.pb.go generated protobuf file should not be edited:
https://github.com/influxdata/influxdb/pull/5418
Hi @nuss-justin, I was looking at the possible things to take up and I think you can check these off:
I am currently tackling cmd/ packages. Might be able to get a PR in 2 days.
@corylanou running lint on services/continuous_querier is returning: don't use an underscore in package name
Now, while I can change this and any package importing it, I think it will break someone else's code if they are importing it. How should I go forward?
@corylanou it seems as though package importer/v8 is fine per golint and can be marked as complete
Updated list (including influx_tsm changes:
Going to work on influxdb/stress, should be able to make a PR today
Hi,
I ran the linter on influxdb/influxql and there is some work there to be done which I would like to tackle if it is fine.
@clebs Sounds good. Let me know if you have any questions. Happy to help. Thanks!
Thanks for the quick response @corylanou!
In fact I do have one question :)
iterator_mapper.go has types and an interface that are exported but not documented, so the linter complains.
Nevertheless, they are only used inside the same package influxql. So my idea was to unexport them.
I can't do that because iterator_mapper_test.go has its own package influxql_test.
Is there a reason for that? Shouldn't it also have package influxql?
Thanks!
@jsternberg do you know the answer? Is it a matter of updating the generator (I think those files are generated, but didn't look). Thanks.
@clebs @corylanou influxql_test exists so that the exported API of the influxql is tested. It may or may not be possible to unexport types in influxql as we (InfluxData) may have other projects/tools depending on them.
@clebs one other piece of advice — if the file ends in .gen.go then you will need to lint the .gen.go.tmpl file and re-run go generate. 👍
Hi @e-dard and thanks for the tips!
I see, so the reason is to test the public API only... I am then wondering if those types really need to be tested from an external perspective. Right now they look to me like internal works on how the QL gets and processes queried data.
I will give it a thought and either document the exported types or come back to seek consensus on unexporting them and adapting the tests.
I wanted to spend this weekend a couple of hours and make a few of these packages lintable.
Regarding influxdb/services/graphite package. In the parser.go file the exported function NewTemplate returns a pointer to an unexported type *graphite.template. To make it also testable it is idiomatic to return an exported interface if not an exported struct, then the returned satisfying struct of that interface can be unexported. That would make the linter pass for that specific line. What you think?
@corylanou I was looking at tackling influxdb/services/httpd it looks like all of the currently exported Structs/functions without comments are only used within the httpd package. Would you prefer them to be changed to private? It should be pretty straight forward to go either way I just wanted to see if there was a preference.
@jrbury I'm no longer with Influx but hopefully someone else can give you direction on the issue from the team.
@corylanou Thanks! Maybe @e-dard would know and/or point me towards who would
@jrbury can you give me some example struct/methods you're talking about?
For example in httpd/requests.go there is
type RequestInfo struct {
IPAddr string
Username string
}
type RequestStats struct {
Writes int64 `json:"writes"`
Queries int64 `json:"queries"`
}
Currently, neither of these structs are accessed outside of the httpd package, so I could make them private, but if they were designed with the intent to be able to access them, then I'll just comment them.
I think before we continue working on this, we need a way to make sure that packages that have been made golintable stay golinted. That usually means the build has to fail.
So I would say if you want to start somewhere, updating the build system so that it runs golint on a subset of directories that have been golinted already is the first thing that has to be done before we bother accepting more PR's for this issue. Without that, this issue will have no end since we will just continue writing code and forgetting to run golint to check it.
Can we get the latest state? I see that the updating is about 10 months ago.
@corylanou
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had recent activity. Please reopen if this issue is still important to you. Thank you for your contributions.
Most helpful comment
Updated list (including
influx_tsmchanges: