1
0
mirror of https://github.com/golang/go synced 2024-10-04 08:21:22 -06:00
Commit Graph

163 Commits

Author SHA1 Message Date
Robert Griesemer
dddc8b193f cmd/gofmt: fix gofmt -s for 3-index slices
3-index slices of the form s[:len(s):len(s)]
cannot be simplified to s[::len(s)].

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/108330043
2014-07-01 10:40:27 -07:00
Simon Whitehead
138099ae96 gofmt/main: Added removal of empty declaration groups.
Fixes #7631.

LGTM=gri
R=golang-codereviews, bradfitz, gri
CC=golang-codereviews
https://golang.org/cl/101410046
2014-07-01 09:32:03 -07:00
Robert Griesemer
6a22823939 gofmt: remove redundant check in rewriter
If the actual types of two reflect values are
the same and the values are structs, they must
have the same number of fields.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/108280043
2014-06-30 14:40:12 -07:00
Shenghou Ma
ca6be91cbc all: fix "the the" typos.
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/93470043
2014-05-20 14:42:07 -04:00
Robert Griesemer
e9ee0bf63c cmd/gofmt: minor internal cleanups
Reflect changes of reflect API.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/69240044
2014-02-27 09:00:27 -08:00
Brad Fitzpatrick
014f3dcc83 cmd/gofmt: remove -tabwidth and -tabs flags
Having these flags misleads people into thinking they're acceptable
for code that "must be gofmt'd".

If an organization wishes to use gofmt internally with
different settings, they can fork gofmt trivially. But "gofmt"
as used by the community with open source Go code should not
support these old knobs.

Also removes the -comments flag.

Fixes #7101

R=r, gri
CC=golang-codereviews
https://golang.org/cl/52170043
2014-01-14 11:10:56 -08:00
Robert Hencke
a51b8cf870 gofmt: explain why lower bounds aren't automatically simplified
Full credit goes to gri and rsc for their explanations.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14229043
2013-10-03 10:55:17 -07:00
Andrew Gerrand
d445b76331 cmd/gofmt: document -s transformations
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13721043
2013-09-16 11:19:39 +10:00
Josh Bleecher Snyder
08925ce6ee cmd/gofmt: sort more, remove some duplicate imports
* Sort imports by import path, then import name, then comment. Currently, gofmt sorts only by import path.
* If two imports have the same import path and import name, and one of them has no comment, remove the import with no comment. (See the discussion at issue 4414.)

Based on @rsc's https://golang.org/cl/7231070/

Fixes #4414.

R=gri, rsc
CC=golang-dev
https://golang.org/cl/12837044
2013-09-06 16:25:15 -04:00
Robert Griesemer
2ba6ecb3e2 go/parser: ParseExpr must accept type expressions
My old code was trying to be too smart.
Also: Slightly better error message format
for gofmt -r pattern errors.

Fixes #4406.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/8267045
2013-04-03 07:41:26 -07:00
Robert Griesemer
9115e411f5 cmd/gofmt: handle ... in rewrite of calls
Fixes #5059.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8284043
2013-04-02 13:18:32 -07:00
Robert Griesemer
3ee87d02b0 cmd/godoc: use go/build to determine package and example files
Also:
- faster code for example extraction
- simplify handling of command documentation:
  all "main" packages are treated as commands
- various minor cleanups along the way

For commands written in Go, any doc.go file containing
documentation must now be part of package main (rather
then package documentation), otherwise the documentation
won't show up in godoc (it will still build, though).

For commands written in C, documentation may still be
in doc.go files defining package documentation, but the
recommended way is to explicitly ignore those files with
a +build ignore constraint to define package main.

Fixes #4806.

R=adg, rsc, dave, bradfitz
CC=golang-dev
https://golang.org/cl/7333046
2013-02-19 11:19:58 -08:00
Robert Griesemer
5b1885c241 go/parser: cleanups following CL 7307085
- use the new AllErrors flag where appropriate
- unless AllErrors is set, eliminate spurious
  errors before they are added to the errors list
  (it turns out that reporting spurious errors always
  leads to too many uninformative errors after all)

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7323065
2013-02-14 13:36:40 -08:00
Shenghou Ma
d46d0f15a7 all: remove exec bit on files
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7128048
2013-01-18 02:41:17 +08:00
Robin Eklind
f36a53cd5d cmd/gofmt, bufio, image: Consistency and error handling.
cmd/gofmt: Add error handling for ioutil.WriteFile.
bufio: Consistency, rename e to err.
image: Consistency, fix comment for asReader.

