Skip to content

Commit 77294ea

Browse files
committed
experiment: try to get line number of errors
1 parent d8e57af commit 77294ea

File tree

4 files changed

+148
-8
lines changed

4 files changed

+148
-8
lines changed

examples/basic.commented.html

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<!DOCTYPE html><!-- respec-sourcemap#examples/basic.html:1 -->
2+
<html><!-- respec-sourcemap#examples/basic.html:2 -->
3+
<head><!-- respec-sourcemap#examples/basic.html:3 -->
4+
<meta charset='utf-8'><!-- respec-sourcemap#examples/basic.html:4 -->
5+
<title>
6+
Replace me with a real title
7+
</title><!-- respec-sourcemap#examples/basic.html:7 -->
8+
<script src='../builds/respec-w3c.js' async class='remove'></script><!-- respec-sourcemap#examples/basic.html:8 -->
9+
<script class='remove'>
10+
var respecConfig = {
11+
specStatus: "ED",
12+
subtitle: "Subtitle",
13+
shortName: "shortname-api",
14+
editors: [{
15+
name: "Your Name",
16+
url: "https://your-site.com",
17+
}],
18+
github: "https://github.com/w3c/some-API/",
19+
lint: { "check-punctuation": true },
20+
implementationReportURI: "https://w3c.github.io/test-results/some-API",
21+
};
22+
</script><!-- respec-sourcemap#examples/basic.html:22 -->
23+
</head><!-- respec-sourcemap#examples/basic.html:23 -->
24+
<body><!-- respec-sourcemap#examples/basic.html:24 -->
25+
<section id='abstract'><!-- respec-sourcemap#examples/basic.html:25 -->
26+
<p><!-- respec-sourcemap#examples/basic.html:26 -->
27+
This is required.<!-- respec-sourcemap#examples/basic.html:27 -->
28+
</p><!-- respec-sourcemap#examples/basic.html:28 -->
29+
</section><!-- respec-sourcemap#examples/basic.html:29 -->
30+
<section id='sotd'><!-- respec-sourcemap#examples/basic.html:30 -->
31+
<p><!-- respec-sourcemap#examples/basic.html:31 -->
32+
This is required.<!-- respec-sourcemap#examples/basic.html:32 -->
33+
</p><!-- respec-sourcemap#examples/basic.html:33 -->
34+
</section><!-- respec-sourcemap#examples/basic.html:34 -->
35+
<section class="introductory" id="overview"><!-- respec-sourcemap#examples/basic.html:35 -->
36+
<h2><!-- respec-sourcemap#examples/basic.html:36 -->
37+
Overview<!-- respec-sourcemap#examples/basic.html:37 -->
38+
</h2><!-- respec-sourcemap#examples/basic.html:38 -->
39+
<p><!-- respec-sourcemap#examples/basic.html:39 -->
40+
This section has a CSS class "<code>introductory</code>", which means<!-- respec-sourcemap#examples/basic.html:40 -->
41+
it will not appear in the <abbr title="Table of Contents">TOC</abbr>.<!-- respec-sourcemap#examples/basic.html:41 -->
42+
Example Link to Section.<!-- respec-sourcemap#examples/basic.html:42 -->
43+
</p><!-- respec-sourcemap#examples/basic.html:43 -->
44+
</section><!-- respec-sourcemap#examples/basic.html:44 -->
45+
<section class="informative" id="intro"><!-- respec-sourcemap#examples/basic.html:45 -->
46+
<h2><!-- respec-sourcemap#examples/basic.html:46 -->
47+
Introduction<!-- respec-sourcemap#examples/basic.html:47 -->
48+
</h2><!-- respec-sourcemap#examples/basic.html:48 -->
49+
<p><!-- respec-sourcemap#examples/basic.html:49 -->
50+
This section has a CSS class "<code>informative</code>", so it is<!-- respec-sourcemap#examples/basic.html:50 -->
51+
listed in the TOC. ReSpec will list this reference as non-normative<!-- respec-sourcemap#examples/basic.html:51 -->
52+
since this is an informative section [[DOM]].<!-- respec-sourcemap#examples/basic.html:52 -->
53+
</p><!-- respec-sourcemap#examples/basic.html:53 -->
54+
</section><!-- respec-sourcemap#examples/basic.html:54 -->
55+
<section data-dfn-for="Foo"><!-- respec-sourcemap#examples/basic.html:55 -->
56+
<h2><!-- respec-sourcemap#examples/basic.html:56 -->
57+
<dfn>Foo</dfn> interface<!-- respec-sourcemap#examples/basic.html:57 -->
58+
</h2><!-- respec-sourcemap#examples/basic.html:58 -->
59+
<pre class="idl"><!-- respec-sourcemap#examples/basic.html:59 -->
60+
[Exposed Window]<!-- respec-sourcemap#examples/basic.html:60 -->
61+
interface Foo {<!-- respec-sourcemap#examples/basic.html:61 -->
62+
constructor();<!-- respec-sourcemap#examples/basic.html:62 -->
63+
attribute DOMString bar;<!-- respec-sourcemap#examples/basic.html:63 -->
64+
undefined doTheFoo();<!-- respec-sourcemap#examples/basic.html:64 -->
65+
};<!-- respec-sourcemap#examples/basic.html:65 -->
66+
</pre><!-- respec-sourcemap#examples/basic.html:66 -->
67+
<p><!-- respec-sourcemap#examples/basic.html:67 -->
68+
The <a>Foo</a> interface is nice. Lets you do stuff.<!-- respec-sourcemap#examples/basic.html:68 -->
69+
</p><!-- respec-sourcemap#examples/basic.html:69 -->
70+
<p><!-- respec-sourcemap#examples/basic.html:70 -->
71+
The <dfn>Foo.constructor()</dfn> creates a Foo instance<!-- respec-sourcemap#examples/basic.html:71 -->
72+
</p><!-- respec-sourcemap#examples/basic.html:72 -->
73+
<p><!-- respec-sourcemap#examples/basic.html:73 -->
74+
The <dfn>bar</dfn> attribute, returns 🍺.<!-- respec-sourcemap#examples/basic.html:74 -->
75+
</p><!-- respec-sourcemap#examples/basic.html:75 -->
76+
<p><!-- respec-sourcemap#examples/basic.html:76 -->
77+
The <dfn>doTheFoo()</dfn> method, returns nothing<!-- respec-sourcemap#examples/basic.html:77 -->
78+
</p><!-- respec-sourcemap#examples/basic.html:78 -->
79+
<p><!-- respec-sourcemap#examples/basic.html:79 -->
80+
ReSpec will list this reference as normative [[ECMASCRIPT]].<!-- respec-sourcemap#examples/basic.html:80 -->
81+
</p><!-- respec-sourcemap#examples/basic.html:81 -->
82+
<p><!-- respec-sourcemap#examples/basic.html:82 -->
83+
This is an example of a non-normative reference in a normative section<!-- respec-sourcemap#examples/basic.html:83 -->
84+
[[?HTML]]<!-- respec-sourcemap#examples/basic.html:84 -->
85+
</p><!-- respec-sourcemap#examples/basic.html:85 -->
86+
<pre class="js example" title="Usage example"><!-- respec-sourcemap#examples/basic.html:86 -->
87+
const foo = new Foo();<!-- respec-sourcemap#examples/basic.html:87 -->
88+
if (foo.bar === "my bar") {<!-- respec-sourcemap#examples/basic.html:88 -->
89+
foo.doTheBar();<!-- respec-sourcemap#examples/basic.html:89 -->
90+
}<!-- respec-sourcemap#examples/basic.html:90 -->
91+
</pre><!-- respec-sourcemap#examples/basic.html:91 -->
92+
</section><!-- respec-sourcemap#examples/basic.html:92 -->
93+
<section id="logo"><!-- respec-sourcemap#examples/basic.html:93 -->
94+
<h2><!-- respec-sourcemap#examples/basic.html:94 -->
95+
Figure<!-- respec-sourcemap#examples/basic.html:95 -->
96+
</h2><!-- respec-sourcemap#examples/basic.html:96 -->
97+
<figure id="figure"><!-- respec-sourcemap#examples/basic.html:97 -->
98+
<img src="figure.svg" alt="W3C Logo"><!-- respec-sourcemap#examples/basic.html:98 -->
99+
<figcaption><!-- respec-sourcemap#examples/basic.html:99 -->
100+
The W3C logo<!-- respec-sourcemap#examples/basic.html:100 -->
101+
</figcaption><!-- respec-sourcemap#examples/basic.html:101 -->
102+
</figure><!-- respec-sourcemap#examples/basic.html:102 -->
103+
<p><!-- respec-sourcemap#examples/basic.html:103 -->
104+
Link to <a href="#figure"></a>.<!-- respec-sourcemap#examples/basic.html:104 -->
105+
</p><!-- respec-sourcemap#examples/basic.html:105 -->
106+
</section><!-- respec-sourcemap#examples/basic.html:106 -->
107+
<section id="idl-index" class="appendix"><!-- respec-sourcemap#examples/basic.html:107 -->
108+
<h2><!-- respec-sourcemap#examples/basic.html:108 -->
109+
IDL Index<!-- respec-sourcemap#examples/basic.html:109 -->
110+
</h2><!-- respec-sourcemap#examples/basic.html:110 -->
111+
<p><!-- respec-sourcemap#examples/basic.html:111 -->
112+
All the Web IDL in this specification is collected in this section.<!-- respec-sourcemap#examples/basic.html:112 -->
113+
</p><!-- respec-sourcemap#examples/basic.html:113 -->
114+
</section><!-- respec-sourcemap#examples/basic.html:114 -->
115+
<section id="tof" class="informative appendix"></section><!-- respec-sourcemap#examples/basic.html:115 -->
116+
</body><!-- respec-sourcemap#examples/basic.html:116 -->
117+
</html><!-- respec-sourcemap#examples/basic.html:117 -->

