Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13561)

Issue 92250045: code review 92250045: go.tools/astutil: fix edge case in DeleteImport causing... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 11 months ago by shurcooL
Modified:
9 years, 11 months ago
Reviewers:
bradfitz
CC:
golang-codereviews, gobot, adonovan, bradfitz
Visibility:
Public.

Description

go.tools/astutil: fix edge case in DeleteImport causing merging of import sections. The issue occurs only when deleting an import that has a blank line immediately preceding, and other imports before that. Currently, DeleteImport assumes there's a blank line-sized hole left behind where the import was, and always deletes it. That blank line-sized hole is there in all cases except the above edge case. This fix checks for that edge case, and does not remove the blank line-sized hole. The CL also adds a previously failing test case that catches this scenario. After the change to DeleteImport, the new test passes (along with all other tests). Fixes issue 7679. Note that there is no attempt to ensure the result *ast.File and *token.FileSet are perfectly matching to what you would get if you printed the AST and parsed it back. This is how the rest of the package and the current tests work (i.e., they only check that printing the AST gives the correct output). Changing that is very hard, if not impossible, at least not without resorting to manipulating AST via printing, text manipulation and parsing. This is okay for most usages, but it does create potential problems. For example, astutil.Imports() currently only works correctly on freshly parsed AST. If that AST is manipulated via astutil funcs, then Imports() may not always generate correct output. However, thas is a separate issue and should be treated as such.

Patch Set 1 #

Patch Set 2 : diff -r 994ab8ea78ff https://code.google.com/p/go.tools #

Patch Set 3 : diff -r 994ab8ea78ff https://code.google.com/p/go.tools #

Patch Set 4 : diff -r 994ab8ea78ff https://code.google.com/p/go.tools #

Unified diffs Side-by-side diffs Delta from patch set Stats (+105 lines, -4 lines) Patch
M astutil/imports.go View 1 1 chunk +15 lines, -4 lines 0 comments Download
M astutil/imports_test.go View 1 1 chunk +55 lines, -0 lines 0 comments Download
M imports/fix_test.go View 1 2 3 1 chunk +35 lines, -0 lines 0 comments Download

Messages

Total messages: 4
shurcooL
Hello golang-codereviews@googlegroups.com (cc: bradfitz, golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go.tools
9 years, 11 months ago (2014-05-11 22:01:35 UTC) #1
gobot
R=adonovan@google.com (assigned by r@golang.org)
9 years, 11 months ago (2014-05-19 17:09:56 UTC) #2
bradfitz
LGTM I think. AST scares me.
9 years, 11 months ago (2014-05-19 20:52:05 UTC) #3
bradfitz
9 years, 11 months ago (2014-05-19 21:04:32 UTC) #4
*** Submitted as
https://code.google.com/p/go/source/detail?r=40ad4f3c94ed&repo=tools ***

go.tools/astutil: fix edge case in DeleteImport causing merging of import
sections.

The issue occurs only when deleting an import that has a blank line immediately
preceding,
and other imports before that.

Currently, DeleteImport assumes there's a blank line-sized hole left behind
where the import was, and always deletes it. That blank line-sized hole is there
in all cases
except the above edge case.

This fix checks for that edge case, and does not remove the blank line-sized
hole.

The CL also adds a previously failing test case that catches this scenario.
After the change to
DeleteImport, the new test passes (along with all other tests).

Fixes issue 7679.

Note that there is no attempt to ensure the result *ast.File and *token.FileSet
are perfectly
matching to what you would get if you printed the AST and parsed it back. This
is how the
rest of the package and the current tests work (i.e., they only check that
printing the AST gives
the correct output).
Changing that is very hard, if not impossible, at least not
without resorting to manipulating AST via printing, text manipulation and
parsing.
This is okay for most usages, but it does create potential problems. For
example,
astutil.Imports() currently only works correctly on freshly parsed AST. If that
AST
is manipulated via astutil funcs, then Imports() may not always generate correct
output. However, thas is a separate issue and should be treated as such.

LGTM=bradfitz
R=golang-codereviews, gobot, adonovan, bradfitz
CC=golang-codereviews
https://codereview.appspot.com/92250045

Committer: Brad Fitzpatrick <bradfitz@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b