Skip to content

Commit 15e8e48

Browse files
committed
Just: run prettier on .ts files
1 parent c67e123 commit 15e8e48

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

misc/just/codeql-test-run.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const vars = {
99
cmd_begin: process.env["CMD_BEGIN"] || "",
1010
cmd_end: process.env["CMD_END"] || "",
1111
semmle_code: process.env["SEMMLE_CODE"],
12-
}
12+
};
1313

1414
function invoke(
1515
invocation: string[],
@@ -81,7 +81,10 @@ function codeqlTestRun(argv: string[]): number {
8181
if (args.all) {
8282
parseArgs(args, all_args);
8383
}
84-
if (!vars.semmle_code && (args.codeql === "build" || args.codeql === "built")) {
84+
if (
85+
!vars.semmle_code &&
86+
(args.codeql === "build" || args.codeql === "built")
87+
) {
8588
console.error(
8689
"Using `--codeql=build` or `--codeql=built` requires working with the internal repository",
8790
);

misc/just/forward-command.ts

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,39 @@ const vars = {
77
error: process.env["JUST_ERROR"] || "",
88
};
99

10-
console.debug = (...args: any[]) => {} // comment out to debug script
10+
console.debug = (...args: any[]) => {}; // comment out to debug script
1111
const old_console_error = console.error;
1212
console.error = (message: string) => {
1313
old_console_error(vars.error + message);
1414
};
1515

16-
17-
function checkJustCommand(justfile: string, command: string, postitionalArgs: string[]): boolean {
16+
function checkJustCommand(
17+
justfile: string,
18+
command: string,
19+
postitionalArgs: string[],
20+
): boolean {
1821
if (!fs.existsSync(justfile)) {
1922
return false;
2023
}
21-
let {cwd, args} = getJustContext(justfile, command, [], postitionalArgs);
22-
console.debug(`Checking: ${cwd ? `cd ${cwd}; ` : ""}just ${args.join(", ")}`);
24+
let { cwd, args } = getJustContext(justfile, command, [], postitionalArgs);
25+
console.debug(
26+
`Checking: ${cwd ? `cd ${cwd}; ` : ""}just ${args.join(", ")}`,
27+
);
2328
const res = child_process.spawnSync(vars.just, ["--dry-run", ...args], {
2429
stdio: ["ignore", "ignore", "pipe"],
2530
encoding: "utf8",
2631
cwd,
2732
});
2833
console.debug("result:", res);
2934
// avoid having the forwarder find itself
30-
return res.status === 0 && !res.stderr.includes(`forward-command.ts" ${command} "$@"`);
35+
return (
36+
res.status === 0 &&
37+
!res.stderr.includes(`forward-command.ts" ${command} "$@"`)
38+
);
3139
}
3240

3341
function findJustfile(command: string, arg: string): string | undefined {
34-
for (let p = arg;; p = path.dirname(p)) {
42+
for (let p = arg; ; p = path.dirname(p)) {
3543
const candidate = path.join(p, "justfile");
3644
if (checkJustCommand(candidate, command, [arg])) {
3745
return candidate;
@@ -54,23 +62,28 @@ function forward(cmd: string, args: string[]): number {
5462
// non-positional arguments are flags, + (used by language tests) or environment variable settings
5563
const is_non_positional = /^(-.*|\+|[A-Z_][A-Z_0-9]*=.*)$/;
5664
const flags = args.filter((arg) => is_non_positional.test(arg));
57-
const positionalArgs = args.filter(
58-
(arg) => !is_non_positional.test(arg),
59-
);
65+
const positionalArgs = args.filter((arg) => !is_non_positional.test(arg));
6066
let justfiles: Map<string, string[]> = new Map();
61-
for(const arg of positionalArgs.length > 0 ? positionalArgs : ["."]) {
67+
for (const arg of positionalArgs.length > 0 ? positionalArgs : ["."]) {
6268
const justfile = findJustfile(cmd, arg);
6369
if (!justfile) {
6470
console.error(`No justfile found for ${cmd} on ${arg}`);
6571
return 1;
6672
}
67-
justfiles.set(justfile, [...justfiles.get(justfile) || [], arg]);
73+
justfiles.set(justfile, [...(justfiles.get(justfile) || []), arg]);
6874
}
69-
const invocations = Array.from(justfiles.entries()).map(([justfile, positionalArgs]) => {
70-
const {cwd, args} = getJustContext(justfile, cmd, flags, positionalArgs);
71-
console.log(`-> ${cwd ? `cd ${cwd}; ` : ""}just ${args.join(" ")}`);
72-
return { cwd, args };
73-
});
75+
const invocations = Array.from(justfiles.entries()).map(
76+
([justfile, positionalArgs]) => {
77+
const { cwd, args } = getJustContext(
78+
justfile,
79+
cmd,
80+
flags,
81+
positionalArgs,
82+
);
83+
console.log(`-> ${cwd ? `cd ${cwd}; ` : ""}just ${args.join(" ")}`);
84+
return { cwd, args };
85+
},
86+
);
7487
for (const { cwd, args } of invocations) {
7588
if (invokeJust(cwd, args) !== 0) {
7689
return 1;
@@ -79,27 +92,26 @@ function forward(cmd: string, args: string[]): number {
7992
return 0;
8093
}
8194

82-
function getJustContext(justfile: string, cmd: string, flags: string[], positionalArgs: string[]): {args: string[], cwd?: string} {
83-
if (positionalArgs.length === 1 && justfile == path.join(positionalArgs[0], "justfile")) {
95+
function getJustContext(
96+
justfile: string,
97+
cmd: string,
98+
flags: string[],
99+
positionalArgs: string[],
100+
): { args: string[]; cwd?: string } {
101+
if (
102+
positionalArgs.length === 1 &&
103+
justfile == path.join(positionalArgs[0], "justfile")
104+
) {
84105
// If there's only one positional argument and it matches the justfile path, suppress arguments
85106
// so for example `just build ql/rust` becomes `just build` in the `ql/rust` directory
86107
return {
87108
cwd: positionalArgs[0],
88-
args: [
89-
cmd,
90-
...flags,
91-
],
109+
args: [cmd, ...flags],
92110
};
93111
} else {
94112
return {
95113
cwd: undefined,
96-
args: [
97-
"--justfile",
98-
justfile,
99-
cmd,
100-
...flags,
101-
...positionalArgs,
102-
],
114+
args: ["--justfile", justfile, cmd, ...flags, ...positionalArgs],
103115
};
104116
}
105117
}

misc/just/language-tests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import * as path from "path";
2-
import * as process from "process"
2+
import * as process from "process";
33
import * as child_process from "child_process";
44

55
function languageTests(argv: string[]): number {
66
const [extra_args, dir, ...relativeRoots] = argv;
77
const semmle_code = process.env["SEMMLE_CODE"]!;
8-
let roots = relativeRoots.map((root) => path.relative(semmle_code, path.join(dir, root)));
8+
let roots = relativeRoots.map((root) =>
9+
path.relative(semmle_code, path.join(dir, root)),
10+
);
911
const invocation = [
1012
process.env["JUST_EXECUTABLE"] || "just",
1113
"--justfile",

0 commit comments

Comments
 (0)