Skip to content

Commit

Permalink
Lint: Improve logic for validating algorithm steps. (webmachinelearni…
Browse files Browse the repository at this point in the history
…ng#727)

* Lint: Improve logic for validating algorithm steps.

Previously, the test ensuring that algorithm steps end in '.' or ':'
looked at the Bikeshed source. This didn't handle word wrapping. While
we prefer not to word wrap, that shouldn't cause this test to fail.

Make the test analyse the DOM instead.

* Fix some unrelated lint failures introduced in f08f9f7
  • Loading branch information
inexorabletash authored Jul 17, 2024
1 parent f08f9f7 commit ac83a20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -6066,7 +6066,7 @@ partial interface MLGraphBuilder {
The <dfn method for=MLGraphBuilder>where(|condition|, |trueValue|, |falseValue|)</dfn> method steps are:
</summary>
1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |condition|, |input|, and |other| returns false, then [=exception/throw=] a {{TypeError}}.
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |condition|, |trueValue|, and |falseValue| returns false, then [=exception/throw=] a {{TypeError}}.
1. If |condition|'s [=MLOperand/dataType=] is not equal to {{MLOperandDataType/"uint8"}}, then [=exception/throw=] a {{TypeError}}.
1. If |trueValue|'s [=MLOperand/dataType=] is not equal to |falseValue|'s [=MLOperand/dataType=], then [=exception/throw=] a {{TypeError}}.
1. Let |descriptor| be a new {{MLOperandDescriptor}}.
Expand Down
17 changes: 7 additions & 10 deletions tools/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,15 @@ for (const pre of root.querySelectorAll('pre.highlight:not(.idl)')) {
}

// Ensure algorithm steps end in '.' or ':'.
for (const match of source.matchAll(/^ *\d+\. .*$/mg)) {
let str = match[0].trim();
for (const p of root.querySelectorAll('.algorithm li > p')) {
let str = p.innerText;

// Strip asterisks from things like "1. *Make graph connections.*"
const match2 = str.match(/^(\d+\. )\*(.*)\*$/);
if (match2) {
str = match2[1] + match2[2];
}
// Strip "[Issue #123]" suffix.
str = str.replace(/\s+\[Issue #\d+\]/, '');

const match3 = str.match(/[^.:]$/);
if (match3) {
error(`Algorithm steps should end with '.' or ':': ${format(match3)}`);
const match = str.match(/[^.:]$/);
if (match) {
error(`Algorithm steps should end with '.' or ':': ${format(match)}`);
}
}

Expand Down

0 comments on commit ac83a20

Please sign in to comment.