Skip to content

Commit cf669bb

Browse files
authored
Merge pull request #201 from rescript-lang/oxfmt
Use oxfmt
2 parents bb19519 + b60f543 commit cf669bb

File tree

14 files changed

+401
-202
lines changed

14 files changed

+401
-202
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- name: Install dependencies
3131
run: npm ci
3232

33+
- name: Check formatting
34+
run: npm run format:check
35+
3336
- name: Rebuild ReScript code
3437
run: npm run build
3538

@@ -81,4 +84,4 @@ jobs:
8184
steps:
8285
- name: Deploy to GitHub Pages
8386
id: deployment
84-
uses: actions/deploy-pages@v4
87+
uses: actions/deploy-pages@v4

docs/content/docs/contributing/api-modelling.mdx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ String(unsafeConversation(t))
112112
}
113113
`
114114

115-
<Code
116-
code={fillStyleModule}
117-
title="DOMAPI/FillStyle.res"
118-
lang="ReScript"
119-
></Code>
115+
<Code code={fillStyleModule} title="DOMAPI/FillStyle.res" lang="ReScript"></Code>
120116

121117
We can now use `FillStyle.decode` to get the actual value of the `fillStyle` property.
122118
And use `FillStyle.fromString`, `FillStyle.fromCanvasGradient`, and `FillStyle.fromCanvasPattern` to set the value.
@@ -135,11 +131,5 @@ switch ctx.fillStyle->FillStyle.decode {
135131
}
136132
```
137133

138-
<Icon
139-
name="information"
140-
color="var(--sl-color-text-accent)"
141-
class="inline-icon"
142-
size="1.5rem"
143-
/>
144-
Try and use `decoded` and `decode` as conventions for the type and function
145-
names.
134+
<Icon name="information" color="var(--sl-color-text-accent)" class="inline-icon" size="1.5rem" />
135+
Try and use `decoded` and `decode` as conventions for the type and function names.

docs/content/docs/contributing/api-module-structure.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ type htmlSpanElement = {
5151
```
5252

5353
<Aside>
54-
Properties spreading is not possible in recursive types! When a circular
55-
reference is detected, the base properties are duplicated instead.
54+
Properties spreading is not possible in recursive types! When a circular reference is detected,
55+
the base properties are duplicated instead.
5656
</Aside>
5757

5858
```ReScript

docs/content/docs/contributing/code-generation.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ interfaceHierarchy = [
6464
name: "Temp",
6565
entries: [
6666
enums(["WebGLPowerPreference"]),
67-
dictionaries([
68-
"ImageBitmapRenderingContextSettings",
69-
"WebGLContextAttributes",
70-
]),
67+
dictionaries(["ImageBitmapRenderingContextSettings", "WebGLContextAttributes"]),
7168
],
7269
opens: [],
7370
},

docs/content/docs/contributing/getting-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ slug: "01-getting-started"
77
import { Aside } from "@astrojs/starlight/components";
88

99
<Aside type="caution">
10-
**Real talk**: First time diving into this project? Might feel like a letdown.
11-
But hey, the upside? It’s stupid easy to toss us a PR and make it better!
10+
**Real talk**: First time diving into this project? Might feel like a letdown. But hey, the
11+
upside? It’s stupid easy to toss us a PR and make it better!
1212
</Aside>
1313

1414
The [WebAPI](https://developer.mozilla.org/en-US/docs/Web/API) are vast and ever-growing. We need your help to make them better.

docs/content/docs/contributing/module-type-structure.mdx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ open DOMAPI
4545
// A concrete type for \`T.t\` is passed later using the \`include\` keyword.
4646
module Impl = (T: { type t }) => {
4747
48-
/**
48+
/\*_
4949
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLElement/focus)
50-
*/
50+
_/
5151
@send
5252
external focus: (T.t, ~options: focusOptions=?) => unit = "focus"
5353
@@ -56,11 +56,7 @@ external focus: (T.t, ~options: focusOptions=?) => unit = "focus"
5656
include Impl({ type t = htmlElement })
5757
`;
5858

59-
<Code
60-
code={htmlElementModule}
61-
title="DOMAPI/HTMLElement.res"
62-
lang="ReScript"
63-
></Code>
59+
<Code code={htmlElementModule} title="DOMAPI/HTMLElement.res" lang="ReScript"></Code>
6460

6561
export const buttonModule = `
6662
open DOMAPI
@@ -70,17 +66,12 @@ include HTMLElement.Impl({ type t = htmlButtonElement })
7066
7167
// Add additional methods specific to HTMLButtonElement:
7268
73-
/**
69+
/\*_
7470
Returns whether a form will validate when it is submitted, without having to submit it.
75-
[Read more on MDN](
76-
https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/checkValidity)
77-
*/
71+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/checkValidity)
72+
_/
7873
@send
7974
external checkValidity: htmlButtonElement => bool = "checkValidity"
8075
`;
8176

82-
<Code
83-
code={buttonModule}
84-
title="DOMAPI/HTMLButtonElement.res"
85-
lang="ReScript"
86-
></Code>
77+
<Code code={buttonModule} title="DOMAPI/HTMLButtonElement.res" lang="ReScript"></Code>

docs/content/docs/contributing/testing.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ npm test
3636
If any of the existing tests have different ouput JavaScript, you will see a diff in the output and the test will fail.
3737

3838
<Aside>
39-
Depending on your use-case, it might be okay to have slightly different output
40-
JavaScript. The maintainers will help you to decide if the change is
41-
acceptable.
39+
Depending on your use-case, it might be okay to have slightly different output JavaScript. The
40+
maintainers will help you to decide if the change is acceptable.
4241
</Aside>
4342

4443
## Why add tests?

docs/content/docs/index.mdx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,10 @@ Install the package using your favorite package manager:
2727

2828
<Tabs syncKey="package manager">
2929
<TabItem label="npm">
30-
<Code
31-
lang="shell"
32-
frame="none"
33-
code="npm i @rescript/webapi@experimental"
34-
/>
30+
<Code lang="shell" frame="none" code="npm i @rescript/webapi@experimental" />
3531
</TabItem>
3632
<TabItem label="bun">
37-
<Code
38-
lang="shell"
39-
frame="none"
40-
code="bun i @rescript/webapi@experimental"
41-
/>
33+
<Code lang="shell" frame="none" code="bun i @rescript/webapi@experimental" />
4234
</TabItem>
4335
</Tabs>
4436

docs/llm.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,102 +6,102 @@ import fs from "node:fs/promises";
66
const execAsync = promisify(exec);
77

88
const bins = await import(
9-
path.join(import.meta.dirname, "../node_modules/rescript/cli/common/bins.js")
9+
path.join(import.meta.dirname, "../node_modules/rescript/cli/common/bins.js")
1010
);
1111
const rescriptTools = bins["rescript_tools_exe"];
1212

1313
if (!rescriptTools) {
14-
throw new Error("rescript-tools not found");
14+
throw new Error("rescript-tools not found");
1515
}
1616

1717
async function getDocJson(filePath) {
18-
try {
19-
const command = `${rescriptTools} doc "${filePath}"`;
20-
const options = { maxBuffer: 10 * 1024 * 1024 };
21-
const { stdout, stderr } = await execAsync(command, options);
22-
23-
if (stderr) {
24-
throw new Error(`Error executing command for ${filePath}: ${stderr}`);
25-
}
26-
27-
return JSON.parse(stdout);
28-
} catch (error) {
29-
throw new Error(`Failed to get documentation JSON for ${filePath}:`, error);
18+
try {
19+
const command = `${rescriptTools} doc "${filePath}"`;
20+
const options = { maxBuffer: 10 * 1024 * 1024 };
21+
const { stdout, stderr } = await execAsync(command, options);
22+
23+
if (stderr) {
24+
throw new Error(`Error executing command for ${filePath}: ${stderr}`);
3025
}
26+
27+
return JSON.parse(stdout);
28+
} catch (error) {
29+
throw new Error(`Failed to get documentation JSON for ${filePath}:`, error);
30+
}
3131
}
3232

3333
async function processFile(filePath) {
34-
const json = await getDocJson(filePath);
35-
36-
const moduleName = "WebAPI." + json.name.replace("-WebAPI", "");
37-
38-
const types = [];
39-
const functions = [];
40-
41-
function mkType(item) {
42-
let description = "";
43-
if (item.docstrings.length > 0) {
44-
description = "\n Description: " + item.docstrings.join("\n");
45-
}
46-
let fields = "";
47-
if (item.detail && item.detail.kind === "record") {
48-
fields =
49-
"\n Fields:\n" +
50-
item.detail.items
51-
.map((field) => {
52-
let fieldDoc = "";
53-
if (field.docstrings.length > 0) {
54-
fieldDoc = " - " + field.docstrings.join(" ");
55-
}
56-
return ` - ${field.name}: ${field.signature}${fieldDoc}`;
57-
})
58-
.join("\n");
59-
}
60-
return `- ${item.signature}${description}${fields}`;
61-
}
34+
const json = await getDocJson(filePath);
6235

63-
function mkFunction(item) {
64-
let description = "";
65-
if (item.docstrings.length > 0) {
66-
description = "\n Description: " + item.docstrings.join("\n");
67-
}
68-
return `- ${item.signature}${description}`;
69-
}
36+
const moduleName = "WebAPI." + json.name.replace("-WebAPI", "");
7037

71-
for (const item of json.items) {
72-
switch (item.kind) {
73-
case "type":
74-
types.push(mkType(item));
75-
break;
76-
case "value":
77-
functions.push(mkFunction(item));
78-
break;
79-
}
80-
}
38+
const types = [];
39+
const functions = [];
8140

82-
let typeString = "";
83-
if (types.length > 0) {
84-
typeString = "\n\nTypes:\n\n" + types.join("\n\n");
41+
function mkType(item) {
42+
let description = "";
43+
if (item.docstrings.length > 0) {
44+
description = "\n Description: " + item.docstrings.join("\n");
8545
}
46+
let fields = "";
47+
if (item.detail && item.detail.kind === "record") {
48+
fields =
49+
"\n Fields:\n" +
50+
item.detail.items
51+
.map((field) => {
52+
let fieldDoc = "";
53+
if (field.docstrings.length > 0) {
54+
fieldDoc = " - " + field.docstrings.join(" ");
55+
}
56+
return ` - ${field.name}: ${field.signature}${fieldDoc}`;
57+
})
58+
.join("\n");
59+
}
60+
return `- ${item.signature}${description}${fields}`;
61+
}
8662

87-
let functionString = "";
88-
if (functions.length > 0) {
89-
functionString = "\n\nFunctions:\n\n" + functions.join("\n\n");
63+
function mkFunction(item) {
64+
let description = "";
65+
if (item.docstrings.length > 0) {
66+
description = "\n Description: " + item.docstrings.join("\n");
67+
}
68+
return `- ${item.signature}${description}`;
69+
}
70+
71+
for (const item of json.items) {
72+
switch (item.kind) {
73+
case "type":
74+
types.push(mkType(item));
75+
break;
76+
case "value":
77+
functions.push(mkFunction(item));
78+
break;
9079
}
80+
}
81+
82+
let typeString = "";
83+
if (types.length > 0) {
84+
typeString = "\n\nTypes:\n\n" + types.join("\n\n");
85+
}
9186

92-
return `File: ${json.source.filepath}
87+
let functionString = "";
88+
if (functions.length > 0) {
89+
functionString = "\n\nFunctions:\n\n" + functions.join("\n\n");
90+
}
91+
92+
return `File: ${json.source.filepath}
9393
Module: ${moduleName}${typeString}${functionString}
9494
`;
9595
}
9696

97-
const pattern = "../src/**/*.res"
97+
const pattern = "../src/**/*.res";
9898
const files = [];
99-
for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) {
100-
files.push(path.join(import.meta.dirname, file));
99+
for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) {
100+
files.push(path.join(import.meta.dirname, file));
101101
}
102102
files.sort();
103103

104-
const pages = await Promise.all(files.map(processFile))
104+
const pages = await Promise.all(files.map(processFile));
105105
const packageJson = await fs.readFile(path.join(import.meta.dirname, "../package.json"), "utf-8");
106106
let version = JSON.parse(packageJson).version;
107107
const sha = await execAsync("git rev-parse --short HEAD").then(({ stdout }) => stdout.trim());
@@ -111,7 +111,7 @@ const header = `Experimental Rescript WebAPI Documentation ${fullVersion}
111111
This is the API documentation for the experimental WebAPI module version ${fullVersion}.
112112
More information can be found on https://rescript-lang.github.io/experimental-rescript-webapi/
113113
114-
`
114+
`;
115115
const content = pages.join("\n---\n\n");
116116
await fs.writeFile(path.join(import.meta.dirname, "public/llm.txt"), header + content);
117-
console.log("Generated llm.txt");
117+
console.log("Generated llm.txt");

0 commit comments

Comments
 (0)