Skip to content

Commit 2bb06a1

Browse files
committed
enable lint for js
1 parent 51c30f9 commit 2bb06a1

File tree

85 files changed

+1006
-801
lines changed

Some content is hidden

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

85 files changed

+1006
-801
lines changed

.github/workflows/get_artifact_dir_name.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require("fs");
2-
const os = require("os");
1+
const fs = require("node:fs");
2+
const os = require("node:os");
33

44
const { dirName: artifactDirName } = require("../../cli/bin_path.js");
55

.github/workflows/prepare_package_upload.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require("fs");
2-
const os = require("os");
1+
const fs = require("node:fs");
2+
const os = require("node:os");
33

44
const packageSpec = require("rescript/package.json");
55
const { version } = packageSpec;

analysis/examples/example-project/types.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
}
99
],
1010
"custom": [
11-
{"module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1}
11+
{ "module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1 }
1212
]
13-
}
13+
}

analysis/examples/larger-project/.watchmanconfig

Whitespace-only changes.

biome.json

+26-19
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
"useIgnoreFile": true
88
},
99
"linter": {
10-
"enabled": false
10+
"enabled": true,
11+
"rules": {
12+
"recommended": true
13+
}
1114
},
1215
"organizeImports": {
13-
"enabled": false
16+
"enabled": true
1417
},
1518
"formatter": {
1619
"enabled": true,
@@ -19,23 +22,7 @@
1922
"indentWidth": 2,
2023
"lineEnding": "lf",
2124
"lineWidth": 80,
22-
"attributePosition": "auto",
23-
"ignore": [
24-
"tests/build_tests/**",
25-
"tests/tests/**",
26-
"tests/tools_tests/**",
27-
"tests/analysis_tests/**",
28-
"tests/docstring_tests/**",
29-
"analysis/examples/**",
30-
"analysis/reanalyze/examples/**",
31-
"lib/**",
32-
"ninja/**",
33-
"playground/**",
34-
"**/*.bs.js",
35-
"**/*.res.js",
36-
"**/*.gen.ts*",
37-
"package.json"
38-
]
25+
"attributePosition": "auto"
3926
},
4027
"javascript": {
4128
"formatter": {
@@ -49,5 +36,25 @@
4936
"quoteStyle": "double",
5037
"attributePosition": "auto"
5138
}
39+
},
40+
"files": {
41+
"include": ["tests/build_tests/**/node_modules/**"],
42+
"ignore": [
43+
"tests/analysis_tests/**/src/**",
44+
"tests/build_tests/**/src/**",
45+
"tests/docstring_tests/**",
46+
"tests/tests/**/src/**",
47+
"tests/tools_tests/**/src/**",
48+
"analysis/examples/**/src/**",
49+
"lib/es6/**",
50+
"lib/js/**",
51+
"ninja/**",
52+
"playground/packages/**",
53+
"*.bs.js",
54+
"*.res.js",
55+
"*.res.mjs",
56+
"*.gen.ts*",
57+
"package.json"
58+
]
5259
}
5360
}

cli/bin_path.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,61 @@
1-
//@ts-check
1+
// @ts-check
22

3-
const path = require("path");
3+
const path = require("node:path");
44

55
/**
6-
* @type{string}
7-
*
86
* For compatibility reasons, if the architecture is x64, omit it from the bin directory name.
97
* So we'll have "darwin", "linux" and "win32" for x64 arch,
108
* but "darwinarm64" and "linuxarm64" for arm64 arch.
119
* Also, we do not have Windows ARM binaries yet. But the x64 binaries do work on Windows 11 ARM.
1210
* So omit the architecture for Windows, too.
1311
*/
14-
const binDirName =
12+
const platformName =
1513
process.arch === "x64" || process.platform === "win32"
1614
? process.platform
1715
: process.platform + process.arch;
1816

1917
/**
20-
*
21-
* @type{string}
18+
* @type {string}
2219
*/
23-
const binAbsolutePath = path.join(__dirname, "..", binDirName);
20+
const platformDir = path.resolve(__dirname, "..", platformName);
2421

2522
/**
26-
* @type{string}
23+
* @type {string}
2724
*/
28-
const bsc_exe = path.join(binAbsolutePath, "bsc.exe");
25+
const bsc_exe = path.join(platformDir, "bsc.exe");
2926

3027
/**
31-
* @type{string}
28+
* @type {string}
3229
*/
33-
const ninja_exe = path.join(binAbsolutePath, "ninja.exe");
30+
const ninja_exe = path.join(platformDir, "ninja.exe");
3431

3532
/**
36-
* @type{string}
33+
* @type {string}
3734
*/
38-
const rescript_exe = path.join(binAbsolutePath, "rescript.exe");
35+
const rescript_exe = path.join(platformDir, "rescript.exe");
3936

4037
/**
41-
* @type{string}
38+
* @type {string}
4239
*/
43-
const rescript_tools_exe = path.join(binAbsolutePath, "rescript-tools.exe");
40+
const rescript_tools_exe = path.join(platformDir, "rescript-tools.exe");
4441

4542
/**
46-
* @type{string}
43+
* @type {string}
4744
*/
4845
const rescript_editor_analysis_exe = path.join(
49-
binAbsolutePath,
46+
platformDir,
5047
"rescript-editor-analysis.exe",
5148
);
5249

53-
exports.dirName = binDirName;
54-
exports.absolutePath = binAbsolutePath;
50+
/**
51+
* @type {string}
52+
*/
53+
const rewatch_exe = path.join(platformDir, "rewatch.exe");
54+
55+
exports.platformDir = platformDir;
5556
exports.bsc_exe = bsc_exe;
5657
exports.ninja_exe = ninja_exe;
5758
exports.rescript_exe = rescript_exe;
5859
exports.rescript_tools_exe = rescript_tools_exe;
5960
exports.rescript_editor_analysis_exe = rescript_editor_analysis_exe;
61+
exports.rewatch_exe = rewatch_exe;

cli/bsc

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env node
2+
3+
// @ts-check
4+
25
"use strict";
36

4-
var child_process = require("child_process");
5-
var { bsc_exe } = require("./bin_path");
7+
const child_process = require("child_process");
8+
const { bsc_exe } = require("./bin_path.js");
69

7-
var delegate_args = process.argv.slice(2);
10+
const delegate_args = process.argv.slice(2);
811

912
try {
1013
child_process.execFileSync(bsc_exe, delegate_args, { stdio: "inherit" });

cli/rescript

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#!/usr/bin/env node
2+
23
//@ts-check
4+
35
"use strict";
46

5-
/**
6-
* This script is supposed to be running in project root directory
7-
* It matters since we need read .sourcedirs(location)
8-
* and its content are file/directories with regard to project root
9-
*/
7+
// This script is supposed to be running in project root directory
8+
// It matters since we need read .sourcedirs(location)
9+
// and its content are file/directories with regard to project root
1010

11-
var { bsc_exe, rescript_exe } = require("./bin_path.js");
12-
var bsb = require("./rescript_bsb.js");
11+
const tty = require("node:tty");
12+
const { bsc_exe, rescript_exe } = require("./bin_path.js");
13+
const bsb = require("./rescript_bsb.js");
1314

14-
var cwd = process.cwd();
15+
const cwd = process.cwd();
1516
process.env.BSB_PROJECT_ROOT = cwd;
1617

1718
if (process.env.FORCE_COLOR === undefined) {
18-
if (require("tty").isatty(1)) {
19+
if (tty.isatty(1)) {
1920
process.env.FORCE_COLOR = "1";
2021
process.env.NINJA_ANSI_FORCED = "1";
2122
}

cli/rescript-tools

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env node
2-
//@ts-check
3-
"use strict";
42

5-
const path = require("path");
6-
const child_process = require("child_process");
3+
// @ts-check
4+
5+
"use strict";
76

8-
const { absolutePath: binAbsolutePath } = require("./bin_path");
9-
const rewatchExe = path.join(binAbsolutePath, "rescript-tools.exe");
7+
const child_process = require("node:child_process");
8+
const { rescript_tools_exe } = require("./bin_path.js");
109

1110
const args = process.argv.slice(2);
1211

13-
child_process.spawnSync(rewatchExe, args, { stdio: "inherit" });
12+
child_process.spawnSync(rescript_tools_exe, args, { stdio: "inherit" });

cli/rescript_arg.js

+35-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//@ts-check
1+
// @ts-check
2+
23
class StringBuilder {
34
constructor() {
45
this.val = "";
@@ -13,23 +14,32 @@ class StringBuilder {
1314
return this;
1415
}
1516
}
17+
1618
class ArgError extends Error {}
1719

1820
/**
19-
*
2021
* @param {string} s
2122
*/
2223
function bad_arg(s) {
2324
throw new ArgError(s);
2425
}
2526

2627
/**
27-
* @typedef {{val : string}} stringref
28-
* @typedef {{val : boolean}} boolref
29-
* @typedef {{kind:"Unit_call",data : ()=>void } | {kind : "Unit_set", data : boolref}} unit_action
30-
* @typedef {{kind:"String_call",data:(s : string)=>void} | {kind : "String_set",data: stringref}} string_action
31-
* @typedef {{kind:"Unit",data : unit_action } | {kind:"String", data: string_action}} action
32-
* @typedef {Array<[string,action,string]>} specs
28+
* @typedef {{ val: string }} stringref
29+
* @typedef {{ val: boolean }} boolref
30+
* @typedef {(
31+
* | { kind: "Unit_call", data: () => void }
32+
* | { kind: "Unit_set", data: boolref }
33+
* )} unit_action
34+
* @typedef {(
35+
* | { kind: "String_call", data: (s: string) => void }
36+
* | {kind: "String_set", data: stringref }
37+
* )} string_action
38+
* @typedef {(
39+
* | { kind: "Unit", data: unit_action }
40+
* | { kind: "String", data: string_action}
41+
* )} action
42+
* @typedef {Array<[string, action, string]>} specs
3343
* @param {StringBuilder} b
3444
* @param {string} usage
3545
* @param {specs} specs
@@ -39,33 +49,32 @@ function usage_b(b, usage, specs) {
3949
if (specs.length === 0) {
4050
return;
4151
}
42-
b.add(`\nOptions:\n`);
43-
var max_col = 0;
44-
for (let [key] of specs) {
52+
b.add("\nOptions:\n");
53+
let max_col = 0;
54+
for (const [key] of specs) {
4555
if (key.length > max_col) {
4656
max_col = key.length;
4757
}
4858
}
4959
for (let i = 0; i < specs.length; i++) {
50-
let [key, _, doc] = specs[i];
60+
const [key, _, doc] = specs[i];
5161
if (!doc.startsWith("*internal*")) {
5262
b.add(" ")
5363
.add(key)
5464
.add(" ".repeat(max_col - key.length + 2));
5565
let cur = 0;
56-
let doc_length = doc.length;
66+
const doc_length = doc.length;
5767
while (cur < doc_length) {
5868
if (cur !== 0) {
5969
b.add("\n").add(" ".repeat(max_col + 4));
6070
}
61-
let i = doc.indexOf("\n", cur);
71+
const i = doc.indexOf("\n", cur);
6272
if (i < 0) {
6373
b.add(doc.substring(cur));
6474
break;
65-
} else {
66-
b.add(doc.substr(cur, i - cur));
67-
cur = i + 1;
6875
}
76+
b.add(doc.substring(cur, i - cur));
77+
cur = i + 1;
6978
}
7079
b.add("\n");
7180
}
@@ -79,7 +88,7 @@ function usage_b(b, usage, specs) {
7988
* @param {specs} specs
8089
*/
8190
function stop_raise(usage, error, specs) {
82-
var b = new StringBuilder();
91+
const b = new StringBuilder();
8392
switch (error.kind) {
8493
case "Unknown":
8594
if (["-help", "--help", "-h"].includes(error.data)) {
@@ -89,8 +98,10 @@ function stop_raise(usage, error, specs) {
8998
} else {
9099
b.add(`Unknown option "${error.data}".\n'`);
91100
}
101+
break;
92102
case "Missing":
93103
b.add(`Option "${error.data}" needs an argument.\n'`);
104+
break;
94105
}
95106
usage_b(b, usage, specs);
96107
bad_arg(b.val);
@@ -114,15 +125,15 @@ function parse_exn(
114125
// first 3 are [node, rescript, subcommand]
115126
finish = argv.length,
116127
) {
117-
var current = start;
118-
var list = [];
128+
let current = start;
129+
const list = [];
119130
while (current < finish) {
120-
let s = argv[current];
131+
const s = argv[current];
121132
++current;
122133
if (s !== "" && s[0] === "-") {
123-
var out = specs.find(([flag]) => flag === s);
134+
const out = specs.find(([flag]) => flag === s);
124135
if (out !== undefined) {
125-
let [_, action] = out;
136+
const [_, action] = out;
126137
switch (action.kind) {
127138
case "Unit":
128139
switch (action.data.kind) {
@@ -139,7 +150,7 @@ function parse_exn(
139150
if (current >= finish) {
140151
stop_raise(usage, { kind: "Missing", data: s }, specs);
141152
} else {
142-
let arg = argv[current];
153+
const arg = argv[current];
143154
++current;
144155
switch (action.data.kind) {
145156
case "String_call":

0 commit comments

Comments
 (0)