Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to accept list of files #8

Closed
sp71 opened this issue Jan 26, 2021 · 7 comments · May be fixed by #11
Closed

Add Option to accept list of files #8

sp71 opened this issue Jan 26, 2021 · 7 comments · May be fixed by #11

Comments

@sp71
Copy link

sp71 commented Jan 26, 2021

DESCRIPTION

  • Its often to not format all files
  • Example: vendor folder, protobuf generated files, etc

REQUEST

  • Add an option where the image accepts a list of files to process
  • Or provide options to ignore vendor and/or protobuf generated files since they are used often

WORKAROUND

  • Running docker run on each file is much slower with this workaround
#!/bin/bash

files=$(find . -type f -name "*.go" | grep -v vendor | grep -v pb.go)
for f in $files; do
    diff=$(docker run --rm -v $(pwd):/data cytopia/goimports -d $f)
    if [[ "$diff" != "" ]]; then
        echo "File fails goimports linter: $f"
        exit 2
    fi
done
@cytopia
Copy link
Owner

cytopia commented Jan 30, 2021

@sp71 Is that not provided by default by goimports? How do you ususally do that if you run the binary locally?

@sp71
Copy link
Author

sp71 commented Mar 9, 2021

It's not a default behavior but should be since proto, vendor, etc should be ignored. I created a custom Dockerfile and shell script so it would be much quicker on any CI. It will be great if you can incorporate this behavior into your own script. Otherwise, the current solution with your image is to spin up the docker image every time for every file.

Dockerfile

FROM golang:1.14

COPY . /go/src/github.com/repo
RUN cd /go/src/github.com/repo
RUN go get golang.org/x/tools/cmd/goimports
COPY ./scripts/lint_go.sh /lint_go.sh
WORKDIR /go/src/github.com/repo/

ENTRYPOINT ["/lint_go.sh"]

lint_go.sh


#!/bin/bash

files=$(find . -type f -name "*.go" | grep -v vendor | grep -v pb.go)
for f in $files; do
    diff=$(goimports -d $f)
    if [[ "$diff" != "" ]]; then
        echo "Linter detected error for file: $f"
        echo "Developer needs to ensure code follows linting rules"
        exit 2
    fi
done

@sp71
Copy link
Author

sp71 commented Sep 7, 2021

@cytopia

@Yscream
Copy link

Yscream commented Feb 13, 2023

any solutions?

@darkdragon-001
Copy link

I proposed #11. Can you try if this fixes the problem?

@sp71
Copy link
Author

sp71 commented Sep 6, 2023

Another tool that offers functionality

https://github.com/incu6us/goimports-reviser

@sp71
Copy link
Author

sp71 commented Sep 20, 2023

Been a few years with no progress so closing out issue

@sp71 sp71 closed this as completed Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants