Skip to content

Commit 0ab3d4b

Browse files
authored
Ensure algorithm steps are always wrapped in braces (#1146)
1 parent b7c57ea commit 0ab3d4b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

.github/algorithm-format-check.mjs

+30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { readFile, readdir } from "node:fs/promises";
22

33
const SPEC_DIR = new URL("../spec", import.meta.url).pathname;
44

5+
/** @see {@link https://spec-md.com/#sec-Value-Literals} */
6+
const valueLiteralsRegexp = /\{((?:[^{}]|(?:\{[^{}]*\}))+)\}/g;
7+
58
process.exitCode = 0;
69
const filenames = await readdir(SPEC_DIR);
710
for (const filename of filenames) {
@@ -72,6 +75,33 @@ for (const filename of filenames) {
7275
console.log();
7376
process.exitCode = 1;
7477
}
78+
79+
const stepWithoutValueLiterals = step.replace(
80+
valueLiteralsRegexp,
81+
""
82+
);
83+
if (stepWithoutValueLiterals.match(/\b[A-Z][A-Za-z0-9]+\(/)) {
84+
console.log(
85+
`Bad formatting of '${algorithmName}' step (algorithm call should be wrapped in braces: \`{MyAlgorithm(a, b, c)}\`) in '${filename}':`
86+
);
87+
console.dir(step);
88+
console.log();
89+
process.exitCode = 1;
90+
}
91+
92+
const valueLiterals = step.matchAll(valueLiteralsRegexp, "");
93+
for (const lit of valueLiterals) {
94+
const inner = lit[1];
95+
if (inner.includes("{")) {
96+
console.log(
97+
`Bad formatting of '${algorithmName}' step (algorithm call should not contain braces: \`${lit}\`) in '${filename}':`
98+
);
99+
console.dir(step);
100+
console.log();
101+
process.exitCode = 1;
102+
}
103+
}
104+
75105
const trimmedInnerLine = step.replace(/\s+/g, " ");
76106
if (
77107
trimmedInnerLine.match(

spec/Section 3 -- Type System.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ IsInputType(type):
351351

352352
- If {type} is a List type or Non-Null type:
353353
- Let {unwrappedType} be the unwrapped type of {type}.
354-
- Return IsInputType({unwrappedType}).
354+
- Return {IsInputType(unwrappedType)}.
355355
- If {type} is a Scalar, Enum, or Input Object type:
356356
- Return {true}.
357357
- Return {false}.
@@ -360,7 +360,7 @@ IsOutputType(type):
360360

361361
- If {type} is a List type or Non-Null type:
362362
- Let {unwrappedType} be the unwrapped type of {type}.
363-
- Return IsOutputType({unwrappedType}).
363+
- Return {IsOutputType(unwrappedType)}.
364364
- If {type} is a Scalar, Object, Interface, Union, or Enum type:
365365
- Return {true}.
366366
- Return {false}.

0 commit comments

Comments
 (0)