Skip to content

Commit

Permalink
leave comment blocks before imports
Browse files Browse the repository at this point in the history
  • Loading branch information
incu6us committed May 25, 2020
1 parent 946ab5a commit d9dd0f9
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 d9dd0f9

Please sign in to comment.