Skip to content

Commit 98fadef

Browse files
committed
enable lint for scripts
1 parent 6b230b9 commit 98fadef

File tree

71 files changed

+1220
-1086
lines changed

Some content is hidden

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

71 files changed

+1220
-1086
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;

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ playground/compiler.js
9797
rewatch/target/
9898
rewatch/rewatch
9999

100-
*.tsbuildinfo
100+
*.tsbuildinfo

biome.json

+34-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,39 @@
77
"useIgnoreFile": true
88
},
99
"linter": {
10-
"enabled": false
10+
"enabled": true,
11+
"rules": {
12+
"recommended": true
13+
},
14+
"ignore": [
15+
"jscomp/build_tests/**/lib/**",
16+
"jscomp/build_tests/**/src/**",
17+
"jscomp/test/**",
18+
"lib/es6/**",
19+
"lib/js/**",
20+
"ninja/**",
21+
"playground/packages/**",
22+
"**/*.bs.js",
23+
"**/*.res.js",
24+
"**/*.gen.ts*",
25+
"package.json"
26+
]
1127
},
1228
"organizeImports": {
13-
"enabled": false
29+
"enabled": true,
30+
"ignore": [
31+
"jscomp/build_tests/**/lib/**",
32+
"jscomp/build_tests/**/src/**",
33+
"jscomp/test/**",
34+
"lib/es6/**",
35+
"lib/js/**",
36+
"ninja/**",
37+
"playground/packages/**",
38+
"**/*.bs.js",
39+
"**/*.res.js",
40+
"**/*.gen.ts*",
41+
"package.json"
42+
]
1443
},
1544
"formatter": {
1645
"enabled": true,
@@ -24,9 +53,10 @@
2453
"jscomp/build_tests/**/lib/**",
2554
"jscomp/build_tests/**/src/**",
2655
"jscomp/test/**",
27-
"lib/**",
56+
"lib/es6/**",
57+
"lib/js/**",
2858
"ninja/**",
29-
"playground/**",
59+
"playground/packages/**",
3060
"**/*.bs.js",
3161
"**/*.res.js",
3262
"**/*.gen.ts*",

cli/bin_path.js

+7-22
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
1-
//@ts-check
1+
// @ts-check
22

3-
var 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-
var binDirName =
12+
const binDirName =
1513
process.arch === "x64" || process.platform === "win32"
1614
? process.platform
1715
: process.platform + process.arch;
1816

19-
/**
20-
*
21-
* @type{string}
22-
*/
23-
var binAbsolutePath = path.join(__dirname, "..", binDirName);
17+
const binAbsolutePath = path.join(__dirname, "..", binDirName);
2418

25-
/**
26-
* @type{string}
27-
*/
28-
var bsc_exe = path.join(binAbsolutePath, "bsc.exe");
19+
const bsc_exe = path.join(binAbsolutePath, "bsc.exe");
2920

30-
/**
31-
* @type{string}
32-
*/
33-
var ninja_exe = path.join(binAbsolutePath, "ninja.exe");
21+
const ninja_exe = path.join(binAbsolutePath, "ninja.exe");
3422

35-
/**
36-
* @type{string}
37-
*/
38-
var rescript_exe = path.join(binAbsolutePath, "rescript.exe");
23+
const rescript_exe = path.join(binAbsolutePath, "rescript.exe");
3924

4025
exports.dirName = binDirName;
4126
exports.absolutePath = binAbsolutePath;

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)