examples/basic.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>
66
Replace me with a real title
77
</title>
8-
<script src='../profiles/w3c.js' async class='remove'></script>
8+
<script src='../builds/respec-w3c.js' async class='remove'></script>
99
<script class='remove'>
1010
var respecConfig = {
1111
specStatus: "ED",
@@ -16,7 +16,7 @@
1616
url: "https://your-site.com",
1717
}],
1818
github: "https://github.com/w3c/some-API/",
19-
testSuiteURI: "https://w3c-test.org/some-API/",
19+
lint: { "check-punctuation": true },
2020
implementationReportURI: "https://w3c.github.io/test-results/some-API",
2121
};
2222
</script>
@@ -39,7 +39,7 @@ <h2>
3939
<p>
4040
This section has a CSS class "<code>introductory</code>", which means
4141
it will not appear in the <abbr title="Table of Contents">TOC</abbr>.
42-
Example Link to Section <a href="#logo"></a>.
42+
Example Link to Section.
4343
</p>
4444
</section>
4545
<section class="informative" id="intro">
@@ -57,7 +57,7 @@ <h2>
5757
<dfn>Foo</dfn> interface
5858
</h2>
5959
<pre class="idl">
60-
[Exposed=Window]
60+
[Exposed Window]
6161
interface Foo {
6262
constructor();
6363
attribute DOMString bar;
@@ -68,13 +68,13 @@ <h2>
6868
The <a>Foo</a> interface is nice. Lets you do stuff.
6969
</p>
7070
<p>
71-
The <dfn>Foo.constructor()</dfn> creates a Foo instance.
71+
The <dfn>Foo.constructor()</dfn> creates a Foo instance
7272
</p>
7373
<p>
7474
The <dfn>bar</dfn> attribute, returns 🍺.
7575
</p>
7676
<p>
77-
The <dfn>doTheFoo()</dfn> method, returns nothing.
77+
The <dfn>doTheFoo()</dfn> method, returns nothing
7878
</p>
7979
<p>
8080
ReSpec will list this reference as normative [[ECMASCRIPT]].
@@ -101,7 +101,7 @@ <h2>
101101
</figcaption>
102102
</figure>
103103
<p>
104-
Link to <a href="#figure"></a>
104+
Link to <a href="#figure"></a>.
105105
</p>
106106
</section>
107107
<section id="idl-index" class="appendix">

tools/respec2html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Logger {
8686
const paddedTitle = `${title}:`.padStart(padWidth);
8787
console.error(" ", colors.bold(paddedTitle), this._formatMarkdown(value));
8888
};
89-
print("Count", rsError.elements && String(rsError.elements.length));
89+
print("Line", rsError.location && rsError.location.join(", "));
9090
print("Plugin", rsError.plugin);
9191
print("Hint", rsError.hint);
9292
}

tools/respecDocWriter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ function handleConsoleMessages(page, onError, onWarning) {
290290
return JSON.stringify({ message: String(obj) });
291291
} else {
292292
// Ideally: `obj instanceof RsError` and `RsError instanceof Error`.
293+
if (obj.elements) {
294+
/** @type {HTMLElement[]} */
295+
const elems = obj.elements;
296+
const regex = /respec-sourcemap#(.+)/;
297+
/** @param {Node} [node] */
298+
const hasComment = node => {
299+
if (!node || node.nodeType !== Node.COMMENT_NODE) return false;
300+
return regex.test(node.textContent);
301+
};
302+
/** @param {Node} node */
303+
const match = node => node.textContent.match(regex)[1].trim();
304+
const location = elems.map(el => {
305+
if (hasComment(el.firstChild)) {
306+
return match(el.firstChild);
307+
}
308+
if (hasComment(el.nextSibling)) {
309+
return match(el.nextSibling);
310+
}
311+
return 0;
312+
});
313+
const result = { ...JSON.parse(JSON.stringify(obj)), location };
314+
return JSON.stringify(result);
315+
}
293316
return JSON.stringify(obj);
294317
}
295318
}, handle);

0 commit comments

Comments
 (0)