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

fix(alejandra): one --exclude flag per file #433

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

mrcjkb
Copy link
Contributor

@mrcjkb mrcjkb commented Apr 16, 2024

alejandra --exclude file1 file2 file3 doesn't work.

It should be alejandra --exclude file1 --exclude file2 --exclude file3

@sandydoo sandydoo added the bug Something isn't working label Apr 16, 2024
@domenkozar domenkozar merged commit 8e1b839 into cachix:master Apr 24, 2024
4 checks passed
@mrcjkb mrcjkb deleted the alejandra branch April 24, 2024 11:41
@@ -1659,7 +1659,7 @@ in
cmdArgs =
mkCmdArgs (with hooks.alejandra.settings; [
[ check "--check" ]
[ (exclude != [ ]) "--exclude ${lib.escapeShellArgs (lib.unique exclude)}" ]
[ (exclude != [ ]) "${lib.escapeShellArgs (map (file: "--exclude '${file}'") (lib.unique exclude))}" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclude has a specific meaning in pre-commit, which is probably not this.

Wouldn't it be better to let pre-commit pass the list of changed files anyway?

Copy link
Contributor Author

@mrcjkb mrcjkb Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand.
Afaik, pre-commit already passes in a list of changed files.
My use case for --exclude with alejandra is to prevent it from formatting nix files that were generated (e.g. with a cabal2nix hook).

In any case, passing multiple files to --exclude doesn't work with alejandra.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not well documented upstream, but the pre-commit exclude field is a regex. I now see my mistake: I confused hooks.alejandra.excludes for hooks.alejandra.settings.exclude.

So we have

  1. pre-commit: exclude, singular, regex
  2. git-hooks.nix: excludes, plural, regex
  3. alejandra settings: exclude, unrelated

where 1 and 2 are the same concepts, but 3 is something else.
I suppose 3 could be removed without loss of functionality, but I don't know whether keeping or removing is more harmful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose for the use case of generating nix files with cabal2nix, it would make sense to use

git-hooks.nix: excludes, plural, regex

I'll give it a go in a few days and report back here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested the git-hooks excludes, and it works fine for my use case.
So I would agree that alejandra.settings.excludes is redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants