Skip to content

Commit 7138c40

Browse files
Enforce TypeScript formatting with Biome (#1456)
This builds on the existing Biome setup for the TypeScript code. I found that 'just ts::fmt' was calling 'npm run format', but that script did not exist yet. Also, formatting was only handled through pre-commit, so it was still possible for unformatted TypeScript code to get merged if pre-commit was not installed locally. This PR adds Biome as a TypeScript dev dependency, adds format scripts, and makes the TypeScript lint step check formatting too. Closes #842. **Testing I did** Ran locally: - 'npm ci' - 'npm run format:check' - 'npm run format' - 'npm run lint' - 'npm run test' - 'npm run build' I also temporarily added badly formatted TypeScript and confirmed 'npm run format:check' failed, then restored the file.
1 parent d9e0f71 commit 7138c40

4 files changed

Lines changed: 191 additions & 1 deletion

File tree

.github/workflows/autofix.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ on:
88
permissions: {}
99

1010
jobs:
11+
ts-fmt:
12+
name: Format TypeScript
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
if: |
17+
github.event.action == 'opened' ||
18+
github.event.action == 'synchronize' ||
19+
github.event.action == 'reopened'
20+
steps:
21+
- name: Checkout sources
22+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
23+
with: { persist-credentials: false }
24+
- uses: taiki-e/install-action@7a79fe8c3a13344501c80d99cae481c1c9085912 # v2.81.10
25+
with: { tool: 'just' }
26+
- uses: ./.github/actions/mlt-setup-node
27+
- name: Format TypeScript
28+
run: just ts::fmt
29+
30+
- uses: autofix-ci/action@c5b2d67aa2274e7b5a18224e8171550871fc7e4a # v1.3.4
31+
with: { commit-message: "chore: format TypeScript" }
32+
1133
rust-fmt-toml:
1234
name: Format Cargo.toml
1335
runs-on: ubuntu-latest

ts/mod.just

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ install:
3333
# Run linting
3434
lint: install
3535
npm run lint
36+
npm run format:check
3637

3738
# Run tests
3839
test: install

ts/package-lock.json

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"scripts": {
1717
"build": "tsc",
1818
"test": "vitest run --coverage --coverage.reportOnFailure",
19-
"lint": "eslint"
19+
"lint": "eslint",
20+
"format": "biome format --write ./src",
21+
"format:check": "biome format ./src"
2022
},
2123
"repository": {
2224
"type": "git",
@@ -26,6 +28,7 @@
2628
"url": "https://github.com/maplibre/maplibre-tile-spec/issues"
2729
},
2830
"devDependencies": {
31+
"@biomejs/biome": "^2.4.16",
2932
"@eslint/js": "^10.0.1",
3033
"@mapbox/vector-tile": "^2.0.4",
3134
"@maplibre/maplibre-gl-style-spec": "^24.7.0",

0 commit comments

Comments
 (0)