Skip to content

Commit

Permalink
[WPB-8712] use treefmt for everything (#4000)
Browse files Browse the repository at this point in the history
* [chore] use treefmt for everything

Co-authored-by: Matthias Fischmann <[email protected]>

---------

Co-authored-by: Matthias Fischmann <[email protected]>
  • Loading branch information
MangoIV and fisx authored Apr 22, 2024
1 parent b55e6e6 commit 2d5073e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
43 changes: 11 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ devtest:
.PHONY: sanitize-pr
sanitize-pr:
./hack/bin/generate-local-nix-packages.sh
make formatf
make hlint-inplace-pr
make hlint-check-pr # sometimes inplace has been observed not to do its job very well.
make format
make git-add-cassandra-schema
@git diff-files --quiet -- || ( echo "There are unstaged changes, please take a look, consider committing them, and try again."; exit 1 )
@git diff-index --quiet --cached HEAD -- || ( echo "There are staged changes, please take a look, consider committing them, and try again."; exit 1 )
Expand All @@ -155,28 +154,16 @@ ghcid:

# Used by CI
.PHONY: lint-all
lint-all: formatc hlint-check-all check-local-nix-derivations treefmt-check

.PHONY: hlint-check-all
hlint-check-all:
./tools/hlint.sh -f all -m check
lint-all: treefmt-check check-local-nix-derivations

.PHONY: hlint-inplace-all
hlint-inplace-all:
./tools/hlint.sh -f all -m inplace

.PHONY: hlint-check-pr
hlint-check-pr:
./tools/hlint.sh -f pr -m check

.PHONY: hlint-inplace-pr
hlint-inplace-pr:
./tools/hlint.sh -f pr -m inplace

.PHONY: hlint-check
hlint-check:
./tools/hlint.sh -f changeset -m check

.PHONY: hlint-inplace
hlint-inplace:
./tools/hlint.sh -f changeset -m inplace
Expand All @@ -192,35 +179,27 @@ check-local-nix-derivations: regen-local-nix-derivations
services: init install
$(MAKE) -C services/nginz

# formats all Haskell files (which don't contain CPP)
# formats everything according to treefmt rules
# this may take a while (5 minutes) on first run but should be instant on
# any subsequent run except after you have changed files.
.PHONY: format
format:
./tools/ormolu.sh

# formats all Haskell files changed in this PR, even if local changes are not committed to git
.PHONY: formatf
formatf:
./tools/ormolu.sh -f pr

# formats all Haskell files even if local changes are not committed to git
.PHONY: formatf-all
formatf-all:
./tools/ormolu.sh -f all
treefmt

# checks that all Haskell files are formatted; fail if a `make format` run is needed.
# checks the format
.PHONY: formatc
formatc:
./tools/ormolu.sh -c
formatc:
treefmt-check

# For any Haskell or Rust file, update or add a license header if necessary.
# Headers should be added according to Ormolu's formatting rules, but please check just in case.
.PHONY: add-license
add-license:
# Check headroom is installed. If not, please run 'stack install headroom'
# Check headroom is installed.
command -v headroom
headroom run
@echo ""
@echo "you might want to run 'make formatf' now to make sure ormolu is happy"
@echo "you might want to run 'make format' now to make sure ormolu is happy"

.PHONY: treefmt
treefmt:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5-internal/WPB-8712
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
move formatting and linting of haskell files to treefmt, remove some of the now unneeded rules
20 changes: 15 additions & 5 deletions treefmt.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]
excludes = [
"nix/sources.nix" # managed by niv.
]
excludes = [ "nix/sources.nix"] # managed by niv.

[formatter.cabal-fmt]
command = "cabal-fmt"
options = [ "--inplace" ]
includes = [ "*.cabal" ]
excludes = [
"dist-newstyle/"
excludes = [ "dist-newstyle/" ]

[formatter.ormolu]
command = "ormolu"
includes = ["*.hs"]
excludes = [ "dist*" ]
options = [
"--mode", "inplace",
"--check-idempotence",
]

[formatter.hlint]
command = "hlint"
includes = ["*.hs"]
excludes = [ "dist*" ]

[formatter.shellcheck]
command = "shellcheck"
includes = ["*.sh"]
Expand Down

0 comments on commit 2d5073e

Please sign in to comment.