There are plenty of great options for keeping your code clean and consistent, whether you use these official code checkers or others provided by the community. You can always reassign it later if you want. For example, Goland includes gofmt support, and VSCode includes an official Go extension that can check your code whenever you save a file. It can be used as a drop-in replacement to format your Go code, and running gofmt. The tool is a fork of gofmt as of Go 1.20, and requires Go 1.19 or later. That is, gofumpt is happy with a subset of the formats that gofmt is happy with. If you choose ctrl+s like me, it will ask you what to do with the previous ctrl+s shortcut. Enforce a stricter format than gofmt, while being backwards compatible. In File -> Settings -> Keymap, select your macro located at "Main Menu -> Tools Edit -> "formatted save"Ĭlick "Add Keyboard Shortcut", then perform the keystroke you want. Currently, GoLand offers three ways to interact with ‘go fmt’: dedicated actions, before commit. Gofmt’d code is: easier to write: never worry about minor formatting concerns while hacking away, easier to read: when all code looks the same you need not mentally convert others’ formatting style into something you can understand. Name the macro (something like "formatted save") Running ‘go fmt’ on Save The current state. Gofmt is a tool that automatically formats Go source code. I have searched on google, and found quite a well solution / workaround to this problem:īelow is it (I have fixed the macro menu path below from Tools to Edit for P圜harm):Ĭode -> "Optimize Imports.", if a dialogue box appears, check the box that says "Do not show this message again.", then click "Run". It seems that due to performance consideration, IDEA will not try to detect current file change quite frequently. I have also tested on local file reformat and get the same result, it will just take more than 10 seconds to get the updated file in editor and for remote mounted smbfs file, it will take more than 2 minutes. Now that golint is duplicated, so alternatively we can use revive which is a faster linter for Go and runs the same rules as golint. gofmt automatically formats code, but golint is concerned with coding style so it just prints out a warning. go install /x/tools/cmd/goimportslatest In addition to fixing imports, goimports also formats your code in the same style as gofmt so it can be used as a replacement for your editor's gofmt-on-save hook. To me, the root cause seems to be that how IDEA treats/detects outside file change. golint is a linter tool for Go source code, which differs from gofmt. Overview Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones. Thanks for your effect for trying to fix this issue!
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |