On Wed, Apr 19, 2017 at 9:25 AM, Kamil Dziedzic <arve...@gmail.com> wrote:
>
> One thing that annoys me often while going through long source code file is
> that often function declarations are organized in some random order. I was
> thinking about using some tool (at least for my projects) to automatically
> order all function declarations. This seems to be already true for
> generating documentation, e.g. here https://golang.org/pkg/database/sql/ you
> can see declarations are sorted (also grouped - variables first, functions
> second, structs last).
>
> I've put in the title gofmt, as it makes sense such option could be in
> gofmt, but I understand such crazy idea would affect waaaay to much projects
> :) So I rather think about separate tool.
>
> Did anyone thought about such tool already? Or I'm on my own and probably
> gofmt is best starting point to develop similar tool? It's a bit hard to
> google that as first thing I get are references to "sort" package.

It's intentional that gofmt does not reorder top level declarations.
The programmer is expected to arrange those declarations in some order
that makes sense to people reading the source code.

It shouldn't be hard to use go/parser and go/format to do what you want.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to