Skip to content

gofmt and gofix mangle line endings #2242

Closed
@gopherbot

Description

@gopherbot

by seanerussell:

Bug, or feature request?  I'm not sure.

Up to weekly.2011-06-23 8876 (b42014761d96), both gofix and gofmt mangle line endings. 
I argue that this is undesirable behavior, since it interferes with developers working
on different platforms.

To reproduce: create a Go source file on Linux, and run gofmt on it.  Take the resulting
file to a Windows machine, and run the exact same version of gofmt on it on Windows.

When run on Windows, gofmt will report that every file needs to be fixed (which is
incorrect), and if told to write the changes, will change the line endings of every line
in the file; consequently, version control systems will think every line has changed.

gofmt should be idempotent when the same version of gofmt is run on the same file on
different platforms.  In other words, gofmt should leave line endings alone.  It's
acceptable for gofmt to choose an EOL style when it has to insert or break lines.
Ideally, gofmt should grab the line ending of the first line in the file and use that
when it has to insert line endings, but otherwise leave line endings alone.

gofix does the same thing, changing the line endings on lines which it otherwise doesn't
touch.  This is slightly less onerous than gofmt's behavior, because gofmt is more of a
desirable candidate to be added as a pre-commit hook, or part of the build chain (for
example).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions