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 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 minux commented Jan 15, 2017

@dgryski
Copy link
Contributor

@dgryski 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

@josharian josharian commented Jan 15, 2017

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.

@josharian josharian closed this Jan 15, 2017
@timakin
Copy link
Contributor Author

@timakin 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.