goimports-reviser
goimports-reviser copied to clipboard
Option to recursively format files in a directory
I would like to use this tool to format the imports for every file in my project. To do this, I have to write a script something similar to
for file in $(find . -name '*.go'); do
goimports-reviser -file-path $file -project-name $PROJECT_NAME
done
goimports
supports this, for example simply running goimports -w .
will recursively format imports for every go file in .
I would suggest a similar approach, allow the file-path
argument to take a directory and format all files when given as an input, but will defer to code owners for what's best.
Thanks!
This helps a lot if you are switching from go run golang.org/x/tools/cmd/[email protected] ...
to go run github.com/incu6us/goimports-reviser/[email protected]
as iteratively executing go run
is expensive in a loop, and it is clutter to have to special-case this vs other tools that can work on all files.
also not sure if this requires a separate issue, but the main concern is working with multiple files. Ex I evaluate them in make, so don't need goimports-reviser
to recurse. However, it should be possible to give a list of paths instead of a single one.
Need format all of the project
I am using Makefile to manage project, a demo like below:
.PHONY: format
format:
@$(foreach file,$(shell find . -type f -name '*.go'),goimports-reviser -file-path $(file) -project-name $(PROJECT_NAME);)
You can use version v3.1.0 to apply sorting to each go file in your project, like:
goimports-reviser -rm-unused -set-alias -format ./...