Skip to content

Commit

Permalink
Merge pull request #16 from incu6us/hotfix/skip-replacing-comment-wit…
Browse files Browse the repository at this point in the history
…hout-imports

Skip replacing comments without imports
  • Loading branch information
incu6us authored Jun 15, 2020
2 parents 2a7c418 + 1ff76be commit 86b4af1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion reviser/reviser.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func clearImportDocs(f *ast.File, importsPositions []*importPosition) {
}
}

if len(importsComments) > 0 {
if len(f.Imports) > 0 {
f.Comments = importsComments
}
}
Expand Down
38 changes: 38 additions & 0 deletions reviser/reviser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,44 @@ import (
)
// nolint:gomnd
`,
wantChange: false,
wantErr: false,
},

{
name: "success no changes by imports and comments",
args: args{
projectName: "github.com/incu6us/goimports-reviser",
filePath: "./testdata/example.go",
fileContent: `package testdata
import (
"context"
"database/sql"
"fmt"
_ "github.com/lib/pq" // configure database/sql with postgres driver
"github.com/pkg/errors"
"go.uber.org/fx"
"github.com/incu6us/goimports-reviser/pkg/somepkg"
)
`,
},
want: `package testdata
import (
"context"
"database/sql"
"fmt"
_ "github.com/lib/pq" // configure database/sql with postgres driver
"github.com/pkg/errors"
"go.uber.org/fx"
"github.com/incu6us/goimports-reviser/pkg/somepkg"
)
`,
wantChange: false,
wantErr: false,
Expand Down

0 comments on commit 86b4af1

Please sign in to comment.