Skip to content

Commit

Permalink
Use the full .loc for more line-number things. #3013
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Jan 23, 2025
1 parent 980fafc commit b87965b
Show file tree
Hide file tree
Showing 314 changed files with 10,036 additions and 8,341 deletions.
6 changes: 3 additions & 3 deletions bikeshed/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
MetadataT: t.TypeAlias = t.Mapping[str, t.Sequence[MetadataValueT]]


def boilerplateFromHtml(doc: t.SpecT, htmlString: str, filename: str) -> t.NodesT:
htmlString = h.parseText(htmlString, h.ParseConfig.fromSpec(doc, context=filename))
def boilerplateFromHtml(doc: t.SpecT, htmlString: str, context: str) -> t.NodesT:
htmlString = h.parseText(htmlString, h.ParseConfig.fromSpec(doc, context=context))
bp = h.E.div({}, h.parseHTML(htmlString))
conditional.processConditionals(doc, bp)
return h.childNodes(bp, clear=True)
Expand All @@ -29,7 +29,7 @@ def loadBoilerplate(doc: t.SpecT, filename: str, bpname: str | None = None) -> N
if bpname is None:
bpname = filename
html = retrieve.retrieveBoilerplateFile(doc, filename)
el = boilerplateFromHtml(doc, html, filename)
el = boilerplateFromHtml(doc, html, context=f"{filename} boilerplate")
fillWith(bpname, el, doc=doc)


Expand Down
10 changes: 5 additions & 5 deletions bikeshed/h/parser/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def fromStream(
)

def __str__(self) -> str:
s = f"<{self.tag} bs-line-number={self.line}"
s = f'<{self.tag} bs-line-number="{escapeAttr(self.loc)}"'
if self.context:
s += f' bs-parse-context="{escapeAttr(self.context)}"'
for k, v in sorted(self.attrs.items()):
Expand Down Expand Up @@ -205,7 +205,7 @@ def fromStartTag(cls, tag: StartTag) -> t.Self:
)

def __str__(self) -> str:
s = f"<{self.tag} bs-line-number={self.line}"
s = f'<{self.tag} bs-line-number="{escapeAttr(self.loc)}"'
if self.context:
s += f' bs-parse-context="{escapeAttr(self.context)}"'
for k, v in sorted(self.attrs.items()):
Expand Down Expand Up @@ -362,15 +362,15 @@ def update(self, node: ParserNode) -> None:
for entry in reversed(self.tags):
if entry.startTag.tag == node.tag:
m.die(
f"Saw an end tag {node}, but there were unclosed elements remaining before the nearest matching start tag (on line {entry.startTag.line}).\nOpen tags: {', '.join(self.printOpenTags())}",
lineNum=node.line,
f"Saw an end tag {node}, but there were unclosed elements remaining before the nearest matching start tag (at {entry.startTag.loc}).\nOpen tags: {', '.join(self.printOpenTags())}",
lineNum=node.loc,
)
break
else:
openTagsMsg = f"\nOpen tags: {', '.join(self.printOpenTags())}" if self.tags else ""
m.die(
f"Saw an end tag {node}, but there's no open element corresponding to it.{openTagsMsg}",
lineNum=node.line,
lineNum=node.loc,
)
elif isinstance(node, (SelfClosedTag, RawElement)):
self.autoCloseStart(node.tag)
Expand Down
2 changes: 1 addition & 1 deletion bikeshed/issuelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def printIssueList(infilename: str | None = None, outfilename: str | None = None
infile = open(infilename + suffix, encoding="utf-8") # noqa: SIM115
infilename += suffix
break
except Exception: # noqa: S110
except Exception:
pass
else:
m.die("Couldn't read from the infile(s)")
Expand Down
18 changes: 17 additions & 1 deletion bikeshed/unsortedJunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,13 +1402,29 @@ def addNoteHeaders(doc: t.SpecT) -> None:
preText = _t("EXAMPLE: ")
else:
preText = ""
lineNum = int(el.get("bs-line-number", "1"))
lineNum = lineNumberFromBsLineNumber(el.get("bs-line-number"))
parseConfig = h.ParseConfig.fromSpec(doc=doc, context="heading='' attribute")
parsedHeading = h.parseHTML(h.parseText(el.get("heading", ""), parseConfig, startLine=lineNum))
h.prependChild(el, h.E.div({"class": "marker"}, preText, *parsedHeading))
h.removeAttr(el, "heading")


def lineNumberFromBsLineNumber(value: str | None) -> int:
if value is None:
return 1
try:
return int(value)
except:

Check warning on line 1417 in bikeshed/unsortedJunk.py

View workflow job for this annotation

GitHub Actions / lint

No exception type(s) specified (bare-except)
pass
try:
# If it's a 'loc' value: line:col + maybe other context
num, _, _ = value.partition(":")
return int(num)
except:

Check warning on line 1423 in bikeshed/unsortedJunk.py

View workflow job for this annotation

GitHub Actions / lint

No exception type(s) specified (bare-except)
pass
return 1


def locateFillContainers(doc: t.SpecT) -> t.FillContainersT:
fillContainers = defaultdict(list)
for el in h.findAll("[data-fill-with]", doc):
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ lint.ignore = [
"ANN401",
# assert is for type annotations
"S101",
# Perfectly fine pattern as used.
"S110",
# Not doing any secure crypto, just hashing
"S324",
# these are all dumb
Expand Down
18 changes: 9 additions & 9 deletions tests/algorithm001.console.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
LINE 29: Algorithm container has no name, and there is no <dfn> to infer one from. Please set the algorithm='name here' attribute.
LINE 33: Algorithm container has no name, and there are too many <dfn>s to choose which to infer a name from. Please set the algorithm='name here' attribute.
LINE 26: The var 'foo' (in algorithm 'find more foo') is only used once.
LINE 29:1: Algorithm container has no name, and there is no <dfn> to infer one from. Please set the algorithm='name here' attribute.
LINE 33:1: Algorithm container has no name, and there are too many <dfn>s to choose which to infer a name from. Please set the algorithm='name here' attribute.
LINE 26:2: The var 'foo' (in algorithm 'find more foo') is only used once.
If this is not a typo, please add an ignore='' attribute to the <var>.
FATAL ERROR: Multiple declarations of the '' algorithm.
LINE 24: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="24" data-dfn-type="dfn" id="find-more-foo" data-lt="find more foo" data-noexport="by-default" class="dfn-paneled">find more foo</dfn>
LINE 34: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="34" data-dfn-type="dfn" id="find-even-more-foo" data-lt="find even more foo" data-noexport="by-default" class="dfn-paneled">find even more foo</dfn>
LINE 35: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="35" data-dfn-type="dfn" id="find-some-bar" data-lt="find some bar" data-noexport="by-default" class="dfn-paneled">find some bar</dfn>
LINE 24:2: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="24:2" data-dfn-type="dfn" id="find-more-foo" data-lt="find more foo" data-noexport="by-default" class="dfn-paneled">find more foo</dfn>
LINE 34:2: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="34:2" data-dfn-type="dfn" id="find-even-more-foo" data-lt="find even more foo" data-noexport="by-default" class="dfn-paneled">find even more foo</dfn>
LINE 35:11: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="35:11" data-dfn-type="dfn" id="find-some-bar" data-lt="find some bar" data-noexport="by-default" class="dfn-paneled">find some bar</dfn>
6 changes: 3 additions & 3 deletions tests/biblio001.console.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
LINE 68:32: [[...]] shorthand (opened on 68:1) was closed, but there were still open elements inside of it.
Open tags: [[...]] at 68:1, <i> at 68:22
LINE 68: Saw an end tag </a>, but there were unclosed elements remaining before the nearest matching start tag (on line 68).
LINE 68:32: Saw an end tag </a>, but there were unclosed elements remaining before the nearest matching start tag (at 68:1).
Open tags: <a> at 68:1, <i> at 68:22
LINE 79: Saw an end tag </span>, but there were unclosed elements remaining before the nearest matching start tag (on line 79).
LINE 79:48: Saw an end tag </span>, but there were unclosed elements remaining before the nearest matching start tag (at 79:1).
Open tags: <span> at 79:1, [[...]] at 79:7
LINE 79: Saw an end tag </span>, but there were unclosed elements remaining before the nearest matching start tag (on line 79).
LINE 79:48: Saw an end tag </span>, but there were unclosed elements remaining before the nearest matching start tag (at 79:1).
Open tags: <span> at 79:1, <a> at 79:7
6 changes: 3 additions & 3 deletions tests/biblio002.console.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LINE 1 of macro [ABSTRACT]: No 'property' refs found for 'inline'.
LINE 1:30 of macro [ABSTRACT] of macro [ABSTRACT]: No 'property' refs found for 'inline'.
'inline'
LINE 1 of macro [ABSTRACT]: No 'property' refs found for 'index'.
LINE 1:216 of macro [ABSTRACT] of macro [ABSTRACT]: No 'property' refs found for 'index'.
'index'
LINE 1 of macro [ABSTRACT]: No 'property' refs found for 'direct'.
LINE 1:400 of macro [ABSTRACT] of macro [ABSTRACT]: No 'property' refs found for 'direct'.
'direct'
8 changes: 4 additions & 4 deletions tests/caniuse001.console.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LINE 15: The var 'where' (in global scope) is only used once.
LINE 15:64: The var 'where' (in global scope) is only used once.
If this is not a typo, please add an ignore='' attribute to the <var>.
LINE 15: The var 'element' (in global scope) is only used once.
LINE 15:82: The var 'element' (in global scope) is only used once.
If this is not a typo, please add an ignore='' attribute to the <var>.
LINE 15: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="15" data-dfn-type="dfn" id="insertadjacentelement-where-element" data-lt="insertAdjacentElement(where, element)" data-noexport="by-default" class="dfn-paneled caniuse-paneled"><code bs-line-number="15">insertAdjacentElement(<var bs-line-number="15">where</var>, <var bs-line-number="15">element</var>)</code></dfn>
LINE 15:5: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="15:5" data-dfn-type="dfn" id="insertadjacentelement-where-element" data-lt="insertAdjacentElement(where, element)" data-noexport="by-default" class="dfn-paneled caniuse-paneled"><code bs-line-number="15:36">insertAdjacentElement(<var bs-line-number="15:64">where</var>, <var bs-line-number="15:82">element</var>)</code></dfn>
2 changes: 1 addition & 1 deletion tests/conditional002.console.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LINE 14: <if-wrapper> elements must have an include-if and/or exclude-if attribute.
LINE 14:1: <if-wrapper> elements must have an include-if and/or exclude-if attribute.
2 changes: 1 addition & 1 deletion tests/css-production-range001.console.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
LINE 19:1: Shorthand <<integer [∞, 1]>> has a range whose start is equal or greater than its end.
LINE 35: No 'type' refs found for '<something>'.
LINE 35:1: No 'type' refs found for '<something>'.
<<something [0, 20long-unit]>>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LINE 41: Multiple possible 'key' dfn refs.
LINE 41:52: Multiple possible 'key' dfn refs.
Arbitrarily chose https://infra.spec.whatwg.org/#map-key
To auto-select one of the following refs, insert one of these lines into a <pre class=link-defaults> block:
spec:infra; type:dfn; text:key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
LINE 328: Saw an end tag </p>, but there's no open element corresponding to it.
LINE 328:64: Saw an end tag </p>, but there's no open element corresponding to it.
Open tags: <section> at 303:1, <aside> at 317:1
LINE 121: No 'idl' refs found for 'createInternals()'.
LINE 121:13: No 'idl' refs found for 'createInternals()'.
{{createInternals()}}
LINE 219: Couldn't find section '#custom-element-definition' in spec 'html':
LINE 219:41: Couldn't find section '#custom-element-definition' in spec 'html':
[[HTML#custom-element-definition]]
LINE 220: Couldn't find section '#element-definition' in spec 'html':
LINE 220:31: Couldn't find section '#element-definition' in spec 'html':
[[HTML#element-definition]]
8 changes: 4 additions & 4 deletions tests/github/WICG/aom/spec/input-events.console.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LINT: Your document appears to use tabs to indent, but line 162 starts with spac
LINT: Your document appears to use tabs to indent, but line 164 starts with spaces.
LINT: Your document appears to use tabs to indent, but line 165 starts with spaces.
LINE 4:60 of macro [ABSTRACT]: Found unmatched text macro [UI-EVENTS]. Correct the macro, or escape it by replacing the opening [ with &#91;
LINE 77: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="77" data-dfn-for="InputEvent" data-dfn-type="dfn" id="inputevent-inputtype" data-lt="inputType" data-noexport="by-default" class="dfn-paneled">inputType</dfn>
LINE 85: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="85" data-dfn-type="dfn" id="input-event-types" data-lt="Input Event Types" data-noexport="by-default" class="dfn-paneled">Input Event Types</dfn>
LINE 77:5: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="77:5" data-dfn-for="InputEvent" data-dfn-type="dfn" id="inputevent-inputtype" data-lt="inputType" data-noexport="by-default" class="dfn-paneled">inputType</dfn>
LINE 85:33: Unexported dfn that's not referenced locally - did you mean to export it?
<dfn bs-line-number="85:33" data-dfn-type="dfn" id="input-event-types" data-lt="Input Event Types" data-noexport="by-default" class="dfn-paneled">Input Event Types</dfn>
60 changes: 31 additions & 29 deletions tests/github/WICG/app-history/spec.console.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
LINE 241: No 'dfn' refs found for 'still on its initial about:blank document'.
<a bs-line-number="241" data-link-spec="HTML" data-link-type="dfn" data-lt="still on its initial about:blank Document">still on its initial <code bs-line-number="241" bs-autolink-syntax="`about:blank`" bs-opaque="">about:blank</code> <code bs-line-number="241" bs-autolink-syntax="`Document`" bs-opaque="">Document</code></a>
LINE 430: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="430" data-link-spec="HTML" data-link-type="dfn" data-lt="Traverse the history">Traverse the history</a>
LINE 437: No 'dfn' refs found for 'entries' with for='['FormData']'.
LINE 241:30: No 'dfn' refs found for 'still on its initial about:blank document'.
<a bs-line-number="241:30" data-link-spec="HTML" data-link-type="dfn" data-lt="still on its initial about:blank Document">still on its initial <code bs-line-number="241:66" bs-autolink-syntax="`about:blank`" bs-opaque="">about:blank</code> <code bs-line-number="241:80" bs-autolink-syntax="`Document`" bs-opaque="">Document</code></a>
LINE 430:8: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="430:8" data-link-spec="HTML" data-link-type="dfn" data-lt="Traverse the history">Traverse the history</a>
LINE 437:487: No 'dfn' refs found for 'entries' with for='['FormData']'.
[=FormData/entries=]
LINE 509: Multiple possible 'user agent' dfn refs.
LINE 509:10: Multiple possible 'user agent' dfn refs.
Arbitrarily chose https://infra.spec.whatwg.org/#user-agent
To auto-select one of the following refs, insert one of these lines into a <pre class=link-defaults> block:
spec:infra; type:dfn; text:user agent
Expand All @@ -13,7 +13,7 @@ spec:css2; type:dfn; for:/; text:user agent
https://www.w3.org/TR/CSS21/conform.html#ua
https://www.w3.org/TR/CSS21/conform.html#user-agent
[=user agent=]
LINE 517: Multiple possible 'user agent' dfn refs.
LINE 517:10: Multiple possible 'user agent' dfn refs.
Arbitrarily chose https://infra.spec.whatwg.org/#user-agent
To auto-select one of the following refs, insert one of these lines into a <pre class=link-defaults> block:
spec:infra; type:dfn; text:user agent
Expand All @@ -22,36 +22,38 @@ spec:css2; type:dfn; for:/; text:user agent
https://www.w3.org/TR/CSS21/conform.html#ua
https://www.w3.org/TR/CSS21/conform.html#user-agent
[=user agent=]
LINE 608: No 'dfn' refs found for 'entries' with for='['FormData']'.
LINE 608:74: No 'dfn' refs found for 'entries' with for='['FormData']'.
[=FormData/entries=]
LINE 688: Multiple possible 'submit button' dfn refs.
LINE 688:15: Multiple possible 'submit button' dfn refs.
Arbitrarily chose https://html.spec.whatwg.org/multipage/form-elements.html#attr-button-type-submit-state
The following refs show up multiple times in their spec, in a way that Bikeshed can't distinguish between. Either create a manual link, or ask the spec maintainer to add disambiguating attributes (usually a for='' attribute to all of them).
spec:html; type:dfn; for:/; text:submit button
https://html.spec.whatwg.org/multipage/form-elements.html#attr-button-type-submit-state
https://html.spec.whatwg.org/multipage/forms.html#concept-submit-button
<a bs-line-number="688" data-link-spec="HTML" data-link-type="dfn" data-lt="submit button">submit button</a>
LINE 720: No 'dfn' refs found for 'active document' with for='None'.
<a bs-line-number="688:15" data-link-spec="HTML" data-link-type="dfn" data-lt="submit button">submit button</a>
LINE 720:43: No 'dfn' refs found for 'active document' with for='None'.
[=active document=]
LINE 720: No 'dfn' refs found for 'source browsing context'.
LINE 720:124: No 'dfn' refs found for 'source browsing context'.
[=source browsing context=]
LINE 721: No 'dfn' refs found for 'create a new browsing context' with spec 'html'.
<a bs-line-number="721" data-link-spec="HTML" data-lt="create a new browsing context" data-link-type="dfn">created</a>
LINE 725: No 'dfn' refs found for 'active window' with for='['browsing context']'.
LINE 720:154: No 'dfn' refs found for 'active document' with for='None'.
[=active document=]
LINE 721:188: No 'dfn' refs found for 'create a new browsing context' with spec 'html'.
<a bs-line-number="721:188" data-link-spec="HTML" data-lt="create a new browsing context" data-link-type="dfn">created</a>
LINE 725:66: No 'dfn' refs found for 'active window' with for='['browsing context']'.
[=browsing context/active window=]
LINE 736: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="736" data-link-spec="HTML" data-link-type="dfn" data-lt="traverse the history">traverse the history</a>
LINE 738: No 'dfn' refs found for 'active window' with for='['browsing context']'.
LINE 736:151: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="736:151" data-link-spec="HTML" data-link-type="dfn" data-lt="traverse the history">traverse the history</a>
LINE 738:73: No 'dfn' refs found for 'active window' with for='['browsing context']'.
[=browsing context/active window=]
LINE 739: No 'dfn' refs found for 'active document' with for='None'.
LINE 739:85: No 'dfn' refs found for 'active document' with for='None'.
[=active document=]
LINE 764: No 'dfn' refs found for 'update the session history with the new page'.
<a bs-line-number="764" data-link-spec="HTML" data-link-type="dfn" data-lt="update the session history with the new page">update the session history with the new page</a>
LINE 771: No 'dfn' refs found for 'update the session history with the new page'.
<a bs-line-number="771" data-link-spec="HTML" data-link-type="dfn" data-lt="update the session history with the new page">update the session history with the new page</a>
LINE 777: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="777" data-link-spec="HTML" data-link-type="dfn" data-lt="traverse the history">traverse the history</a>
LINE 782: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="782" data-link-spec="HTML" data-link-type="dfn" data-lt="traverse the history">traverse the history</a>
LINE 793: No 'dfn' refs found for 'creating a new browsing context' with spec 'html'.
<a bs-line-number="793" data-link-spec="HTML" data-link-type="dfn" data-lt="creating a new browsing context">creating a new browsing context</a>
LINE 764:14: No 'dfn' refs found for 'update the session history with the new page'.
<a bs-line-number="764:14" data-link-spec="HTML" data-link-type="dfn" data-lt="update the session history with the new page">update the session history with the new page</a>
LINE 771:12: No 'dfn' refs found for 'update the session history with the new page'.
<a bs-line-number="771:12" data-link-spec="HTML" data-link-type="dfn" data-lt="update the session history with the new page">update the session history with the new page</a>
LINE 777:24: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="777:24" data-link-spec="HTML" data-link-type="dfn" data-lt="traverse the history">traverse the history</a>
LINE 782:14: No 'dfn' refs found for 'traverse the history'.
<a bs-line-number="782:14" data-link-spec="HTML" data-link-type="dfn" data-lt="traverse the history">traverse the history</a>
LINE 793:76: No 'dfn' refs found for 'creating a new browsing context' with spec 'html'.
<a bs-line-number="793:76" data-link-spec="HTML" data-link-type="dfn" data-lt="creating a new browsing context">creating a new browsing context</a>
Loading

0 comments on commit b87965b

Please sign in to comment.