Skip to content

Commit 4ca614c

Browse files
authored
build: adopt Oxfmt and enforce TypeScript formatting in CI (#1825)
## Summary Follow up on #1818 and the toolchain review in #1732 by introducing a shared formatter and checking formatting in CI. After the ESLint migration, contributors had no formatting command or CI check; this PR provides both and formats the existing TypeScript sources consistently. To keep the diff reviewable, formatting is limited to TypeScript files (`.ts`, `.tsx`, `.mts`, `.cts`) for now. Other file types can be enabled in follow-up PRs. - Pin Oxfmt to 0.73.0 and add `pnpm run format` / `pnpm run format:check`. - Share `.oxfmtrc.jsonc` between the CLI and the already recommended Oxc editor extension. Restrict the scope to TypeScript via `ignorePatterns`, use four-space indentation and single quotes, and disable import and package metadata sorting. Generated output (`out/`, `dist/`) is skipped through the existing Git ignore rules. - Format 173 TypeScript files (169 under `src/`, 4 under `html/`) in a dedicated mechanical commit. Move one `no-control-regex` suppression comment next to the regular expression after line wrapping moved it to another line. - Add an independent `format` CI job with Node.js 24, frozen-lockfile installation, and `pnpm run format:check`. Enable format on save for TypeScript and document the contributor commands.
1 parent f41b947 commit 4ca614c

179 files changed

Lines changed: 25823 additions & 9357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/main.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ jobs:
128128
with:
129129
name: ${{ env.VSIX_FILE }}
130130
path: ${{ env.VSIX_FILE }}
131+
format:
132+
runs-on: ubuntu-latest
133+
steps:
134+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
135+
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
136+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
137+
with:
138+
node-version: 24
139+
cache: 'pnpm'
140+
- run: pnpm install --frozen-lockfile
141+
- name: Check TypeScript formatting
142+
run: pnpm run format:check
131143
lint:
132144
runs-on: ubuntu-latest
133145
env:

‎.oxfmtrc.jsonc‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"printWidth": 100,
4+
"tabWidth": 4,
5+
"singleQuote": true,
6+
"endOfLine": "lf",
7+
// Keep imports and package metadata in their existing order.
8+
"sortImports": false,
9+
"sortPackageJson": false,
10+
// Format TypeScript files only for now: ignore everything, then re-include
11+
// directories and TypeScript sources. The CLI and the Oxc VS Code extension
12+
// both read this file.
13+
"ignorePatterns": ["*", "!*/", "!*.ts", "!*.tsx", "!*.mts", "!*.cts"],
14+
}

‎.vscode/settings.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"out": true // set this to false to include "out" folder in search results
88
},
99
"r.lsp.diagnostics": true,
10+
"[typescript][typescriptreact]": {
11+
"editor.defaultFormatter": "oxc.oxc-vscode",
12+
"editor.formatOnSave": true
13+
},
1014
"editor.codeActionsOnSave": {
1115
"source.fixAll.markdownlint": "explicit"
1216
}

‎CONTRIBUTING.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ If launching reports `Configured debug type 'extensionHost' is not supported`, e
2525

