Go: cmd/gofmt: weird indentation with block comments

Created on 26 Jan 2017  路  4Comments  路  Source: golang/go

Please answer these questions before submitting your issue. Thanks!

What did you do?

Block comments are formatted weirdly.

            /*
            * - Remove package from manifest
            *   - if the package IS NOT being used, solving should do what we want
            *   - if the package IS being used:
            *       - Desired behavior: stop and tell the user, unless --force
            *       - Actual solver behavior: ?
             */

What did you expect to see?

Comment beginner and ender is aligned correctly even though it requires adding indentation with spaces.

            /*
             * - Remove package from manifest
             *  - if the package IS NOT being used, solving should do what we want
             *  - if the package IS being used:
             *      - Desired behavior: stop and tell the user, unless --force
             *      - Actual solver behavior: ?
             */

System details

go version devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jbd"
GORACE=""
GOROOT="/Users/jbd/go"
GOTOOLDIR="/Users/jbd/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lq/qcn67khn4_1b41_g48x3zchh005d21/T/go-build547869116=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +6a3c6c0 Sat Jan 14 05:57:07 2017 +0000 X:framepointer
uname -v: Darwin Kernel Version 15.6.0: Wed Nov  2 20:30:56 PDT 2016; root:xnu-3248.60.11.1.2~2/RELEASE_X86_64
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G1212
lldb --version: lldb-360.1.70
NeedsFix

Most helpful comment

@rakyll It's very tricky to get this right. If the "line of stars" is aligned to start with, it works out most of the time. The problem is recognizing the "line of stars" as a line and not interfere when it's not. There's some support for the argument that gofmt should never touch comment internals in the first place. Fixing this requires meddling with the inside text of a /*-comment. Sometimes the heuristic will be wrong.

All 4 comments

/cc @griesemer

@rakyll It's very tricky to get this right. If the "line of stars" is aligned to start with, it works out most of the time. The problem is recognizing the "line of stars" as a line and not interfere when it's not. There's some support for the argument that gofmt should never touch comment internals in the first place. Fixing this requires meddling with the inside text of a /*-comment. Sometimes the heuristic will be wrong.

There's some support for the argument that gofmt should never touch comment internals in the first place.

That's exactly what I would like to see one day.

Moving this to 1.10 as it may have wider-ranging implications.

Was this page helpful?
0 / 5 - 0 ratings