Can you pass multiple paths to `credo suggest` via the command line?

Can you pass multiple paths to credo suggest via the command line? I am attempting to add a precommit hook to lint my changed files with

git --no-pager diff --name-only --cached | grep -E "\.(ex|exs)$" | xargs mix credo

but it appears to only lint the first file in the list (which happens to be .credo.exs)

Thanks!

Nope, you can’t.

But you can use -n of xargs to run mix credo sequentially for each file.

Still, you really shouldn’t do that. To get the most benefit from credo, you should always let it scan the full project, or it won’t find some of the consistency stuff.

Interesting, my intent with only running it on the staged files is because I know the rest of my code might still be WIP, and might fail the linter check.

I also plan on running credo on my CI, which would run it on every file. With your statement in mind, am I correct in guessing that credo may fail on CI (running on every file) even if it passed in my pre-commit hook (running on a subset of files)?

Yes.

Consider you had a fully passing credo and all was green.

Then you change a single file which wraps spaces around operators, while all others don’t. You do not touch the other files at all.

Checking only the staged changes will allow you to commit, while your CI will complain, as that one file violates a consitency check now.

3 Likes

That makes sense, thanks for sharing that knowledge!

Note to future readers: credo 1.7 now supports this out of the box.

(sorry for bumping this thread, but it’s still among the top google results for people who didn’t update credo yet)

Do my concerns about consistency checks still apply, or is there some mechanism in place that will save us from passing pre-commit and failing CI?

For what it’s worth, my POV is that pre-commit hooks must be fast and may not need to be 100% correct, as long as the CI catches any leftover error later on. If they catch 90% of the basic errors, I’m happy.

I’m pretty sure this was added by popular request later on and that the consistency issue still stands, an official confirmation would be welcomed!