R=golang-dev, dave, minux.ma, adg
CC=golang-dev
https://golang.org/cl/7029056
2013-01-07 11:15:53 +11:00
Matthew Dempsky
46811d27ce src: Use bytes.Equal instead of bytes.Compare where possible.
bytes.Equal is simpler to read and should also be faster because
of short-circuiting and assembly implementations.

Change generated automatically using:
  gofmt -r 'bytes.Compare(a, b) == 0 -> bytes.Equal(a, b)'
  gofmt -r 'bytes.Compare(a, b) != 0 -> !bytes.Equal(a, b)'

R=golang-dev, dave, adg, rsc
CC=golang-dev
https://golang.org/cl/7038051
2013-01-07 10:03:49 +11:00
Robert Griesemer
42a854b746 gofmt: test rewrite of (x.(type)) -> x.(type)
R=rsc
CC=golang-dev
https://golang.org/cl/6867062
2012-12-06 09:20:03 -08:00
Robert Griesemer
0cbca268d8 gofmt: simplify slices of the form s[a : len(s)] to s[a:]
Fixes #4314.

R=r, rsc
CC=golang-dev
https://golang.org/cl/6822059
2012-10-31 11:48:55 -07:00
Robert Griesemer
83601807af gofmt: added testcase for files containing \r\n line endings
(see also issue 3961).

