Skip to content

Commit

Permalink
Merge pull request #25 from incu6us/feature/ISSUE-23
Browse files Browse the repository at this point in the history
#23 Place local packages separately from project(main code base)
  • Loading branch information
incu6us authored Oct 16, 2020
2 parents a2d1e7b + 7bc087e commit a1a5d88
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ changelog:
- "^test:"

release:
prerelease: auto
github:
owner: incu6us
name: goimports-reviser
Expand Down
2 changes: 1 addition & 1 deletion reviser/reviser.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func groupImports(

var isLocalPackageFound bool
for _, localPackagePrefix := range localPackagePrefixes {
if strings.HasPrefix(pkgWithoutAlias, localPackagePrefix) {
if strings.HasPrefix(pkgWithoutAlias, localPackagePrefix) && !strings.HasPrefix(pkgWithoutAlias, projectName) {
projectLocalPkgs = append(projectLocalPkgs, imprt)
isLocalPackageFound = true
break
Expand Down
90 changes: 89 additions & 1 deletion reviser/reviser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ import (
"github.com/incu6us/goimports-reviser/pkg"
"goimports-reviser/pkg"
)
// nolint:gomnd
func main(){
_ = fmt.Println("test")
Expand All @@ -762,6 +761,95 @@ import (
"goimports-reviser/pkg"
)
// nolint:gomnd
func main() {
_ = fmt.Println("test")
}
`,
wantChange: true,
wantErr: false,
},
{
name: "group local packages separately from project files",
args: args{
projectName: "github.com/incu6us/goimports-reviser/code/thispkg",
localPkgPrefixes: "github.com/incu6us/goimports-reviser/code",
filePath: "./testdata/example.go",
fileContent: `package testdata
import (
"fmt"
"github.com/3rdparty/pkg"
"github.com/incu6us/goimports-reviser/code/foopkg"
"github.com/incu6us/goimports-reviser/code/otherpkg"
"github.com/incu6us/goimports-reviser/code/thispkg/stuff"
"github.com/incu6us/goimports-reviser/code/thispkg/morestuff"
)
// nolint:gomnd
func main(){
_ = fmt.Println("test")
}
`,
},
want: `package testdata
import (
"fmt"
"github.com/3rdparty/pkg"
"github.com/incu6us/goimports-reviser/code/foopkg"
"github.com/incu6us/goimports-reviser/code/otherpkg"
"github.com/incu6us/goimports-reviser/code/thispkg/morestuff"
"github.com/incu6us/goimports-reviser/code/thispkg/stuff"
)
// nolint:gomnd
func main() {
_ = fmt.Println("test")
}
`,
wantChange: true,
wantErr: false,
},
{
name: "check without local packages",
args: args{
projectName: "github.com/incu6us/goimports-reviser/code/thispkg",
localPkgPrefixes: "",
filePath: "./testdata/example.go",
fileContent: `package testdata
import (
"fmt"
"github.com/3rdparty/pkg"
"github.com/incu6us/goimports-reviser/code/foopkg"
"github.com/incu6us/goimports-reviser/code/otherpkg"
"github.com/incu6us/goimports-reviser/code/thispkg/stuff"
"github.com/incu6us/goimports-reviser/code/thispkg/morestuff"
)
// nolint:gomnd
func main(){
_ = fmt.Println("test")
}
`,
},
want: `package testdata
import (
"fmt"
"github.com/3rdparty/pkg"
"github.com/incu6us/goimports-reviser/code/foopkg"
"github.com/incu6us/goimports-reviser/code/otherpkg"
"github.com/incu6us/goimports-reviser/code/thispkg/morestuff"
"github.com/incu6us/goimports-reviser/code/thispkg/stuff"
)
// nolint:gomnd
func main() {
_ = fmt.Println("test")
Expand Down

0 comments on commit a1a5d88

Please sign in to comment.