Skip to content

Commit 241828e

Browse files
committed
Update @types/hast, utilities
1 parent de5dbc2 commit 241828e

File tree

63 files changed

+579
-578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+579
-578
lines changed

lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ export function fromHtml(value, options) {
133133
message.ruleId = code
134134
message.fatal = fatalities[level]
135135
message.note = format(info.description)
136-
message.url = 'url' in info && info.url === false ? null : base + code
136+
message.url =
137+
'url' in info && info.url === false ? undefined : base + code
137138
// @ts-expect-error: `onerror` is not passed if `warn` is not set.
138139
warn(message)
139140
}

package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,31 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"@types/hast": "^2.0.0",
37-
"hast-util-from-parse5": "^7.0.0",
36+
"@types/hast": "^3.0.0",
37+
"hast-util-from-parse5": "^8.0.0",
3838
"parse5": "^7.0.0",
39-
"vfile": "^5.0.0",
40-
"vfile-message": "^3.0.0"
39+
"vfile": "^6.0.0",
40+
"vfile-message": "^4.0.0"
4141
},
4242
"devDependencies": {
43+
"@types/mdast": "^4.0.0",
4344
"@types/node": "^20.0.0",
4445
"c8": "^8.0.0",
45-
"mdast-zone": "^5.0.0",
46-
"prettier": "^2.0.0",
46+
"mdast-zone": "^6.0.0",
47+
"prettier": "^3.0.0",
4748
"remark-cli": "^11.0.0",
4849
"remark-preset-wooorm": "^9.0.0",
50+
"to-vfile": "^8.0.0",
4951
"type-coverage": "^2.0.0",
5052
"type-fest": "^4.0.0",
5153
"typescript": "^5.0.0",
52-
"unist-builder": "^3.0.0",
54+
"unist-builder": "^4.0.0",
5355
"xo": "^0.55.0"
5456
},
5557
"scripts": {
5658
"prepack": "npm run build && npm run format",
5759
"build": "tsc --build --clean && tsc --build && type-coverage",
58-
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
60+
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
5961
"test-api": "node --conditions development test/index.js",
6062
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6163
"test": "npm run build && npm run format && npm run test-coverage"

script/parse-error.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ const ignoreFixture = {
2626
surrogateInInputStream: true
2727
}
2828

29-
/** @type {import('unified').Plugin<Array<void>, Root>} */
29+
/** @type {import('unified').Plugin<[], Root>} */
3030
export default function remarkParseErrors() {
31-
return (tree) => {
31+
/**
32+
* @param {Root} tree
33+
*/
34+
// @ts-expect-error: remove when `unified` is updated.
35+
return function (tree) {
3236
zone(tree, 'parse-error', (start, _, end) => {
3337
/** @type {Array<ListItem>} */
3438
const list = []

test/index.js

+71-57
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import assert from 'node:assert/strict'
66
import fs from 'node:fs/promises'
7+
import process from 'node:process'
78
import test from 'node:test'
89
import {VFile} from 'vfile'
910
import {toVFile, read} from 'to-vfile'
@@ -92,20 +93,19 @@ test('fromHtml', () => {
9293
JSON.parse(JSON.stringify(args)),
9394
[
9495
{
95-
name: '1:1-1:1',
96+
column: 1,
97+
fatal: false,
9698
message: 'Missing doctype before other content',
97-
reason: 'Missing doctype before other content',
9899
line: 1,
99-
column: 1,
100-
source: 'parse-error',
101-
ruleId: 'missing-doctype',
102-
position: {
100+
name: '1:1-1:1',
101+
place: {
103102
start: {line: 1, column: 1, offset: 0},
104103
end: {line: 1, column: 1, offset: 0}
105104
},
106-
fatal: false,
107-
note: 'Expected a `<!doctype html>` before anything else',
108-
url: null
105+
reason: 'Missing doctype before other content',
106+
ruleId: 'missing-doctype',
107+
source: 'parse-error',
108+
note: 'Expected a `<!doctype html>` before anything else'
109109
}
110110
],
111111
'should support `options.onerror`'
@@ -151,18 +151,18 @@ test('fromHtml', () => {
151151
JSON.parse(JSON.stringify(args)),
152152
[
153153
{
154-
name: '1:3-1:3',
154+
column: 3,
155+
fatal: false,
155156
message: 'Unexpected unknown named character reference',
156-
reason: 'Unexpected unknown named character reference',
157157
line: 1,
158-
column: 3,
159-
source: 'parse-error',
160-
ruleId: 'unknown-named-character-reference',
161-
position: {
158+
name: '1:3-1:3',
159+
place: {
162160
start: {line: 1, column: 3, offset: 2},
163161
end: {line: 1, column: 3, offset: 2}
164162
},
165-
fatal: false,
163+
reason: 'Unexpected unknown named character reference',
164+
ruleId: 'unknown-named-character-reference',
165+
source: 'parse-error',
166166
note: 'Unexpected character reference. Expected known named character references',
167167
url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unknown-named-character-reference'
168168
}
@@ -182,18 +182,18 @@ test('fromHtml', () => {
182182
JSON.parse(JSON.stringify(args)),
183183
[
184184
{
185-
name: '1:5-1:5',
185+
column: 5,
186+
fatal: false,
186187
message: 'Unexpected slash at end of closing tag',
187-
reason: 'Unexpected slash at end of closing tag',
188188
line: 1,
189-
column: 5,
190-
source: 'parse-error',
191-
ruleId: 'end-tag-with-trailing-solidus',
192-
position: {
189+
name: '1:5-1:5',
190+
place: {
193191
start: {line: 1, column: 5, offset: 4},
194192
end: {line: 1, column: 5, offset: 4}
195193
},
196-
fatal: false,
194+
reason: 'Unexpected slash at end of closing tag',
195+
ruleId: 'end-tag-with-trailing-solidus',
196+
source: 'parse-error',
197197
note: 'Unexpected `/`. Expected `>` instead',
198198
url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-end-tag-with-trailing-solidus'
199199
}
@@ -213,18 +213,18 @@ test('fromHtml', () => {
213213
JSON.parse(JSON.stringify(args)),
214214
[
215215
{
216-
name: '1:2-1:2',
216+
column: 2,
217+
fatal: false,
217218
message: 'Invalid first character in tag name',
218-
reason: 'Invalid first character in tag name',
219219
line: 1,
220-
column: 2,
221-
source: 'parse-error',
222-
ruleId: 'invalid-first-character-of-tag-name',
223-
position: {
220+
name: '1:2-1:2',
221+
place: {
224222
start: {line: 1, column: 2, offset: 1},
225223
end: {line: 1, column: 2, offset: 1}
226224
},
227-
fatal: false,
225+
reason: 'Invalid first character in tag name',
226+
ruleId: 'invalid-first-character-of-tag-name',
227+
source: 'parse-error',
228228
note: 'Unexpected `` ` ``. Expected an ASCII letter instead',
229229
url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-invalid-first-character-of-tag-name'
230230
}
@@ -244,18 +244,18 @@ test('fromHtml', () => {
244244
JSON.parse(JSON.stringify(args)),
245245
[
246246
{
247-
name: '1:1-1:1',
247+
column: 1,
248+
fatal: false,
248249
message: 'Unexpected NULL character',
249-
reason: 'Unexpected NULL character',
250250
line: 1,
251-
column: 1,
252-
source: 'parse-error',
253-
ruleId: 'unexpected-null-character',
254-
position: {
251+
name: '1:1-1:1',
252+
place: {
255253
start: {line: 1, column: 1, offset: 0},
256254
end: {line: 1, column: 1, offset: 0}
257255
},
258-
fatal: false,
256+
reason: 'Unexpected NULL character',
257+
ruleId: 'unexpected-null-character',
258+
source: 'parse-error',
259259
note: 'Unexpected code point `0x0`. Do not use NULL characters in HTML',
260260
url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-null-character'
261261
}
@@ -274,21 +274,20 @@ test('fromHtml', () => {
274274
JSON.parse(JSON.stringify(args)),
275275
[
276276
{
277-
name: 'example.html:1:1-1:1',
277+
column: 1,
278+
fatal: false,
278279
message: 'Missing doctype before other content',
279-
reason: 'Missing doctype before other content',
280280
line: 1,
281-
column: 1,
282-
source: 'parse-error',
283-
ruleId: 'missing-doctype',
284-
position: {
281+
name: 'example.html:1:1-1:1',
282+
place: {
285283
start: {line: 1, column: 1, offset: 0},
286284
end: {line: 1, column: 1, offset: 0}
287285
},
286+
reason: 'Missing doctype before other content',
287+
ruleId: 'missing-doctype',
288+
source: 'parse-error',
288289
file: 'example.html',
289-
fatal: false,
290-
note: 'Expected a `<!doctype html>` before anything else',
291-
url: null
290+
note: 'Expected a `<!doctype html>` before anything else'
292291
}
293292
],
294293
'should support vfiles'
@@ -344,19 +343,19 @@ test('parse-errors: working', async (t) => {
344343
JSON.parse(JSON.stringify(actual)),
345344
[
346345
{
346+
column: 1,
347+
fatal: false,
347348
message: 'Unexpected surrogate character',
348-
name: 'index.html:2:1-2:1',
349-
reason: 'Unexpected surrogate character',
350349
line: 2,
351-
column: 1,
352-
position: {
350+
name: 'index.html:2:1-2:1',
351+
place: {
353352
start: {line: 2, column: 1, offset: 16},
354353
end: {line: 2, column: 1, offset: 16}
355354
},
356-
source: 'parse-error',
355+
reason: 'Unexpected surrogate character',
357356
ruleId: 'surrogate-in-input-stream',
357+
source: 'parse-error',
358358
file: 'index.html',
359-
fatal: false,
360359
note: 'Unexpected code point `0xD800`. Do not use lone surrogate characters in HTML',
361360
url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-surrogate-in-input-stream'
362361
}
@@ -377,11 +376,11 @@ test('parse-errors: working', async (t) => {
377376
}
378377

379378
await t.test(fixture, async () => {
380-
const file = await read(new URL(fixture + '/index.html', root), 'utf8')
379+
const htmlUrl = new URL(fixture + '/index.html', root)
380+
const messageUrl = new URL(fixture + '/messages.json', root)
381+
const file = await read(htmlUrl, 'utf8')
381382
/** @type {Array<Error>} */
382-
const messages = JSON.parse(
383-
String(await fs.readFile(new URL(fixture + '/messages.json', root)))
384-
)
383+
let expected
385384

386385
file.dirname = ''
387386
/** @type {Array<VFileMessage>} */
@@ -393,9 +392,24 @@ test('parse-errors: working', async (t) => {
393392
}
394393
})
395394

395+
try {
396+
if ('UPDATE' in process.env) {
397+
throw new Error('Update')
398+
}
399+
400+
expected = JSON.parse(String(await fs.readFile(messageUrl)))
401+
} catch {
402+
expected = actual
403+
404+
await fs.writeFile(
405+
messageUrl,
406+
JSON.stringify(expected, undefined, 2) + '\n'
407+
)
408+
}
409+
396410
assert.deepEqual(
397411
JSON.parse(JSON.stringify(actual)),
398-
messages,
412+
expected,
399413
'should emit messages for `' + fixture + '`'
400414
)
401415
})
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[
22
{
3+
"column": 1,
4+
"fatal": false,
35
"message": "Unexpected metadata element after head",
4-
"name": "index.html:4:1-4:9",
5-
"reason": "Unexpected metadata element after head",
66
"line": 4,
7-
"column": 1,
8-
"position": {
7+
"name": "index.html:4:1-4:9",
8+
"place": {
99
"start": {
1010
"line": 4,
1111
"column": 1,
@@ -17,11 +17,10 @@
1717
"offset": 76
1818
}
1919
},
20-
"source": "parse-error",
20+
"reason": "Unexpected metadata element after head",
2121
"ruleId": "abandoned-head-element-child",
22+
"source": "parse-error",
2223
"file": "index.html",
23-
"fatal": false,
24-
"note": "Unexpected element after head. Expected the element before `</head>`",
25-
"url": null
24+
"note": "Unexpected element after head. Expected the element before `</head>`"
2625
}
2726
]

test/parse-error/abrupt-closing-of-empty-comment/messages.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[
22
{
3+
"column": 15,
4+
"fatal": false,
35
"message": "Unexpected abruptly closed empty comment",
4-
"name": "index.html:3:15-3:15",
5-
"reason": "Unexpected abruptly closed empty comment",
66
"line": 3,
7-
"column": 15,
8-
"position": {
7+
"name": "index.html:3:15-3:15",
8+
"place": {
99
"start": {
1010
"line": 3,
1111
"column": 15,
@@ -17,20 +17,20 @@
1717
"offset": 77
1818
}
1919
},
20-
"source": "parse-error",
20+
"reason": "Unexpected abruptly closed empty comment",
2121
"ruleId": "abrupt-closing-of-empty-comment",
22+
"source": "parse-error",
2223
"file": "index.html",
23-
"fatal": false,
2424
"note": "Unexpected `>` or `->`. Expected `-->` to close comments",
2525
"url": "https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment"
2626
},
2727
{
28+
"column": 20,
29+
"fatal": false,
2830
"message": "Unexpected abruptly closed empty comment",
29-
"name": "index.html:4:20-4:20",
30-
"reason": "Unexpected abruptly closed empty comment",
3131
"line": 4,
32-
"column": 20,
33-
"position": {
32+
"name": "index.html:4:20-4:20",
33+
"place": {
3434
"start": {
3535
"line": 4,
3636
"column": 20,
@@ -42,10 +42,10 @@
4242
"offset": 99
4343
}
4444
},
45-
"source": "parse-error",
45+
"reason": "Unexpected abruptly closed empty comment",
4646
"ruleId": "abrupt-closing-of-empty-comment",
47+
"source": "parse-error",
4748
"file": "index.html",
48-
"fatal": false,
4949
"note": "Unexpected `>` or `->`. Expected `-->` to close comments",
5050
"url": "https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment"
5151
}

0 commit comments

Comments
 (0)