Proposal: Replace Prettier with Oxfmt and setup a pre-commit hook to run formatting
Background
We currently use Prettier for JS and TS code formatting. We also use @prettier/plugin-oxc to speed up prettier by using the oxidation compiler under the hood. Prettier runs on E/App typically take ~30s.
Problem
When we open a pull request without running all CI checks locally, if Prettier fails, then we waste time and money on CI checks that fail and delay pull requests unnecessarily.
Solution
- Switch from Prettier to Oxfmt. Oxfmt is a 100% compatible* drop-in replacement for Prettier. A clean run of Oxfmt in E/App takes ~0.7s (~38x faster than prettier).
- Using lefthook, set up a pre-commit hook that runs Oxfmt and includes the formatting in the diff.
This solves the problem because it'll be no longer possible to commit unformatted JS/TS code in E/App. The switch to Oxfmt is included because it makes formatting fast enough that it's only a barely-noticable delay in commits.
Notes for completeness:
- lefthook can be bypassed if necessary with
LEFTHOOK=0 or the --no-verify flag for git commit
- Oxfmt is 100% compatible with Prettier, and has its own import sorting built-in. But it's import sorting isn't 100% the same as
@trivago/prettier-plugin-sort-imports. So the PR to enable it has a large diff, but that diff is only reordering imports.
Proposal: Replace Prettier with Oxfmt and setup a pre-commit hook to run formatting
Background
We currently use Prettier for JS and TS code formatting. We also use @prettier/plugin-oxc to speed up prettier by using the oxidation compiler under the hood. Prettier runs on E/App typically take ~30s.
Problem
When we open a pull request without running all CI checks locally, if Prettier fails, then we waste time and money on CI checks that fail and delay pull requests unnecessarily.
Solution
This solves the problem because it'll be no longer possible to commit unformatted JS/TS code in E/App. The switch to Oxfmt is included because it makes formatting fast enough that it's only a barely-noticable delay in commits.
Notes for completeness:
LEFTHOOK=0or the--no-verifyflag for git commit@trivago/prettier-plugin-sort-imports. So the PR to enable it has a large diff, but that diff is only reordering imports.