-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adding gofumpt #1177
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
Adding gofumpt #1177
Conversation
Hey, thank you for opening your first Pull Request ! |
issues = append(issues, goanalysis.NewIssue(&result.Issue{ | ||
FromLinter: gofumptName, | ||
Text: "File is not `gofumpt`-ed", | ||
Pos: token.Position{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a Replacement
parameter to automatically fix issues, which is very useful for gofumpt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken, gofumpt provides only as a public function a way to get the gofumpt-ed version of the file (as a []byte
).
With Replacement
you mean I should include the gofumpt-ed version of the whole file in the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tetafro Am I correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gofumpt provides only as a public function a way to get the gofumpt-ed version of the file
Yeah, sorry, I didn't think of it.
With Replacement you mean I should include the gofumpt-ed version of the whole file in the issue?
I'm not sure if it's a right thing to do. Someone more experienced with golangci-lint architecture should answer.
Anyway, if there's no easy way to do this, just skip my first comment.
Can you please add test to tests/testdata? |
issues = append(issues, goanalysis.NewIssue(&result.Issue{ | ||
FromLinter: gofumptName, | ||
Text: "File is not `gofumpt`-ed", | ||
Pos: token.Position{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gofumpt provides only as a public function a way to get the gofumpt-ed version of the file
Yeah, sorry, I didn't think of it.
With Replacement you mean I should include the gofumpt-ed version of the whole file in the issue?
I'm not sure if it's a right thing to do. Someone more experienced with golangci-lint architecture should answer.
Anyway, if there's no easy way to do this, just skip my first comment.
pkg/lint/lintersdb/manager.go
Outdated
@@ -191,6 +191,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { | |||
WithPresets(linter.PresetFormatting). | |||
WithAutoFix(). | |||
WithURL("https://golang.org/cmd/gofmt/"), | |||
linter.NewConfig(golinters.NewGofumpt()). | |||
WithPresets(linter.PresetFormatting). | |||
WithAutoFix(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no autofix, you should remove this line
# Conflicts: # go.sum
@tetafro I've just added a test. Just something to mention, previously I was setting the error line to 0. I wanted to change it to line 1 but in the test file, I can't do this:
Hence, I set it to the last line number and it's working correctly. |
I've looked how gofmt linter is implemented. Seems like the right thing to do here is to re-use diff code from gofmt linter. But I think using the last line is ok for the first iteration. Maybe just add |
pkg/golinters/gofumpt.go
Outdated
return nil, fmt.Errorf("error while running gofumpt: %w", err) | ||
} | ||
if !bytes.Equal(input, output) { | ||
reader, err := os.Open(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary? You've already read the file into input
. Just use strings.Count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good to me.
@tetafro Any chance to get it merged then? :) |
Yeah, sorry for delay |
Hey, @teivah — we just merged your PR to
By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests. Thanks again! |
Thanks @tetafro |
Hi, how's the doc updated once a new linter is merged? |
@tetafro Just out of curiosity, when do you plan roughly to make a new release? |
@teivah this is a question for guys from core team. I just help with pr reviews from time to time. |
Hey!
I was also interested in #490 (adding gofumpt).
Here is a PR for it.