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

cmd/gofmt: gofmt should rewrite snake-case. #18669

Closed
timakin opened this issue Jan 15, 2017 · 4 comments
Closed

cmd/gofmt: gofmt should rewrite snake-case. #18669

timakin opened this issue Jan 15, 2017 · 4 comments

Comments

@timakin
Copy link
Contributor

timakin commented Jan 15, 2017

When I declare a snake-case value like FOO_BAR_CONST, golint warn me to redefine with camel-case.
But gofmt won't do anything for it.
It should automatically rewrite a snake-case value to camel-case or pascal-case.
Is it too much?

@minux
Copy link
Member

minux commented Jan 15, 2017 via email

@dgryski
Copy link
Contributor

dgryski commented Jan 15, 2017

In the past I've done this with

golint |
   awk '/should be/{printf("gofmt -w -r %c%s -> %s%c .\n", 39, $9, $12, 39)}' |
   sh

@josharian
Copy link
Contributor

Thanks for the suggestion. But if your program contained:

const (
  FOO_BAR_CONST = 0
  FooBarConst = 1
)

Then gofmt would make your program cease to compile. And if someone else imported your package and used p.FOO_BAR_CONST, then changing it to FooBarConst would make someone else's code cease to compile.

gofmt must always be safe to run, so we cannot do this.

@timakin
Copy link
Contributor Author

timakin commented Jan 16, 2017

@josharian
Thank you for a critical example and your polite response.
This seems bad and I can figure out the risk.

@golang golang locked and limited conversation to collaborators Jan 16, 2018
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

5 participants