Skip to content

[INTT-54] Add code formatters for general projects#27

Open
tlater-famedly wants to merge 2 commits into
mainfrom
tlater/treefmt
Open

[INTT-54] Add code formatters for general projects#27
tlater-famedly wants to merge 2 commits into
mainfrom
tlater/treefmt

Conversation

@tlater-famedly

@tlater-famedly tlater-famedly commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

This adds formatting with treefmt, including a pre-commit hook for it. This seems to be reasonably performant, so I think it's fine to keep it in the pre-commit hooks.

Documentation is added via devshell commands, which should hopefully be convenient enough for downstream users.

@tlater-famedly tlater-famedly force-pushed the tlater/treefmt branch 3 times, most recently from b01aa11 to 8779985 Compare June 12, 2026 11:57
@tlater-famedly tlater-famedly force-pushed the tlater/generic-pre-commit branch from 7d3ce0d to 541b197 Compare June 12, 2026 12:07
@tlater-famedly tlater-famedly force-pushed the tlater/generic-pre-commit branch from 541b197 to 5d5a75e Compare June 12, 2026 12:16
@tlater-famedly tlater-famedly force-pushed the tlater/treefmt branch 2 times, most recently from e2c0d4d to 9d3cce6 Compare June 12, 2026 12:18
@tlater-famedly tlater-famedly force-pushed the tlater/generic-pre-commit branch from d0c9fd7 to 98dc997 Compare June 12, 2026 12:20
@tlater-famedly tlater-famedly force-pushed the tlater/generic-pre-commit branch from 98dc997 to 5e4322c Compare June 12, 2026 12:22
@tlater-famedly tlater-famedly force-pushed the tlater/generic-pre-commit branch from 5e4322c to a73e464 Compare June 12, 2026 13:04
@tlater-famedly tlater-famedly force-pushed the tlater/generic-pre-commit branch 2 times, most recently from 2b0046a to 03ae9e0 Compare June 12, 2026 13:14
@RasmusRendal RasmusRendal force-pushed the tlater/generic-pre-commit branch 3 times, most recently from cf2069f to 290c8d4 Compare June 15, 2026 21:45
@RasmusRendal RasmusRendal changed the base branch from tlater/generic-pre-commit to main June 15, 2026 21:55
programs = {
prettier.enable = true;
sqlfluff.enable = true;
shfmt.enable = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have programs.shfmt.indent_size = 0; to use tabs for indentation :))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the default setting:

  -i,  --indent uint       0 for tabs (default), >0 for number of spaces


programs = {
prettier.enable = true;
sqlfluff.enable = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We explicitly went without sqlfluff, because it couldn't handle our complicated postgres

};

programs = {
prettier.enable = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might want to borrow our prettierrc:

{
  "overrides": [
    {
      "files": [
        "*.yml",
        "*.yaml"
      ],
      "options": {
        "singleQuote": false,
        "printWidth": 120,
        "tabWidth": 2,
        "proseWrap": "preserve"
      }
    }
  ]
}

@RasmusRendal RasmusRendal Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

arguing about formatting timeeeeee.

Maybe one formatter per PR would be the way to go :(

@RasmusRendal RasmusRendal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is pretty great

@emgrav emgrav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! I have two questions that are probably not really relevant to this PR, but if the blockers are not big it would be cool if we were able to close these tickets with this PR if we can clear the blockers.

Comment on lines +36 to +39
# TODO: We want to use this, but it conflicts with rustfmt in places
# In the future, we can simply make rustfmt run as a pre-commit hook
# after trailing-whitespace, and it won't be a problem.
# { id = "trailing-whitespace"; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What exactly is needed to make rustfmt run as a pre-commit hook after trailing-whitespace? Adding this back in is tracked in https://famedly.atlassian.net/browse/INTT-55
If we already know what the blocker preventing us from re-enabling it is, it would be great if this information could be added to the ticket :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The only thing blocking trailing-whitespace running after the formatter on main is that on main, there's no formatter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the reason it wasn't as of this PR is because we picked it up in nehws CI. It's a rustfmt bug to begin with, nehws just couldn't start using the pre-commit hooks if we left this one in.

We should probably just fix it as part of this PR.

Comment on lines +61 to +64
# TODO: We would like to use this, but we need to tweak it
# a little for helm charts.
#
# { id = "check-yaml"; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same thing here, we are tracking the missing check-yaml in INTT-56. In what way does it need to be tweaked for helm charts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It probably needs to be disabled entirely. Last time I checked, check-yaml breaks down completely in the face of go templating.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we then maybe standardize around keeping helm charts always in a top-level directory called charts? Then we could reenable check-yaml and simply except crates/** from the check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I like that better than permanently omitting this check. It's nice to be certain that any YAML files that make it into our repos evaluate correctly.

If Helm charts are simply not valid YAML we should find a way to exclude them.

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.

3 participants