JetBrains GoLang IDE. How to remove last empty line and how to add empty lines?

Viewed 201

I'm using JetBrains GoLang IDE, and couple of parameters are not applied, somehow.

  • I want to remove last line
  • I want to be able to add empty lines, in the middle
package main
>
> I want an empty line
import (...)
func main() {
    ...
    ...
}
> I don't want this line

I don't see such issues with PyCharm, and WebStorm, I guess it is GoLang feature. I've tried EditorConfig plugin set it up, but it is not working at all

root = true

[*]
charset = utf-8
tab_width = 4
end_of_line = lf
indent_size = 4
indent_style = space
max_line_length = 120
insert_final_newline = false
ij_continuation_indent_size = 8

I do understand that there are maybe some standarts, but this is annoying, I get used to different style of code

1 Answers

New versions of GoLand use gofmt on save (Command/Ctrl+S or any action, e.g., switch to a different window) that reformats your files in this way.

On the other hand, GoLand has a built-in formatter (Code | Reformat Code) that formats the code the same way as gofmt, but allows you to change some style settings via Preferences/Settings | Editor | Code Style | Go.

To disable these features, you can disable two things:

  • Preferences/Settings | Tools | Actions on Save | Reformat Code.
  • Preferences/Settings | Editor | Code Style | Go | Other | Run gofmt on code reformat.

It will allow you to use your custom code style until you run gofmt or Reformat Code action manually.

Anyway, please keep in mind that gofmt is a de-facto standard in the Go world and it is not recommended to use a custom code style without serious reasons, e.g. Effective Go says:

Formatting issues are the most contentious but the least consequential. People can adapt to different formatting styles but it's better if they don't have to, and less time is devoted to the topic if everyone adheres to the same style. The problem is how to approach this Utopia without a long prescriptive style guide.

With Go we take an unusual approach and let the machine take care of most formatting issues. The gofmt program (also available as go fmt, which operates at the package level rather than source file level) reads a Go program and emits the source in a standard style of indentation and vertical alignment, retaining and if necessary reformatting comments. If you want to know how to handle some new layout situation, run gofmt; if the answer doesn't seem right, rearrange your program (or file a bug about gofmt), don't work around it.

Related