2626
On VS Code 1.139, the regression can leave the development host paused before any extension activates; the launching window's extension host log shows `ECONNREFUSED ::1` and `Could not find any debuggable target`. Upgrade to VS Code 1.140.0 or newer, or use Microsoft's [JavaScript Debugger Nightly](https://marketplace.visualstudio.com/items?itemName=ms-vscode.js-debug-nightly) as a temporary workaround: disable the built-in **JavaScript Debugger**, enable Nightly, and reload VS Code.
2727

28+
## Formatting and linting
29+
30+
Run `pnpm run format` to format TypeScript files with Oxfmt, and
31+
`pnpm run format:check` to check formatting without changing files. CI runs the
32+
same check for pull requests and pushes to `main`. Formatting currently applies
33+
to TypeScript files only (`.ts`, `.tsx`, `.mts`, and `.cts`); other file types,
34+
including JavaScript, JSON, Markdown, YAML, R, C, and EJS files, are not formatted.
35+
36+
The checked-in `.oxfmtrc.jsonc` is shared by the CLI and the recommended Oxc
37+
VS Code extension, and its `ignorePatterns` restrict both to TypeScript files.
38+
TypeScript files use four-space indentation and single quotes. Import and
39+
`package.json` sorting are disabled. The CLI also respects the repository's
40+
`.gitignore` files, so generated bundles, compiled tests, and dependencies are
41+
excluded from `pnpm run format` and `pnpm run format:check`. The editor
42+
integration does not apply `.gitignore`, so it can still format generated files
43+
under `out/` or `dist/` if you open and save them.
44+
45+
Workspace settings select Oxc as the formatter and enable format on save for
46+
TypeScript. Run `pnpm run lint` and `pnpm run typecheck` separately to check
47+
TypeScript code.
48+
2849
## Building bundled sess
2950

3051
Builds require Git and a checkout with HEAD. `scripts/prepare-sess.js` fingerprints

‎html/help/script.ts‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,27 @@ window.onmousedown = (ev) => {
88
vscode.postMessage({
99
message: 'mouseClick',
1010
button: Number(ev.button),
11-
scrollY: window.scrollY
11+
scrollY: window.scrollY,
1212
});
1313
};
1414

15-
1615
// handle requests from vscode ui
1716
window.addEventListener('message', (ev: MessageEvent) => {
1817
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1918
const message = ev.data;
2019
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
21-
if(message.command === 'getScrollY'){
20+
if (message.command === 'getScrollY') {
2221
vscode.postMessage({
2322
message: 'getScrollY',
24-
scrollY: window.scrollY
23+
scrollY: window.scrollY,
2524
});
2625
}
2726
});
2827

29-
3028
// do everything after loading the body
3129
window.document.body.onload = () => {
32-
3330
// make relative path for hyperlinks
34-
const relPath = (document.body.getAttribute('relPath') || '');
31+
const relPath = document.body.getAttribute('relPath') || '';
3532

3633
// notify vscode, used to restore help panels between sessions
3734
vscode.setState(relPath);
@@ -42,42 +39,41 @@ window.document.body.onload = () => {
4239

4340
// scroll to desired position:
4441
const scrollYTo = Number(document.body.getAttribute('scrollYTo') ?? -1);
45-
if(scrollYTo >= 0){
46-
window.scrollTo(0,scrollYTo);
47-
} else if(url1.hash){
42+
if (scrollYTo >= 0) {
43+
window.scrollTo(0, scrollYTo);
44+
} else if (url1.hash) {
4845
document.location.hash = url1.hash;
4946
}
5047

5148
// notify vscode when links are clicked:
5249
const hyperLinks = document.getElementsByTagName('a');
5350

54-
for(let i=0; i<hyperLinks.length; i++){
51+
for (let i = 0; i < hyperLinks.length; i++) {
5552
const hrefAbs = hyperLinks[i].href;
5653
const hrefRel = hyperLinks[i].getAttribute('href') || '';
5754

58-
if(hrefRel.startsWith('#')){
55+
if (hrefRel.startsWith('#')) {
5956
hyperLinks[i].onclick = () => {
6057
document.location.hash = hrefRel;
6158
};
62-
} else if(hrefAbs && hrefAbs.startsWith('vscode-webview://')){
59+
} else if (hrefAbs && hrefAbs.startsWith('vscode-webview://')) {
6360
hyperLinks[i].onclick = () => {
64-
6561
const url2 = new URL(hrefRel, url1);
6662
const finalHref = url2.toString();
6763

6864
vscode.postMessage({
6965
message: 'linkClicked',
7066
href: finalHref,
71-
scrollY: window.scrollY
67+
scrollY: window.scrollY,
7268
});
7369
};
7470
}
7571
}
7672

7773
// notify vscode when code is clicked:
78-
if(document.body.classList.contains('preClickable')){
74+
if (document.body.classList.contains('preClickable')) {
7975
const codeElements = document.getElementsByTagName('pre');
80-
for(let i=0; i<codeElements.length; i++){
76+
for (let i = 0; i < codeElements.length; i++) {
8177
const el = codeElements[i];
8278
el.onclick = (me: MouseEvent) => {
8379
vscode.postMessage({
@@ -88,10 +84,9 @@ window.document.body.onload = () => {
8884
ctrlKey: me.ctrlKey,
8985
shiftKey: me.shiftKey,
9086
metaKey: me.metaKey,
91-
}
87+
},
9288
});
9389
};
9490
}
9591
}
9692
};
97-

‎html/help/webviewMessages.d.ts‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,41 @@ interface VsCode {
55
setState: (state: string) => void;
66
}
77

8-
98
interface IOutMessage {
109
message: string;
1110
}
1211
interface LogMessage extends IOutMessage {
13-
message: 'log',
14-
body: any
12+
message: 'log';
13+
body: any;
1514
}
1615
interface MouseClickMessage extends IOutMessage {
17-
message: 'mouseClick',
18-
button: number,
19-
scrollY: number
16+
message: 'mouseClick';
17+
button: number;
18+
scrollY: number;
2019
}
2120
interface LinkClickedMessage extends IOutMessage {
22-
message: 'linkClicked',
23-
href: string,
24-
scrollY: number
21+
message: 'linkClicked';
22+
href: string;
23+
scrollY: number;
2524
}
2625
interface CodeClickedMessage extends IOutMessage {
27-
message: 'codeClicked',
28-
code: string,
26+
message: 'codeClicked';
27+
code: string;
2928
modifiers: {
30-
altKey: boolean,
31-
ctrlKey: boolean,
32-
shiftKey: boolean,
33-
metaKey: boolean,
34-
}
29+
altKey: boolean;
30+
ctrlKey: boolean;
31+
shiftKey: boolean;
32+
metaKey: boolean;
33+
};
3534
}
3635
interface GetScrollYMessage extends IOutMessage {
37-
message: 'getScrollY',
38-
scrollY: number
36+
message: 'getScrollY';
37+
scrollY: number;
3938
}
4039

41-
type OutMessage = LogMessage | MouseClickMessage | LinkClickedMessage | CodeClickedMessage | GetScrollYMessage;
42-
40+
type OutMessage =
41+
| LogMessage
42+
| MouseClickMessage
43+
| LinkClickedMessage
44+
| CodeClickedMessage
45+
| GetScrollYMessage;

0 commit comments

Comments
 (0)