hexdump -c testdata/crlf.input
0000000   /   *  \r  \n  \t   S   o   u   r   c   e       c   o   n   t
0000010   a   i   n   i   n   g       C   R   /   L   F       l   i   n
0000020   e       e   n   d   i   n   g   s   .  \r  \n  \t   T   h   e
0000030       g   o   f   m   t   '   e   d       o   u   t   p   u   t
0000040       m   u   s   t       o   n   l   y       h   a   v   e
0000050   L   F  \r  \n  \t   l   i   n   e       e   n   d   i   n   g
0000060   s   .  \r  \n   *   /  \r  \n   p   a   c   k   a   g   e
0000070   m   a   i   n  \r  \n  \r  \n   f   u   n   c       m   a   i
0000080   n   (   )       {  \r  \n  \t   /   /       l   i   n   e
0000090   c   o   m   m   e   n   t  \r  \n  \t   p   r   i   n   t   l
00000a0   n   (   "   h   e   l   l   o   ,       w   o   r   l   d   !
00000b0   "   )       /   /       a   n   o   t   h   e   r       l   i
00000c0   n   e       c   o   m   m   e   n   t  \r  \n  \t   p   r   i
00000d0   n   t   l   n   (   )  \r  \n   }  \r  \n
00000db

hexdump -c testdata/crlf.golden
0000000   /   *  \n  \t   S   o   u   r   c   e       c   o   n   t   a
0000010   i   n   i   n   g       C   R   /   L   F       l   i   n   e
0000020       e   n   d   i   n   g   s   .  \n  \t   T   h   e       g
0000030   o   f   m   t   '   e   d       o   u   t   p   u   t       m
0000040   u   s   t       o   n   l   y       h   a   v   e       L   F
0000050  \n  \t   l   i   n   e       e   n   d   i   n   g   s   .  \n
0000060   *   /  \n   p   a   c   k   a   g   e       m   a   i   n  \n
0000070  \n   f   u   n   c       m   a   i   n   (   )       {  \n  \t
0000080   /   /       l   i   n   e       c   o   m   m   e   n   t  \n
0000090  \t   p   r   i   n   t   l   n   (   "   h   e   l   l   o   ,
00000a0       w   o   r   l   d   !   "   )       /   /       a   n   o
00000b0   t   h   e   r       l   i   n   e       c   o   m   m   e   n
00000c0   t  \n  \t   p   r   i   n   t   l   n   (   )  \n   }  \n
00000cf

R=rsc
CC=golang-dev
https://golang.org/cl/6526052
2012-09-19 14:14:21 -07:00
Robert Griesemer
96a609c2d7 gofmt: handle comments correctly in rewrites
R=rsc
CC=golang-dev
https://golang.org/cl/6294076
2012-06-25 13:58:28 -07:00
Yasuhiro Matsumoto
7694da1f3b cmd/gofmt: show ascii in usage.
windows cmd.exe can't show utf-8 correctly basically.
chcp 65001 may make it show, but most people don't have fonts which can
show it.

R=golang-dev, rsc, adg, gri, r
CC=golang-dev
https://golang.org/cl/5820060
2012-03-15 16:38:27 -07:00
Mikio Hara
dfb1af4b97 cmd/gofmt: fix race in long test
Fixes #3249.

R=rsc
CC=golang-dev
https://golang.org/cl/5792043
2012-03-08 23:56:26 +09:00
Nigel Tao
85d33918a0 cmd, pkg/go/*: fix "go vet" warnings for go/ast and go/printer
struct literals.

R=gri
CC=golang-dev
https://golang.org/cl/5653073
2012-02-16 22:43:41 +11:00
Robert Griesemer
47afa4dba5 go/printer: don't lose relevant parentheses when rewriting selector expressions
Also: Simplified handling of selector expressions. As a result, complicated
multi-line expressions containing selectors and calls/indices with arguments
broken accross lines don't get indented the same way as before, but the change
is minimal (see tests) and there's no such code in the std library. It seems
a worthwhile compromise given the much simpler code.

Applied gofmt -w $GOROOT/src $GOROOT/misc .

Fixes #1847.

R=rsc
CC=golang-dev
https://golang.org/cl/5675062
2012-02-15 12:25:37 -08:00
Robert Griesemer
2233942e3c gofmt: fix error message in test
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5652066
2012-02-10 21:47:18 -08:00
Robert Griesemer
f8cf82f6f2 go/printer: implement SourcePos mode
If a printer is configured with the SourcePos mode
set, it will emit //-line comments as necessary to
ensure that the result - if reparsed - reflects the
original source position information.

This change required a bit of reworking of the
output section in printer.go. Specifically:

- Introduced new Config mode 'SourcePos'.

- Introduced new position 'out' which tracks the
position of the generated output if it were read
in again. If there is a discrepancy between out
and the current AST/source position, a //line
comment is emitted to correct for it.

- Lazy emission of indentation so that //line
comments can be placed correctly. As a result,
the trimmer will have to do less work.

- Merged writeItem into writeString.

- Merged writeByteN into writeByte.

- Use a []byte instead of a byte.Buffer both in the
printer and in the trimmer (eliminates dependency).

Also: introduced explicit printer.Mode type (in
sync w/ parser.Mode, scanner.Mode, etc.)

Runs all tests. Applied gofmt to src, misc w/o changes.

Fixes #1047.
Fixes #2697.

R=rsc, rsc
CC=golang-dev
https://golang.org/cl/5643066
2012-02-10 13:27:32 -08:00
Robert Griesemer
467f8751f9 gofmt: replace defunct test.sh with a go test
R=r, rsc
CC=golang-dev
https://golang.org/cl/5639053
2012-02-08 08:47:02 -08:00
Rob Pike
1f565e7d20 tools: update references to "x" to be "go tool x"
For instance, don't talk about gofix, talk about the
fix tool or "go tool fix".

R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/5608053
2012-02-04 07:03:20 +11:00
Russ Cox
2050a9e478 build: remove Make.pkg, Make.tool
Consequently, remove many package Makefiles,
and shorten the few that remain.

gomake becomes 'go tool make'.

Turn off test phases of run.bash that do not work,
flagged with $BROKEN.  Future CLs will restore these,
but this seemed like a big enough CL already.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
2012-01-30 23:43:46 -05:00
Robert Griesemer
6e3af46e7d gofmt: fix test.sh
R=adg, iant
CC=golang-dev
https://golang.org/cl/5573062
2012-01-25 08:58:41 -08:00
Robert Griesemer
e7d513eab0 go/parser: Use explicit parser.Mode type.
R=r, bradfitz
CC=golang-dev
https://golang.org/cl/5574058
2012-01-24 16:36:20 -08:00
Olivier Duperray
c40314821b cmd/gofmt: fix simplify.go by running gofmt on cmd/gofmt
R=golang-dev
CC=golang-dev
https://golang.org/cl/5539061
2012-01-13 18:05:47 -08:00
Robert Griesemer
74cb963225 go/parser: Remove unused Parse* functions. Simplified ParseExpr signature.
Only ParseFile, ParseDir, and ParseExpr are used in the tree.
If partial parsing of code is required, it is fairly simple
to wrap the relevant piece of code into a dummy package for
parsing (see parser.ParseExpr).

Also: minor cleanups.

R=rsc
CC=golang-dev
https://golang.org/cl/5535055
2012-01-12 16:04:48 -08:00
Robert Griesemer
fe746335aa gofmt: simplify flags
-tabs replaces -tabindent
-spaces has been removed

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/5487066
2011-12-13 14:03:25 -08:00
Russ Cox
0dab624b70 gofmt: handle &T in composite literal simplify
R=gri
CC=golang-dev
https://golang.org/cl/5448086
2011-12-02 14:14:04 -05:00
Russ Cox
8dce57e169 os: new FileInfo, FileMode types + update tree
R=golang-dev, r, r, gri, bradfitz, iant, iant, nigeltao, n13m3y3r
CC=golang-dev
https://golang.org/cl/5416060
2011-11-30 12:04:16 -05:00
Robert Griesemer
4874d14180 go/printer: remove "written" result value - is never used
R=r
CC=golang-dev
https://golang.org/cl/5436052
2011-11-22 15:27:10 -08:00
Russ Cox
4d27f64863 gofmt: do not stop test.sh after 1 error
Fix bug377.go to be gofmt-compliant.

R=gri, r, r
CC=golang-dev
https://golang.org/cl/5400045
2011-11-16 18:44:21 -05:00
Rémy Oudompheng
2ba0798682 gofmt: leave nil nodes of the AST unchanged.
Without this check, gofmt panics when trying to apply
the identity transformation on "item.field" expressions.
Fixes #2410.

R=rsc, gri
CC=golang-dev, remy
https://golang.org/cl/5376061
2011-11-11 14:11:30 -08:00
Rob Pike
f9489bed72 renaming_4: gofix -r everything/but/src/pkg
R=rsc
CC=golang-dev
https://golang.org/cl/5338043
2011-11-08 15:43:02 -08:00
Russ Cox
4a9ebb18f1 gofmt, gofix: sort imports
Add ast.SortImports(fset, file) to go/ast, for use by both programs.

Fixes #346.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5330069
2011-11-02 15:53:57 -04:00
Russ Cox
44526cdbe0 non-pkg: gofix -r error -force=error
R=golang-dev, iant, r, r
CC=golang-dev
https://golang.org/cl/5307066
2011-11-01 22:06:05 -04:00
Russ Cox
313c8224d5 gofix -r mapdelete
R=golang-dev, r, adg, r, cw
CC=golang-dev
https://golang.org/cl/5266045
2011-10-18 09:56:34 -04:00
Russ Cox
236aff31c5 gofmt: fix //line handling
Fixes #2369.

R=gri
CC=golang-dev
https://golang.org/cl/5275048
2011-10-14 15:54:45 -04:00
Robert Griesemer
e9ba607bf5 gofmt: fix a couple of crashes, disallow rewrites for incomplete programs
The current implementation of formatting for incomplete programs
cannot tolerate program rewrites; ignore -rewrite in that case
with a warning message (temporary solution).

Fix a couple of crashes that were introduced recently.

Fixes #2348.

R=rsc
CC=golang-dev
https://golang.org/cl/5233054
2011-10-11 21:49:53 -07:00
Robert Griesemer
bb51de1cba gofmt: update test.sh
R=r
CC=golang-dev
https://golang.org/cl/5235043
2011-10-07 15:14:37 -07:00
Russ Cox
b039883946 gofmt: add else test
R=gri
CC=golang-dev
https://golang.org/cl/4978065
2011-09-14 11:29:18 -04:00
Rob Pike
4e3b725cf0 path/filepath: new signature for Walk
This one uses a closure than an interface, and is much simpler to use.
It also enables a called function to return an error and (possibly)
halt processing.

Fixes #2237.

R=golang-dev, gri, rsc, r, cw, n13m3y3r
CC=golang-dev
https://golang.org/cl/5014043
2011-09-13 17:47:59 -07:00
Russ Cox
48e9c771a1 gofmt: accept program fragments on standard input
This makes it possible to grab a block of code
in an editor and pipe it through gofmt, instead of
having to pipe in the entire file.

R=gri
CC=golang-dev
https://golang.org/cl/4973074
2011-09-12 15:41:49 -04:00
Robert Griesemer
49bcc88f79 undo CL 4964067 / 661cb84cc6f0
API change. Needs further reflection.

««« original CL description
path/filepath: Simplify Walk interface

The last argument of filepath.Walk was removed, and the Visitor
interface now contains an Error method that is called on errors.

Fixes #2237.

R=golang-dev, gri, r
CC=golang-dev
https://golang.org/cl/4964067

»»»

R=r
CC=golang-dev
https://golang.org/cl/4974065
2011-09-07 15:19:53 -07:00