incu6us / goimports-reviser

Right imports sorting & code formatting tool (goimports alternative)
MIT License
607 stars 72 forks source link

Getting error in formatting #118

Closed mehdihadeli closed 1 year ago

mehdihadeli commented 1 year ago

Hi, At first, thanks for this useful package. When I run this command, I get this error:

goimports-reviser -rm-unused -set-alias -format -recursive ./...

Error:

-: no Go files in \services\catalog_write_service
Failed to fix directory: failed to walk dif: failed to fix: package has an errors
mehdihadeli commented 1 year ago

My problem fixed by changing command to:

goimports-reviser  ./... -rm-unused -set-alias -format -recursive
incu6us commented 1 year ago

@mehdihadeli it is not a fix. filepath, dir, or just file must be set in the end of the line. in other case, non of your params won’t be applied

mehdihadeli commented 1 year ago

@incu6us Hi, I didn't know about that. Below command also works for me

goimports-reviser -local -format -recursive ./...

but when I add -rm-unused or -set-alias I get the bellow error:

goimports-reviser -local -format -recursive -rm-unused ./...

Error:

Failed to fix directory: failed to walk dif: failed to fix: package has an errors
incu6us commented 1 year ago

@mehdihadeli i'll fix it

mehdihadeli commented 1 year ago

Thanks

danteay commented 1 year ago

This happens to me with latest version using this command:

goimports-reviser -format -recursive ./...

response:

2023/08/22 08:41:12 Failed to fix directory: path is not a directory

version:

version: 3.4.1
build with: 
tag: v3.4.1
commit: 8ec65d10985bd9e317313a87071246fd985f10b3
source: https://github.com/incu6us/goimports-reviser
incu6us commented 1 year ago

closing the issue in case of fix made by @danteay

mehdihadeli commented 1 year ago

@incu6us Hi, I still get the error for:

goimports-reviser -rm-unused -set-alias -format -recursive ./...
-: no Go files in
2023/09/15 13:12:39 Failed to fix directory ./...: failed to walk dif: failed to fix: package has an errors
incu6us commented 1 year ago

@mehdihadeli one of your package has an error. check your code

mehdihadeli commented 1 year ago

But it works fine without error with:

goimports-reviser -format -recursive ./...

When I add -rm-unused or -set-alias I will get this error:

-: no Go files in
2023/09/15 13:19:34 Failed to fix directory ./...: failed to walk dif: failed to fix: package has an errors
incu6us commented 1 year ago

Need to debug your code. Try to find a file with import which should be removed. Delete the import manually and then check what is wrong. There could be multiple files

mehdihadeli commented 1 year ago

For example, I did format in this microservice in my project. I don't know why, could be related to remove some imports with _ or . through goimports-reviser?

incu6us commented 1 year ago

it is known issue https://github.com/incu6us/goimports-reviser/issues/104. working on it

mehdihadeli commented 1 year ago

Yes, Maybe problem is here, because other things works

incu6us commented 1 year ago

added the feature to v3.5.5

mehdihadeli commented 1 year ago

@incu6us Thanks