Add Makefile targets to run hlint on all and changed files.

* `make lint-hs` will lint all files.
* `make lint-hs-changed` will lint all modified files on this branch.
* `make lint` will delegate to `make lint-hs`.
* `make lint-changed` will delegate to `make lint-hs-changed`.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4720
GitOrigin-RevId: d872f5b672b1d06100cd9fdaa5e60dc8bb5cae86
This commit is contained in:
Samir Talwar 2022-06-14 17:20:12 +02:00 committed by hasura-bot
parent 8e69fde547
commit ed1dc00bb8

View File

@ -1,8 +1,10 @@
# skip contrib with its generated .hs file because it doesn't
# come with a cabal file, which can trigger a bug in ormolu
FORMAT_HS_FILES = $(shell git ls-files '*.hs' '*.hs-boot' | grep -v '^contrib/')
FORMAT_CHANGED_HS_FILES = $(shell git diff --diff-filter=d --name-only `git merge-base HEAD origin/main` \
| grep '.*\(hs\|hs-boot\)$$' | grep -v '^contrib/')
HS_FILES = $(shell git ls-files '*.hs' '*.hs-boot' | grep -v '^contrib/')
CHANGED_HS_FILES = $(shell git diff --diff-filter=d --name-only `git merge-base HEAD origin/main` \
| grep '.*\(hs\|hs-boot\)$$' | grep -v '^contrib/')
HLINT = hlint
ORMOLU_CHECK_VERSION = 0.3.0.0
ORMOLU_ARGS = --cabal-default-extensions
@ -26,21 +28,21 @@ check-ormolu-version:
## format-hs: auto-format Haskell source code using ormolu
format-hs: check-ormolu-version
@echo running ormolu --mode inplace
@$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(FORMAT_HS_FILES)
@$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(HS_FILES)
.PHONY: format-hs-changed
## format-hs-changed: auto-format Haskell source code using ormolu (changed files only)
format-hs-changed: check-ormolu-version
@echo running ormolu --mode inplace
@if [ -n "$(FORMAT_CHANGED_HS_FILES)" ]; then \
$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(FORMAT_CHANGED_HS_FILES); \
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
$(ORMOLU) $(ORMOLU_ARGS) --mode inplace $(CHANGED_HS_FILES); \
fi
.PHONY: check-format-hs
## check-format-hs: check Haskell source code formatting using ormolu
check-format-hs: check-ormolu-version
@echo running ormolu --mode check
@$(ORMOLU) $(ORMOLU_ARGS) --mode check $(FORMAT_HS_FILES)
@$(ORMOLU) $(ORMOLU_ARGS) --mode check $(HS_FILES)
.PHONY: format
format: format-hs
@ -50,3 +52,23 @@ format-changed: format-hs-changed
.PHONY: check-format
check-format: check-format-hs
.PHONY: lint-hs
## lint-hs: lint Haskell code using `hlint`
lint-hs:
@echo running hlint
@$(HLINT) $(HS_FILES)
.PHONY: lint-hs-changed
## lint-hs-changed: lint Haskell code using `hlint` (changed files only)
lint-hs-changed:
@echo running hlint
@if [ -n "$(CHANGED_HS_FILES)" ]; then \
$(HLINT) $(CHANGED_HS_FILES); \
fi
.PHONY: lint
lint: lint-hs
.PHONY: lint-changed
lint-changed: lint-hs-changed