Skip to content
This repository has been archived by the owner on Apr 11, 2019. It is now read-only.

Ignore generated code #33

Closed
petermattis opened this issue Mar 19, 2016 · 7 comments
Closed

Ignore generated code #33

petermattis opened this issue Mar 19, 2016 · 7 comments

Comments

@petermattis
Copy link

Generated code frequently has unused code/variables/constants/etc. For example:

~/Development/go/src/github.com/cockroachdb/cockroach pmattis/unused unused ./...
/Users/pmattis/Development/go/src/github.com/cockroachdb/cockroach/acceptance/cluster/testconfig.pb.go:171:6: func encodeFixed64Testconfig is unused
...
/Users/pmattis/Development/go/src/github.com/cockroachdb/cockroach/sql/parser/sql.y:254:2: field empty is unused
...
/Users/pmattis/Development/go/src/github.com/cockroachdb/cockroach/sql/pgwire/clientmessagetype_string.go:17:2: var _clientMessageType_index_2 is unused

The above files were generated by protoc, stringer and yacc respectively. All of the generated code has a header comment that says // Code generated by. Currently, I just grep to ignore warnings in generated code, but it seems preferable to have this logic builtin to the tool.

@dominikh
Copy link
Owner

I'm partial to looking for "DO NOT EDIT" as opposed to "Code generated by". This ties into golang/go#13560.

@petermattis, would "DO NOT EDIT" still match all your generated files?

@dmitshur
Copy link

would "DO NOT EDIT" still match all your generated files?

According to https://github.com/shurcooL/go/blob/master/analysis/generated_detection.go, which is the best current implementation I could come up with before golang/go#13560 is resolved, just "DO NOT EDIT" on its own is not enough to signal that a file is generated. It should also contain the word "GENERATED" or "generated". Although just "Code generated by" on its own is also enough.

@dmitshur
Copy link

just "DO NOT EDIT" on its own is not enough to signal that a file is generated

But maybe it should be?

@petermattis
Copy link
Author

DO NOT EDIT would work for protoc and stringer, but not for yacc. On the other hand, yacc doesn't put anything at the top. We currently manually whack in Code generate by as that triggers the github auto-generated code detection. We could certainly add something else.

@dominikh
Copy link
Owner

We'll match on DO NOT EDIT and Code generated by. I would've loved to push my DO NOT EDIT agenda, but I'd prefer if you didn't have to edit existing files to work with my tool.

@cespare
Copy link

cespare commented Mar 20, 2016

Are you just going to check in the header comment? (Or first N bytes / lines?)

@dominikh
Copy link
Owner

Are you just going to check in the header comment

We're checking the very first comment block in the file. If it turns out that people are putting their copyright notice before that comment (I haven't found anybody do that yet), we'll adjust it to check the first two comment blocks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants