Skip to content

Commit

Permalink
Merge pull request #13 from incu6us/hotfix/leave-comments-before-imports
Browse files Browse the repository at this point in the history
leave comment blocks before imports
  • Loading branch information
incu6us authored May 25, 2020
2 parents 946ab5a + d9dd0f9 commit 1dc66f2
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 @@ -281,7 +281,7 @@ type importPosition struct {
}

func (p *importPosition) IsInRange(comment *ast.CommentGroup) bool {
if p.Start >= comment.Pos() || comment.Pos() <= p.End {
if p.Start <= comment.Pos() && comment.Pos() <= p.End {
return true
}

Expand Down
38 changes: 38 additions & 0 deletions reviser/reviser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,44 @@ import (
_ "github.com/incu6us/goimports-reviser/testdata/innderpkg" // custom package
)
// nolint:gomnd
func main() {
_ = fmt.Println("test")
}
`,
wantChange: true,
wantErr: false,
},
{
name: "success with comments before imports",
args: args{
projectName: "github.com/incu6us/goimports-reviser",
filePath: "./testdata/example.go",
fileContent: `// Some comments are here
package testdata
// test
import (
"fmt" //fmt package
_ "github.com/incu6us/goimports-reviser/testdata/innderpkg" //custom package
)
// nolint:gomnd
func main(){
_ = fmt.Println("test")
}
`,
},
want: `// Some comments are here
package testdata
// test
import (
"fmt" // fmt package
_ "github.com/incu6us/goimports-reviser/testdata/innderpkg" // custom package
)
// nolint:gomnd
func main() {
_ = fmt.Println("test")
Expand Down

0 comments on commit 1dc66f2

Please sign in to comment.