Skip to content

Commit

Permalink
enable lint for scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Jul 21, 2024
1 parent 6b230b9 commit 98fadef
Show file tree
Hide file tree
Showing 71 changed files with 1,220 additions and 1,086 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/get_artifact_dir_name.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const os = require("os");
const fs = require("node:fs");
const os = require("node:os");

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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prepare_package_upload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const os = require("os");
const fs = require("node:fs");
const os = require("node:os");

const packageSpec = require("rescript/package.json");
const { version } = packageSpec;
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ playground/compiler.js
rewatch/target/
rewatch/rewatch

*.tsbuildinfo
*.tsbuildinfo
38 changes: 34 additions & 4 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,39 @@
"useIgnoreFile": true
},
"linter": {
"enabled": false
"enabled": true,
"rules": {
"recommended": true
},
"ignore": [
"jscomp/build_tests/**/lib/**",
"jscomp/build_tests/**/src/**",
"jscomp/test/**",
"lib/es6/**",
"lib/js/**",
"ninja/**",
"playground/packages/**",
"**/*.bs.js",
"**/*.res.js",
"**/*.gen.ts*",
"package.json"
]
},
"organizeImports": {
"enabled": false
"enabled": true,
"ignore": [
"jscomp/build_tests/**/lib/**",
"jscomp/build_tests/**/src/**",
"jscomp/test/**",
"lib/es6/**",
"lib/js/**",
"ninja/**",
"playground/packages/**",
"**/*.bs.js",
"**/*.res.js",
"**/*.gen.ts*",
"package.json"
]
},
"formatter": {
"enabled": true,
Expand All @@ -24,9 +53,10 @@
"jscomp/build_tests/**/lib/**",
"jscomp/build_tests/**/src/**",
"jscomp/test/**",
"lib/**",
"lib/es6/**",
"lib/js/**",
"ninja/**",
"playground/**",
"playground/packages/**",
"**/*.bs.js",
"**/*.res.js",
"**/*.gen.ts*",
Expand Down
29 changes: 7 additions & 22 deletions cli/bin_path.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
//@ts-check
// @ts-check

var path = require("path");
const path = require("node:path");

/**
* @type{string}
*
* For compatibility reasons, if the architecture is x64, omit it from the bin directory name.
* So we'll have "darwin", "linux" and "win32" for x64 arch,
* but "darwinarm64" and "linuxarm64" for arm64 arch.
* Also, we do not have Windows ARM binaries yet. But the x64 binaries do work on Windows 11 ARM.
* So omit the architecture for Windows, too.
*/
var binDirName =
const binDirName =
process.arch === "x64" || process.platform === "win32"
? process.platform
: process.platform + process.arch;

/**
*
* @type{string}
*/
var binAbsolutePath = path.join(__dirname, "..", binDirName);
const binAbsolutePath = path.join(__dirname, "..", binDirName);

/**
* @type{string}
*/
var bsc_exe = path.join(binAbsolutePath, "bsc.exe");
const bsc_exe = path.join(binAbsolutePath, "bsc.exe");

/**
* @type{string}
*/
var ninja_exe = path.join(binAbsolutePath, "ninja.exe");
const ninja_exe = path.join(binAbsolutePath, "ninja.exe");

/**
* @type{string}
*/
var rescript_exe = path.join(binAbsolutePath, "rescript.exe");
const rescript_exe = path.join(binAbsolutePath, "rescript.exe");

exports.dirName = binDirName;
exports.absolutePath = binAbsolutePath;
Expand Down
59 changes: 35 additions & 24 deletions cli/rescript_arg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ts-check
// @ts-check

class StringBuilder {
constructor() {
this.val = "";
Expand All @@ -13,23 +14,32 @@ class StringBuilder {
return this;
}
}

class ArgError extends Error {}

/**
*
* @param {string} s
*/
function bad_arg(s) {
throw new ArgError(s);
}

/**
* @typedef {{val : string}} stringref
* @typedef {{val : boolean}} boolref
* @typedef {{kind:"Unit_call",data : ()=>void } | {kind : "Unit_set", data : boolref}} unit_action
* @typedef {{kind:"String_call",data:(s : string)=>void} | {kind : "String_set",data: stringref}} string_action
* @typedef {{kind:"Unit",data : unit_action } | {kind:"String", data: string_action}} action
* @typedef {Array<[string,action,string]>} specs
* @typedef {{ val: string }} stringref
* @typedef {{ val: boolean }} boolref
* @typedef {(
* | { kind: "Unit_call", data: () => void }
* | { kind: "Unit_set", data: boolref }
* )} unit_action
* @typedef {(
* | { kind: "String_call", data: (s: string) => void }
* | {kind: "String_set", data: stringref }
* )} string_action
* @typedef {(
* | { kind: "Unit", data: unit_action }
* | { kind: "String", data: string_action}
* )} action
* @typedef {Array<[string, action, string]>} specs
* @param {StringBuilder} b
* @param {string} usage
* @param {specs} specs
Expand All @@ -39,33 +49,32 @@ function usage_b(b, usage, specs) {
if (specs.length === 0) {
return;
}
b.add(`\nOptions:\n`);
var max_col = 0;
for (let [key] of specs) {
b.add("\nOptions:\n");
let max_col = 0;
for (const [key] of specs) {
if (key.length > max_col) {
max_col = key.length;
}
}
for (let i = 0; i < specs.length; i++) {
let [key, _, doc] = specs[i];
const [key, _, doc] = specs[i];
if (!doc.startsWith("*internal*")) {
b.add(" ")
.add(key)
.add(" ".repeat(max_col - key.length + 2));
let cur = 0;
let doc_length = doc.length;
const doc_length = doc.length;
while (cur < doc_length) {
if (cur !== 0) {
b.add("\n").add(" ".repeat(max_col + 4));
}
let i = doc.indexOf("\n", cur);
const i = doc.indexOf("\n", cur);
if (i < 0) {
b.add(doc.substring(cur));
break;
} else {
b.add(doc.substr(cur, i - cur));
cur = i + 1;
}
b.add(doc.substring(cur, i - cur));
cur = i + 1;
}
b.add("\n");
}
Expand All @@ -79,7 +88,7 @@ function usage_b(b, usage, specs) {
* @param {specs} specs
*/
function stop_raise(usage, error, specs) {
var b = new StringBuilder();
const b = new StringBuilder();
switch (error.kind) {
case "Unknown":
if (["-help", "--help", "-h"].includes(error.data)) {
Expand All @@ -89,8 +98,10 @@ function stop_raise(usage, error, specs) {
} else {
b.add(`Unknown option "${error.data}".\n'`);
}
break;
case "Missing":
b.add(`Option "${error.data}" needs an argument.\n'`);
break;
}
usage_b(b, usage, specs);
bad_arg(b.val);
Expand All @@ -114,15 +125,15 @@ function parse_exn(
// first 3 are [node, rescript, subcommand]
finish = argv.length,
) {
var current = start;
var list = [];
let current = start;
const list = [];
while (current < finish) {
let s = argv[current];
const s = argv[current];
++current;
if (s !== "" && s[0] === "-") {
var out = specs.find(([flag]) => flag === s);
const out = specs.find(([flag]) => flag === s);
if (out !== undefined) {
let [_, action] = out;
const [_, action] = out;
switch (action.kind) {
case "Unit":
switch (action.data.kind) {
Expand All @@ -139,7 +150,7 @@ function parse_exn(
if (current >= finish) {
stop_raise(usage, { kind: "Missing", data: s }, specs);
} else {
let arg = argv[current];
const arg = argv[current];
++current;
switch (action.data.kind) {
case "String_call":
Expand Down
Loading

0 comments on commit 98fadef

Please sign in to comment.