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

standardize program options with mkFormatterModule #288

Merged
merged 2 commits into from
Jan 2, 2025
Merged

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Dec 31, 2024

A common complaint / observation is that treefmt-nix config tend to be a mix between enabled programs, and treefmt settings to override includes/excludes/priority. Some programs have those options available directly, but not all of them.

In order to fix that, this commit introduces mkFormatterModule, a function that generates a regular module structure based on a few parameters. And that support the includes / excludes / priority out of the box.

A few of the programs are already converted to that format. Ideally all of them are getting converted soon.

@zimbatm zimbatm requested a review from brianmcgee December 31, 2024 15:12
A common complaint / observation is that treefmt-nix config tend to be a
mix between enabled programs, and treefmt settings to override
includes/excludes/priority. Some programs have those options available
directly, but not all of them.

In order to fix that, this commit introduces `mkFormatterModule`, a
function that generates a regular module structure based on a few
parameters. And that support the includes / excludes / priority out of
the box.
@zimbatm zimbatm force-pushed the mkFormatterModule branch 3 times, most recently from 183cfdd to 0ab12ff Compare January 2, 2025 16:21
@zimbatm
Copy link
Member Author

zimbatm commented Jan 2, 2025

Ok this is ready. I was able to convert all the formatters except mypy that does some funky stuff.

Looking for feedback from all the maintainers since this changes all the modules. /cc @anntnzrb @sebaszv @haruki7049 @gabyx @SigmaSquadron @adam-gaia @RossSmyth @JakobLichterfeld

@zimbatm zimbatm force-pushed the mkFormatterModule branch from 0ab12ff to 8030839 Compare January 2, 2025 16:26
Copy link
Member

@phaer phaer left a comment

Choose a reason for hiding this comment

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

Very nice! Seems to work, much less boilerplate code but same features and a cleaner interface.

Just curious if you did use any tooling for the module changes or did that all "by hand"?

@sebaszv
Copy link
Contributor

sebaszv commented Jan 2, 2025

This was something I did pick up on as being an annoyance. Glad this is standardised now. LGTM 👍

@phaer phaer merged commit 3b0afa7 into main Jan 2, 2025
3 checks passed
@phaer phaer deleted the mkFormatterModule branch January 2, 2025 17:34
@SigmaSquadron
Copy link
Contributor

Sorry for missing this. Looks superb; it makes a lot of sense to abstract all of the simpler module definitions. Thanks!

@anntnzrb
Copy link
Contributor

anntnzrb commented Jan 2, 2025

✔️ Great refactor, contributions should be even easier now.

@mcsimw
Copy link

mcsimw commented Jan 2, 2025

These two commits broke the flake-parts module.

@phaer
Copy link
Member

phaer commented Jan 2, 2025

Bug reports are more useful if they contain info on what breaks and how that breakage might be reproducible. :)

It seems to be broken indeed, runs into infinite recursion while evaluating the module arg

       … while evaluating the module argument `mkFormatterModule' in "/nix/store/qa
r0bxqnnbl6j6i3yh34h73xafah1bi5-source/programs/actionlint.nix":

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: infinite recursion encountered
       at /nix/store/j0jlb33bm31w347w43051hbffgh616jr-source/lib/modules.nix:506:28
:
          505|         builtins.addErrorContext (context name)
          506|           (args.${name} or config._module.args.${name})
             |                            ^
          507|       ) (lib.functionArgs f);

Can be reproduced by i.e. nix flake update treefmt-nix in https://github.com/nix-community/buildbot-nix or most probably any other repo using treefmt-nix and flake.parts

@roberth
Copy link
Contributor

roberth commented Jan 2, 2025

Missing specialArgs tend to cause infinite recursions.
The flake-parts module doesn't use this entrypoint.
You could add the specialArgs to this submoduleWith call

type = types.submoduleWith {

Alternatively, you could perhaps go through the main entrypoint and get the type returned by that evalModules call. It should be equivalent to the aforementioned submoduleWith call's return value.

Copy link
Contributor

@JakobLichterfeld JakobLichterfeld left a comment

Choose a reason for hiding this comment

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

Nice refactoring, checked the dart-format part. lgtm beside of the flake-parts issue, see #288 (comment)

@roberth roberth mentioned this pull request Jan 3, 2025
@gabyx
Copy link
Contributor

gabyx commented Jan 23, 2025

@zimbatm : Right this change does not change user facing treefmt.nix code?

@gabyx
Copy link
Contributor

gabyx commented Jan 23, 2025

@zimbatm : great improvement.

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 this pull request may close these issues.

10 participants