Skip to content

Commit e4dff32

Browse files
committed
Refactor code-style
1 parent 66ff2e5 commit e4dff32

File tree

6 files changed

+457
-297
lines changed

6 files changed

+457
-297
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @typedef {import('./lib/index.js').Options} Options
3-
* @typedef {import('./lib/index.js').OnError} OnError
42
* @typedef {import('./lib/index.js').ErrorCode} ErrorCode
53
* @typedef {import('./lib/index.js').ErrorSeverity} ErrorSeverity
4+
* @typedef {import('./lib/index.js').OnError} OnError
5+
* @typedef {import('./lib/index.js').Options} Options
66
*/
77

88
export {fromHtml} from './lib/index.js'

lib/errors.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,275 +1,346 @@
1+
/**
2+
* @typedef ErrorInfo
3+
* Info on a `parse5` error.
4+
* @property {string} reason
5+
* Reason of error.
6+
* @property {string} description
7+
* More info on error.
8+
* @property {false} [url]
9+
* Turn off if this is not documented in the html5 spec (optional).
10+
*/
11+
112
export const errors = {
13+
/** @type {ErrorInfo} */
214
abandonedHeadElementChild: {
315
reason: 'Unexpected metadata element after head',
416
description:
517
'Unexpected element after head. Expected the element before `</head>`',
618
url: false
719
},
20+
/** @type {ErrorInfo} */
821
abruptClosingOfEmptyComment: {
922
reason: 'Unexpected abruptly closed empty comment',
1023
description: 'Unexpected `>` or `->`. Expected `-->` to close comments'
1124
},
25+
/** @type {ErrorInfo} */
1226
abruptDoctypePublicIdentifier: {
1327
reason: 'Unexpected abruptly closed public identifier',
1428
description:
1529
'Unexpected `>`. Expected a closing `"` or `\'` after the public identifier'
1630
},
31+
/** @type {ErrorInfo} */
1732
abruptDoctypeSystemIdentifier: {
1833
reason: 'Unexpected abruptly closed system identifier',
1934
description:
2035
'Unexpected `>`. Expected a closing `"` or `\'` after the identifier identifier'
2136
},
37+
/** @type {ErrorInfo} */
2238
absenceOfDigitsInNumericCharacterReference: {
2339
reason: 'Unexpected non-digit at start of numeric character reference',
2440
description:
2541
'Unexpected `%c`. Expected `[0-9]` for decimal references or `[0-9a-fA-F]` for hexadecimal references'
2642
},
43+
/** @type {ErrorInfo} */
2744
cdataInHtmlContent: {
2845
reason: 'Unexpected CDATA section in HTML',
2946
description:
3047
'Unexpected `<![CDATA[` in HTML. Remove it, use a comment, or encode special characters instead'
3148
},
49+
/** @type {ErrorInfo} */
3250
characterReferenceOutsideUnicodeRange: {
3351
reason: 'Unexpected too big numeric character reference',
3452
description:
3553
'Unexpectedly high character reference. Expected character references to be at most hexadecimal 10ffff (or decimal 1114111)'
3654
},
55+
/** @type {ErrorInfo} */
3756
closingOfElementWithOpenChildElements: {
3857
reason: 'Unexpected closing tag with open child elements',
3958
description:
4059
'Unexpectedly closing tag. Expected other tags to be closed first',
4160
url: false
4261
},
62+
/** @type {ErrorInfo} */
4363
controlCharacterInInputStream: {
4464
reason: 'Unexpected control character',
4565
description:
4666
'Unexpected control character `%x`. Expected a non-control code point, 0x00, or ASCII whitespace'
4767
},
68+
/** @type {ErrorInfo} */
4869
controlCharacterReference: {
4970
reason: 'Unexpected control character reference',
5071
description:
5172
'Unexpectedly control character in reference. Expected a non-control code point, 0x00, or ASCII whitespace'
5273
},
74+
/** @type {ErrorInfo} */
5375
disallowedContentInNoscriptInHead: {
5476
reason: 'Disallowed content inside `<noscript>` in `<head>`',
5577
description:
5678
'Unexpected text character `%c`. Only use text in `<noscript>`s in `<body>`',
5779
url: false
5880
},
81+
/** @type {ErrorInfo} */
5982
duplicateAttribute: {
6083
reason: 'Unexpected duplicate attribute',
6184
description:
6285
'Unexpectedly double attribute. Expected attributes to occur only once'
6386
},
87+
/** @type {ErrorInfo} */
6488
endTagWithAttributes: {
6589
reason: 'Unexpected attribute on closing tag',
6690
description: 'Unexpected attribute. Expected `>` instead'
6791
},
92+
/** @type {ErrorInfo} */
6893
endTagWithTrailingSolidus: {
6994
reason: 'Unexpected slash at end of closing tag',
7095
description: 'Unexpected `%c-1`. Expected `>` instead'
7196
},
97+
/** @type {ErrorInfo} */
7298
endTagWithoutMatchingOpenElement: {
7399
reason: 'Unexpected unopened end tag',
74100
description: 'Unexpected end tag. Expected no end tag or another end tag',
75101
url: false
76102
},
103+
/** @type {ErrorInfo} */
77104
eofBeforeTagName: {
78105
reason: 'Unexpected end of file',
79106
description: 'Unexpected end of file. Expected tag name instead'
80107
},
108+
/** @type {ErrorInfo} */
81109
eofInCdata: {
82110
reason: 'Unexpected end of file in CDATA',
83111
description: 'Unexpected end of file. Expected `]]>` to close the CDATA'
84112
},
113+
/** @type {ErrorInfo} */
85114
eofInComment: {
86115
reason: 'Unexpected end of file in comment',
87116
description: 'Unexpected end of file. Expected `-->` to close the comment'
88117
},
118+
/** @type {ErrorInfo} */
89119
eofInDoctype: {
90120
reason: 'Unexpected end of file in doctype',
91121
description:
92122
'Unexpected end of file. Expected a valid doctype (such as `<!doctype html>`)'
93123
},
124+
/** @type {ErrorInfo} */
94125
eofInElementThatCanContainOnlyText: {
95126
reason: 'Unexpected end of file in element that can only contain text',
96127
description: 'Unexpected end of file. Expected text or a closing tag',
97128
url: false
98129
},
130+
/** @type {ErrorInfo} */
99131
eofInScriptHtmlCommentLikeText: {
100132
reason: 'Unexpected end of file in comment inside script',
101133
description: 'Unexpected end of file. Expected `-->` to close the comment'
102134
},
135+
/** @type {ErrorInfo} */
103136
eofInTag: {
104137
reason: 'Unexpected end of file in tag',
105138
description: 'Unexpected end of file. Expected `>` to close the tag'
106139
},
140+
/** @type {ErrorInfo} */
107141
incorrectlyClosedComment: {
108142
reason: 'Incorrectly closed comment',
109143
description: 'Unexpected `%c-1`. Expected `-->` to close the comment'
110144
},
145+
/** @type {ErrorInfo} */
111146
incorrectlyOpenedComment: {
112147
reason: 'Incorrectly opened comment',
113148
description: 'Unexpected `%c`. Expected `<!--` to open the comment'
114149
},
150+
/** @type {ErrorInfo} */
115151
invalidCharacterSequenceAfterDoctypeName: {
116152
reason: 'Invalid sequence after doctype name',
117153
description: 'Unexpected sequence at `%c`. Expected `public` or `system`'
118154
},
155+
/** @type {ErrorInfo} */
119156
invalidFirstCharacterOfTagName: {
120157
reason: 'Invalid first character in tag name',
121158
description: 'Unexpected `%c`. Expected an ASCII letter instead'
122159
},
160+
/** @type {ErrorInfo} */
123161
misplacedDoctype: {
124162
reason: 'Misplaced doctype',
125163
description: 'Unexpected doctype. Expected doctype before head',
126164
url: false
127165
},
166+
/** @type {ErrorInfo} */
128167
misplacedStartTagForHeadElement: {
129168
reason: 'Misplaced `<head>` start tag',
130169
description:
131170
'Unexpected start tag `<head>`. Expected `<head>` directly after doctype',
132171
url: false
133172
},
173+
/** @type {ErrorInfo} */
134174
missingAttributeValue: {
135175
reason: 'Missing attribute value',
136176
description:
137177
'Unexpected `%c-1`. Expected an attribute value or no `%c-1` instead'
138178
},
179+
/** @type {ErrorInfo} */
139180
missingDoctype: {
140181
reason: 'Missing doctype before other content',
141182
description: 'Expected a `<!doctype html>` before anything else',
142183
url: false
143184
},
185+
/** @type {ErrorInfo} */
144186
missingDoctypeName: {
145187
reason: 'Missing doctype name',
146188
description: 'Unexpected doctype end at `%c`. Expected `html` instead'
147189
},
190+
/** @type {ErrorInfo} */
148191
missingDoctypePublicIdentifier: {
149192
reason: 'Missing public identifier in doctype',
150193
description: 'Unexpected `%c`. Expected identifier for `public` instead'
151194
},
195+
/** @type {ErrorInfo} */
152196
missingDoctypeSystemIdentifier: {
153197
reason: 'Missing system identifier in doctype',
154198
description:
155199
'Unexpected `%c`. Expected identifier for `system` instead (suggested: `"about:legacy-compat"`)'
156200
},
201+
/** @type {ErrorInfo} */
157202
missingEndTagName: {
158203
reason: 'Missing name in end tag',
159204
description: 'Unexpected `%c`. Expected an ASCII letter instead'
160205
},
206+
/** @type {ErrorInfo} */
161207
missingQuoteBeforeDoctypePublicIdentifier: {
162208
reason: 'Missing quote before public identifier in doctype',
163209
description: 'Unexpected `%c`. Expected `"` or `\'` instead'
164210
},
211+
/** @type {ErrorInfo} */
165212
missingQuoteBeforeDoctypeSystemIdentifier: {
166213
reason: 'Missing quote before system identifier in doctype',
167214
description: 'Unexpected `%c`. Expected `"` or `\'` instead'
168215
},
216+
/** @type {ErrorInfo} */
169217
missingSemicolonAfterCharacterReference: {
170218
reason: 'Missing semicolon after character reference',
171219
description: 'Unexpected `%c`. Expected `;` instead'
172220
},
221+
/** @type {ErrorInfo} */
173222
missingWhitespaceAfterDoctypePublicKeyword: {
174223
reason: 'Missing whitespace after public identifier in doctype',
175224
description: 'Unexpected `%c`. Expected ASCII whitespace instead'
176225
},
226+
/** @type {ErrorInfo} */
177227
missingWhitespaceAfterDoctypeSystemKeyword: {
178228
reason: 'Missing whitespace after system identifier in doctype',
179229
description: 'Unexpected `%c`. Expected ASCII whitespace instead'
180230
},
231+
/** @type {ErrorInfo} */
181232
missingWhitespaceBeforeDoctypeName: {
182233
reason: 'Missing whitespace before doctype name',
183234
description: 'Unexpected `%c`. Expected ASCII whitespace instead'
184235
},
236+
/** @type {ErrorInfo} */
185237
missingWhitespaceBetweenAttributes: {
186238
reason: 'Missing whitespace between attributes',
187239
description: 'Unexpected `%c`. Expected ASCII whitespace instead'
188240
},
241+
/** @type {ErrorInfo} */
189242
missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers: {
190243
reason:
191244
'Missing whitespace between public and system identifiers in doctype',
192245
description: 'Unexpected `%c`. Expected ASCII whitespace instead'
193246
},
247+
/** @type {ErrorInfo} */
194248
nestedComment: {
195249
reason: 'Unexpected nested comment',
196250
description: 'Unexpected `<!--`. Expected `-->`'
197251
},
252+
/** @type {ErrorInfo} */
198253
nestedNoscriptInHead: {
199254
reason: 'Unexpected nested `<noscript>` in `<head>`',
200255
description:
201256
'Unexpected `<noscript>`. Expected a closing tag or a meta element',
202257
url: false
203258
},
259+
/** @type {ErrorInfo} */
204260
nonConformingDoctype: {
205261
reason: 'Unexpected non-conforming doctype declaration',
206262
description:
207263
'Expected `<!doctype html>` or `<!doctype html system "about:legacy-compat">`',
208264
url: false
209265
},
266+
/** @type {ErrorInfo} */
210267
nonVoidHtmlElementStartTagWithTrailingSolidus: {
211268
reason: 'Unexpected trailing slash on start tag of non-void element',
212269
description: 'Unexpected `/`. Expected `>` instead'
213270
},
271+
/** @type {ErrorInfo} */
214272
noncharacterCharacterReference: {
215273
reason:
216274
'Unexpected noncharacter code point referenced by character reference',
217275
description: 'Unexpected code point. Do not use noncharacters in HTML'
218276
},
277+
/** @type {ErrorInfo} */
219278
noncharacterInInputStream: {
220279
reason: 'Unexpected noncharacter character',
221280
description: 'Unexpected code point `%x`. Do not use noncharacters in HTML'
222281
},
282+
/** @type {ErrorInfo} */
223283
nullCharacterReference: {
224284
reason: 'Unexpected NULL character referenced by character reference',
225285
description: 'Unexpected code point. Do not use NULL characters in HTML'
226286
},
287+
/** @type {ErrorInfo} */
227288
openElementsLeftAfterEof: {
228289
reason: 'Unexpected end of file',
229290
description: 'Unexpected end of file. Expected closing tag instead',
230291
url: false
231292
},
293+
/** @type {ErrorInfo} */
232294
surrogateCharacterReference: {
233295
reason: 'Unexpected surrogate character referenced by character reference',
234296
description:
235297
'Unexpected code point. Do not use lone surrogate characters in HTML'
236298
},
299+
/** @type {ErrorInfo} */
237300
surrogateInInputStream: {
238301
reason: 'Unexpected surrogate character',
239302
description:
240303
'Unexpected code point `%x`. Do not use lone surrogate characters in HTML'
241304
},
305+
/** @type {ErrorInfo} */
242306
unexpectedCharacterAfterDoctypeSystemIdentifier: {
243307
reason: 'Invalid character after system identifier in doctype',
244308
description: 'Unexpected character at `%c`. Expected `>`'
245309
},
310+
/** @type {ErrorInfo} */
246311
unexpectedCharacterInAttributeName: {
247312
reason: 'Unexpected character in attribute name',
248313
description:
249314
'Unexpected `%c`. Expected whitespace, `/`, `>`, `=`, or probably an ASCII letter'
250315
},
316+
/** @type {ErrorInfo} */
251317
unexpectedCharacterInUnquotedAttributeValue: {
252318
reason: 'Unexpected character in unquoted attribute value',
253319
description: 'Unexpected `%c`. Quote the attribute value to include it'
254320
},
321+
/** @type {ErrorInfo} */
255322
unexpectedEqualsSignBeforeAttributeName: {
256323
reason: 'Unexpected equals sign before attribute name',
257324
description: 'Unexpected `%c`. Add an attribute name before it'
258325
},
326+
/** @type {ErrorInfo} */
259327
unexpectedNullCharacter: {
260328
reason: 'Unexpected NULL character',
261329
description:
262330
'Unexpected code point `%x`. Do not use NULL characters in HTML'
263331
},
332+
/** @type {ErrorInfo} */
264333
unexpectedQuestionMarkInsteadOfTagName: {
265334
reason: 'Unexpected question mark instead of tag name',
266335
description: 'Unexpected `%c`. Expected an ASCII letter instead'
267336
},
337+
/** @type {ErrorInfo} */
268338
unexpectedSolidusInTag: {
269339
reason: 'Unexpected slash in tag',
270340
description:
271341
'Unexpected `%c-1`. Expected it followed by `>` or in a quoted attribute value'
272342
},
343+
/** @type {ErrorInfo} */
273344
unknownNamedCharacterReference: {
274345
reason: 'Unexpected unknown named character reference',
275346
description:

0 commit comments

Comments
 (0)