Skip to content

Commit e3161b7

Browse files
committed
add make check-format and make format using purs-tidy
1 parent 1140bad commit e3161b7

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

Diff for: .tidyrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"importSort": "ide",
3+
"importWrap": "source",
4+
"indent": 2,
5+
"operatorsFile": null,
6+
"ribbon": 1,
7+
"typeArrowPlacement": "last",
8+
"unicode": "never",
9+
"width": null
10+
}

Diff for: Makefile

+40
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ FIND_SRC_FILES_ARGS := -name '*.purs' -type f
1717
NODE_MODULES := $(ROOT_DIR)/node_modules/.stamp
1818
PACKAGE_JSON := $(ROOT_DIR)/package.json
1919
PSA_ARGS ?= --censor-lib --stash=$(BUILD_DIR)/.psa_stash --is-lib=.spago --strict --censor-codes=UserDefinedWarning
20+
PURS_TIDY ?= purs-tidy
2021
SRC_FILES := $(shell find $(SRC_DIR) $(FIND_SRC_FILES_ARGS))
2122
TEST_FILES := $(shell find $(TEST_DIR) $(FIND_SRC_FILES_ARGS))
2223
UI_GUIDE_FILES := $(shell find $(UI_GUIDE_DIR) $(FIND_SRC_FILES_ARGS))
2324
YARN_LOCK := $(ROOT_DIR)/yarn.lock
2425

26+
FORMAT_SRC_PURS_TIDY_STAMP := $(BUILD_DIR)/.format-src-purs-tidy-stamp
27+
FORMAT_TEST_PURS_TIDY_STAMP := $(BUILD_DIR)/.format-test-purs-tidy-stamp
28+
29+
FORMAT_DEPENDENCIES := \
30+
$(FORMAT_SRC_PURS_TIDY_STAMP) \
31+
$(FORMAT_TEST_PURS_TIDY_STAMP)
32+
2533
# Colors for printing
2634
CYAN := \033[0;36m
2735
RESET := \033[0;0m
@@ -72,6 +80,14 @@ $(DIST_DIR)/bundled.js: $(OUTPUT_DIR)/Main/index.js
7280
$(DIST_DIR)/index.js: $(OUTPUT_DIR)/Main/index.js
7381
$(NPX) browserify dist/main.js --outfile $@
7482

83+
$(FORMAT_SRC_PURS_TIDY_STAMP): $(SRC_FILES) $(NODE_MODULES_STAMP) | $(BUILD)
84+
$(PURS_TIDY) $(PURS_TIDY_CMD) $(SRC_DIR)
85+
@touch $@
86+
87+
$(FORMAT_TEST_PURS_TIDY_STAMP): $(TEST_FILES) $(NODE_MODULES_STAMP) | $(BUILD)
88+
$(PURS_TIDY) $(PURS_TIDY_CMD) $(TEST_DIR)
89+
@touch $@
90+
7591
$(NODE_MODULES): $(PACKAGE_JSON) $(YARN_LOCK)
7692
$(NPX) yarn install
7793
touch $@
@@ -88,6 +104,18 @@ build: $(BUILD_DEPS) ## Build everything — all the CSS, and the UI Guide — i
88104
.PHONY: build-ui
89105
build-ui: $(DIST_DIR)/index.js ## Build the UI Guide, installing any missing dependencies along the way
90106

107+
.PHONY: check-format
108+
check-format: PURS_TIDY_CMD=check
109+
check-format: $(FORMAT_DEPENDENCIES) ## Validate formatting of all code
110+
111+
.PHONY: check-format-src
112+
check-format-src: PURS_TIDY_CMD=check
113+
check-format-src: $(FORMAT_SRC_PURS_TIDY_STAMP) ## Validate formatting of the `src` directory
114+
115+
.PHONY: check-format-test
116+
check-format-test: PURS_TIDY_CMD=check
117+
check-format-test: $(FORMAT_TEST_PURS_TIDY_STAMP) ## Validate formatting of the `test` directory
118+
91119
.PHONY: clean
92120
clean: $(CLEAN_DEPS) ## Remove all dependencies and build artifacts, starting with a clean slate
93121
rm -fr \
@@ -98,6 +126,18 @@ clean: $(CLEAN_DEPS) ## Remove all dependencies and build artifacts, starting wi
98126
$(ROOT_DIR)/.spago \
99127
$(ROOT_DIR)/node_modules
100128

129+
.PHONY: format
130+
format: PURS_TIDY_CMD=format-in-place
131+
format: $(FORMAT_DEPENDENCIES) ## Format all code
132+
133+
.PHONY: format-src
134+
format-src: PURS_TIDY_CMD=format-in-place
135+
format-src: $(FORMAT_SRC_PURS_TIDY_STAMP) ## Format the `src` directory
136+
137+
.PHONY: format-test
138+
format-test: PURS_TIDY_CMD=format-in-place
139+
format-test: $(FORMAT_TEST_PURS_TIDY_STAMP) ## Format the `test` directory
140+
101141
.PHONY: help
102142
help: $(BUILD_DIR)/help ## Display this help message
103143
@awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-30s$(RESET) %s\n", $$1, $$2}' $<

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"parcel": "2.2.1",
1515
"purescript": "0.14.9",
1616
"purescript-psa": "0.8.2",
17+
"purs-tidy": "0.9.2",
1718
"spago": "0.20.3",
1819
"yarn-audit-fix": "^9.0.9"
1920
},

0 commit comments

Comments
 (0)