Indentation in Go: tabs or spaces?

前端 未结 2 1926
甜味超标
甜味超标 2021-01-30 19:17

Is there a standard Google Go coding conventions document somewhere that sets whether tabs or spaces are preferred for indentation in Go source code?

What is the official

2条回答
  •  借酒劲吻你
    2021-01-30 19:35

    EDIT 2: he original answer at the bottom is now incorrect. The correct section of the linked source file (current 30/12/2019) is:

    Gofmt formats Go programs. It uses tabs for indentation and blanks for alignment. Alignment assumes that an editor is using a fixed-width font.

    Thanks to TehSphinX for pointing this out!

    ALL INFO BELOW THIS LINE IS NOW INCORRECT

    EDIT: The original answer at the bottom is now incorrect. The correct section of the linked source file (current 25/07/2014) is:

    Gofmt formats Go programs.
    It uses tabs (width = 8) for indentation and blanks for alignment.

    Original answer (deprecated):

    Formatting control flags:
        -comments=true
            Print comments; if false, all comments are elided from the output.
        -tabs=true
            Indent with tabs; if false, spaces are used instead.
        -tabwidth=8
            Tab width in spaces.
    

提交回复
热议问题