Skip to content

Ensure algorithm steps are always wrapped in braces #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/algorithm-format-check.mjs
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@ import { readFile, readdir } from "node:fs/promises";

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

/** @see {@link https://spec-md.com/#sec-Value-Literals} */
const valueLiteralsRegexp = /\{((?:[^{}]|(?:\{[^{}]*\}))+)\}/g;

process.exitCode = 0;
const filenames = await readdir(SPEC_DIR);
for (const filename of filenames) {
@@ -72,6 +75,33 @@ for (const filename of filenames) {
console.log();
process.exitCode = 1;
}

const stepWithoutValueLiterals = step.replace(
valueLiteralsRegexp,
""
);
if (stepWithoutValueLiterals.match(/\b[A-Z][A-Za-z0-9]+\(/)) {
console.log(
`Bad formatting of '${algorithmName}' step (algorithm call should be wrapped in braces: \`{MyAlgorithm(a, b, c)}\`) in '${filename}':`
);
console.dir(step);
console.log();
process.exitCode = 1;
}

const valueLiterals = step.matchAll(valueLiteralsRegexp, "");
for (const lit of valueLiterals) {
const inner = lit[1];
if (inner.includes("{")) {
console.log(
`Bad formatting of '${algorithmName}' step (algorithm call should not contain braces: \`${lit}\`) in '${filename}':`
);
console.dir(step);
console.log();
process.exitCode = 1;
}
}

const trimmedInnerLine = step.replace(/\s+/g, " ");
if (
trimmedInnerLine.match(
4 changes: 2 additions & 2 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
@@ -351,7 +351,7 @@ IsInputType(type):

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

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