html-validate 7.14.0 → 7.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/browser.d.ts +1 -0
  2. package/browser.js +1 -0
  3. package/dist/cjs/browser.d.ts +1 -4
  4. package/dist/cjs/browser.js +13 -1
  5. package/dist/cjs/browser.js.map +1 -1
  6. package/dist/cjs/cli.js +5 -5
  7. package/dist/cjs/cli.js.map +1 -1
  8. package/dist/cjs/core.js +159 -117
  9. package/dist/cjs/core.js.map +1 -1
  10. package/dist/cjs/elements.js +1 -1
  11. package/dist/cjs/html-validate.js +1 -1
  12. package/dist/cjs/index.d.ts +1 -89
  13. package/dist/cjs/index.js +13 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/jest-lib.js +17 -12
  16. package/dist/cjs/jest-lib.js.map +1 -1
  17. package/dist/cjs/jest.d.ts +1 -42
  18. package/dist/cjs/jest.js.map +1 -1
  19. package/dist/cjs/meta-helper.js +3 -0
  20. package/dist/cjs/meta-helper.js.map +1 -1
  21. package/dist/cjs/rules-helper.js +3 -3
  22. package/dist/cjs/rules-helper.js.map +1 -1
  23. package/dist/cjs/test-utils.d.ts +1 -30
  24. package/dist/cjs/test-utils.js +3 -0
  25. package/dist/cjs/test-utils.js.map +1 -1
  26. package/dist/cjs/tsdoc-metadata.json +11 -0
  27. package/dist/es/browser.d.ts +1 -4
  28. package/dist/es/browser.js +2 -2
  29. package/dist/es/cli.js +4 -4
  30. package/dist/es/cli.js.map +1 -1
  31. package/dist/es/core.js +138 -100
  32. package/dist/es/core.js.map +1 -1
  33. package/dist/es/elements.js +1 -1
  34. package/dist/es/html-validate.js +2 -2
  35. package/dist/es/index.d.ts +1 -89
  36. package/dist/es/index.js +2 -2
  37. package/dist/es/jest-lib.js +18 -13
  38. package/dist/es/jest-lib.js.map +1 -1
  39. package/dist/es/jest.d.ts +1 -42
  40. package/dist/es/jest.js.map +1 -1
  41. package/dist/es/meta-helper.js +3 -0
  42. package/dist/es/meta-helper.js.map +1 -1
  43. package/dist/es/rules-helper.js +4 -4
  44. package/dist/es/rules-helper.js.map +1 -1
  45. package/dist/es/test-utils.d.ts +1 -30
  46. package/dist/es/test-utils.js +3 -0
  47. package/dist/es/test-utils.js.map +1 -1
  48. package/dist/{es/core.d.ts → types/browser.d.ts} +2312 -2615
  49. package/dist/{cjs/core.d.ts → types/index.d.ts} +2505 -2615
  50. package/dist/types/jest.d.ts +44 -0
  51. package/dist/types/test-utils.d.ts +817 -0
  52. package/jest.d.ts +1 -2
  53. package/package.json +33 -27
  54. package/test-utils.d.ts +1 -2
  55. package/dist/cjs/meta-helper.d.ts +0 -28
  56. package/dist/cjs/rules-helper.d.ts +0 -54
  57. package/dist/es/meta-helper.d.ts +0 -28
  58. package/dist/es/rules-helper.d.ts +0 -54
@@ -1,2615 +1,2505 @@
1
- import { I as IncludeExcludeOptions } from './rules-helper.js';
2
- import { SchemaObject, ErrorObject } from 'ajv';
3
-
4
- /** @internal */
5
- type EventCallback = (event: string, data: any) => void;
6
- /**
7
- * @internal
8
- */
9
- declare class EventHandler {
10
- listeners: {
11
- [event: string]: EventCallback[];
12
- };
13
- constructor();
14
- /**
15
- * Add an event listener.
16
- *
17
- * @param event - Event names (comma separated) or '*' for any event.
18
- * @param callback - Called any time even triggers.
19
- * @returns Unregistration function.
20
- */
21
- on(event: string, callback: EventCallback): () => void;
22
- /**
23
- * Add a onetime event listener. The listener will automatically be removed
24
- * after being triggered once.
25
- *
26
- * @param event - Event names (comma separated) or '*' for any event.
27
- * @param callback - Called any time even triggers.
28
- * @returns Unregistration function.
29
- */
30
- once(event: string, callback: EventCallback): () => void;
31
- /**
32
- * Trigger event causing all listeners to be called.
33
- *
34
- * @param event - Event name.
35
- * @param data - Event data.
36
- */
37
- trigger(event: string, data: any): void;
38
- }
39
-
40
- /**
41
- * @internal
42
- */
43
- type RuleBlocker = number & {
44
- __type: "rule-blocker";
45
- };
46
-
47
- declare enum TokenType {
48
- UNICODE_BOM = 1,
49
- WHITESPACE = 2,
50
- DOCTYPE_OPEN = 3,
51
- DOCTYPE_VALUE = 4,
52
- DOCTYPE_CLOSE = 5,
53
- TAG_OPEN = 6,
54
- TAG_CLOSE = 7,
55
- ATTR_NAME = 8,
56
- ATTR_VALUE = 9,
57
- TEXT = 10,
58
- TEMPLATING = 11,
59
- SCRIPT = 12,
60
- STYLE = 13,
61
- COMMENT = 14,
62
- CONDITIONAL = 15,
63
- DIRECTIVE = 16,
64
- EOF = 17
65
- }
66
- interface BaseToken {
67
- type: TokenType;
68
- location: Location;
69
- }
70
- interface UnicodeBOMToken extends BaseToken {
71
- type: TokenType.UNICODE_BOM;
72
- data: [bom: string];
73
- }
74
- interface WhitespaceToken extends BaseToken {
75
- type: TokenType.WHITESPACE;
76
- data: [text: string];
77
- }
78
- interface DoctypeOpenToken extends BaseToken {
79
- type: TokenType.DOCTYPE_OPEN;
80
- data: [text: string, tag: string];
81
- }
82
- interface DoctypeValueToken extends BaseToken {
83
- type: TokenType.DOCTYPE_VALUE;
84
- data: [text: string];
85
- }
86
- interface DoctypeCloseToken extends BaseToken {
87
- type: TokenType.DOCTYPE_CLOSE;
88
- data: [text: ">"];
89
- }
90
- interface TagOpenToken extends BaseToken {
91
- type: TokenType.TAG_OPEN;
92
- data: [text: string, close: "/" | "", tag: string];
93
- }
94
- interface TagCloseToken extends BaseToken {
95
- type: TokenType.TAG_CLOSE;
96
- data: [text: ">" | "/>"];
97
- }
98
- interface AttrNameToken extends BaseToken {
99
- type: TokenType.ATTR_NAME;
100
- data: [text: string, name: string];
101
- }
102
- interface AttrValueToken extends BaseToken {
103
- type: TokenType.ATTR_VALUE;
104
- data: [text: string, delimiter: string, value: string, quote?: '"' | "'"];
105
- }
106
- interface TextToken extends BaseToken {
107
- type: TokenType.TEXT;
108
- data: [text: string];
109
- }
110
- interface TemplatingToken extends BaseToken {
111
- type: TokenType.TEMPLATING;
112
- data: [text: string];
113
- }
114
- interface ScriptToken extends BaseToken {
115
- type: TokenType.SCRIPT;
116
- data: [text: string];
117
- }
118
- interface StyleToken extends BaseToken {
119
- type: TokenType.STYLE;
120
- data: [text: string];
121
- }
122
- interface CommentToken extends BaseToken {
123
- type: TokenType.COMMENT;
124
- data: [text: string, comment: string];
125
- }
126
- interface ConditionalToken extends BaseToken {
127
- type: TokenType.CONDITIONAL;
128
- data: [text: string, condition: string];
129
- }
130
- interface DirectiveToken extends BaseToken {
131
- type: TokenType.DIRECTIVE;
132
- data: [text: string, begin: "[", action: string, delimiter: string, rest: string, end: "]" | ""];
133
- }
134
- interface EOFToken extends BaseToken {
135
- type: TokenType.EOF;
136
- data: [];
137
- }
138
- type Token = UnicodeBOMToken | WhitespaceToken | DoctypeOpenToken | DoctypeValueToken | DoctypeCloseToken | TagOpenToken | TagCloseToken | AttrNameToken | AttrValueToken | TextToken | TemplatingToken | ScriptToken | StyleToken | CommentToken | ConditionalToken | DirectiveToken | EOFToken;
139
-
140
- type TokenStream = IterableIterator<Token>;
141
-
142
- type RuleSeverity = "off" | "warn" | "error" | number;
143
- type RuleOptions = string | number | Record<string, any>;
144
- type RuleConfig = Record<string, RuleSeverity | [RuleSeverity] | [RuleSeverity, RuleOptions]>;
145
- interface TransformMap {
146
- [key: string]: string;
147
- }
148
- /**
149
- * @public
150
- */
151
- interface ConfigData {
152
- /**
153
- * If set to true no new configurations will be searched.
154
- */
155
- root?: boolean;
156
- extends?: string[];
157
- /**
158
- * List of sources for element metadata.
159
- *
160
- * The following sources are allowed:
161
- *
162
- * - "html5" (default) for the builtin metadata.
163
- * - node module which export metadata
164
- * - local path to json or js file exporting metadata.
165
- * - object with inline metadata
166
- *
167
- * If elements isn't specified it defaults to `["html5"]`
168
- */
169
- elements?: Array<string | Record<string, unknown>>;
170
- /**
171
- * List of plugins.
172
- *
173
- * Each plugin must be resolvable be require and export the plugin interface.
174
- */
175
- plugins?: string[];
176
- /**
177
- * List of source file transformations. A transformer takes a filename and
178
- * returns Source instances with extracted HTML-templates.
179
- *
180
- * Example:
181
- *
182
- * ```js
183
- * "transform": {
184
- * "^.*\\.foo$": "my-transform"
185
- * }
186
- * ```
187
- *
188
- * To run the "my-transform" module on all .foo files.
189
- */
190
- transform?: TransformMap;
191
- rules?: RuleConfig;
192
- }
193
-
194
- /**
195
- * Reported error message.
196
- *
197
- * @public
198
- */
199
- interface Message {
200
- /** Rule that triggered this message */
201
- ruleId: string;
202
- /** URL to description of error */
203
- ruleUrl?: string;
204
- /** Severity of the message */
205
- severity: number;
206
- /** Message text */
207
- message: string;
208
- /** Offset (number of characters) into the source */
209
- offset: number;
210
- /** Line number */
211
- line: number;
212
- /** Column number */
213
- column: number;
214
- /** From start offset, how many characters is this message relevant for */
215
- size: number;
216
- /** DOM selector */
217
- selector: string | null;
218
- /**
219
- * Optional error context used to provide context-aware documentation.
220
- *
221
- * This context can be passed to [[HtmlValidate#getRuleDocumentation]].
222
- */
223
- context?: any;
224
- }
225
- /**
226
- * @internal
227
- */
228
- interface DeferredMessage extends Omit<Message, "selector"> {
229
- selector: () => string | null;
230
- }
231
- /**
232
- * @public
233
- */
234
- interface Result {
235
- messages: Message[];
236
- filePath: string;
237
- errorCount: number;
238
- warningCount: number;
239
- source: string | null;
240
- }
241
- /**
242
- * Report object returned by [[HtmlValidate]].
243
- *
244
- * @public
245
- */
246
- interface Report {
247
- /** `true` if validation was successful */
248
- valid: boolean;
249
- /** Detailed results per validated source */
250
- results: Result[];
251
- /** Total number of errors across all sources */
252
- errorCount: number;
253
- /** Total warnings of errors across all sources */
254
- warningCount: number;
255
- }
256
- /**
257
- * @internal
258
- */
259
- declare class Reporter {
260
- protected result: Record<string, DeferredMessage[]>;
261
- constructor();
262
- /**
263
- * Merge two or more reports into a single one.
264
- */
265
- static merge(reports: Report[]): Report;
266
- add<ContextType, OptionsType>(rule: Rule<ContextType, OptionsType>, message: string, severity: number, node: DOMNode | null, location: Location, context?: ContextType): void;
267
- addManual(filename: string, message: DeferredMessage): void;
268
- save(sources?: Source[]): Report;
269
- protected isValid(): boolean;
270
- }
271
-
272
- interface ErrorDescriptor<ContextType> {
273
- node: DOMNode | null;
274
- message: string;
275
- location?: Location | null | undefined;
276
- context?: ContextType;
277
- }
278
- /**
279
- * @public
280
- */
281
- interface RuleDocumentation {
282
- description: string;
283
- url?: string;
284
- }
285
- interface RuleConstructor<T, U> {
286
- new (options?: any): Rule<T, U>;
287
- schema(): SchemaObject | null | undefined;
288
- }
289
- /**
290
- * @public
291
- */
292
- declare abstract class Rule<ContextType = void, OptionsType = void> {
293
- private reporter;
294
- private parser;
295
- private meta;
296
- private enabled;
297
- private blockers;
298
- private severity;
299
- private event;
300
- /**
301
- * Rule name. Defaults to filename without extension but can be overwritten by
302
- * subclasses.
303
- */
304
- name: string;
305
- /**
306
- * Rule options.
307
- */
308
- readonly options: OptionsType;
309
- constructor(options: OptionsType);
310
- getSeverity(): number;
311
- setServerity(severity: number): void;
312
- /**
313
- * Block this rule from generating errors. Pass in an id generated by {@link
314
- * createBlocker}. Can be unblocked by {@link unblock}.
315
- *
316
- * A blocked rule is similar to disabling it but it will still receive parser
317
- * events. A list of all blockers is passed to the `rule:error` event.
318
- *
319
- * @internal
320
- */
321
- block(id: RuleBlocker): void;
322
- /**
323
- * Unblock a rule previously blocked by {@link block}.
324
- *
325
- * @internal
326
- */
327
- unblock(id: RuleBlocker): void;
328
- setEnabled(enabled: boolean): void;
329
- /**
330
- * Returns `true` if rule is deprecated.
331
- *
332
- * Overridden by subclasses.
333
- */
334
- get deprecated(): boolean;
335
- /**
336
- * Test if rule is enabled.
337
- *
338
- * To be considered enabled the enabled flag must be true and the severity at
339
- * least warning.
340
- *
341
- * @internal
342
- */
343
- isEnabled(node?: DOMNode | null): boolean;
344
- /**
345
- * Test if rule is enabled.
346
- *
347
- * To be considered enabled the enabled flag must be true and the severity at
348
- * least warning.
349
- *
350
- * @internal
351
- */
352
- isBlocked(node?: DOMNode | null): boolean;
353
- /**
354
- * Get a list of all blockers currently active this rule.
355
- *
356
- * @internal
357
- */
358
- getBlockers(node?: DOMNode | null): RuleBlocker[];
359
- /**
360
- * Check if keyword is being ignored by the current rule configuration.
361
- *
362
- * This method requires the [[RuleOption]] type to include two properties:
363
- *
364
- * - include: string[] | null
365
- * - exclude: string[] | null
366
- *
367
- * This methods checks if the given keyword is included by "include" but not
368
- * excluded by "exclude". If any property is unset it is skipped by the
369
- * condition. Usually the user would use either one but not both but there is
370
- * no limitation to use both but the keyword must satisfy both conditions. If
371
- * either condition fails `true` is returned.
372
- *
373
- * For instance, given `{ include: ["foo"] }` the keyword `"foo"` would match
374
- * but not `"bar"`.
375
- *
376
- * Similarly, given `{ exclude: ["foo"] }` the keyword `"bar"` would match but
377
- * not `"foo"`.
378
- *
379
- * @param keyword - Keyword to match against `include` and `exclude` options.
380
- * @param matcher - Optional function to compare items with.
381
- * @returns `true` if keyword is not present in `include` or is present in
382
- * `exclude`.
383
- */
384
- isKeywordIgnored<T extends IncludeExcludeOptions>(this: {
385
- options: T;
386
- }, keyword: string, matcher?: (list: string[], it: string) => boolean): boolean;
387
- /**
388
- * Get [[MetaElement]] for the given tag. If no specific metadata is present
389
- * the global metadata is returned or null if no global is present.
390
- *
391
- * @public
392
- * @returns A shallow copy of metadata.
393
- */
394
- getMetaFor(tagName: string): MetaElement | null;
395
- /**
396
- * Find all tags which has enabled given property.
397
- */
398
- getTagsWithProperty(propName: MetaLookupableProperty): string[];
399
- /**
400
- * Find tag matching tagName or inheriting from it.
401
- */
402
- getTagsDerivedFrom(tagName: string): string[];
403
- /**
404
- * JSON schema for rule options.
405
- *
406
- * Rules should override this to return an object with JSON schema to validate
407
- * rule options. If `null` or `undefined` is returned no validation is
408
- * performed.
409
- */
410
- static schema(): SchemaObject | null | undefined;
411
- /**
412
- * Report a new error.
413
- *
414
- * Rule must be enabled both globally and on the specific node for this to
415
- * have any effect.
416
- */
417
- report(error: ErrorDescriptor<ContextType>): void;
418
- report(node: DOMNode | null, message: string): void;
419
- report(node: DOMNode | null, message: string, location: Location | null | undefined): void;
420
- report(node: DOMNode | null, message: string, location: Location | null | undefined, context: ContextType): void;
421
- private findLocation;
422
- /**
423
- * Listen for events.
424
- *
425
- * Adding listeners can be done even if the rule is disabled but for the
426
- * events to be delivered the rule must be enabled.
427
- *
428
- * If the optional filter callback is used it must be a function taking an
429
- * event of the same type as the listener. The filter is called before the
430
- * listener and if the filter returns false the event is discarded.
431
- *
432
- * @param event - Event name
433
- * @param filter - Optional filter function. Callback is only called if filter functions return true.
434
- * @param callback - Callback to handle event.
435
- * @returns A function to unregister the listener
436
- */
437
- on<K extends keyof ListenEventMap>(event: K, callback: (event: ListenEventMap[K]) => void): () => void;
438
- on<K extends keyof ListenEventMap>(event: K, filter: (event: ListenEventMap[K]) => boolean, callback: (event: ListenEventMap[K]) => void): () => void;
439
- /**
440
- * Called by [[Engine]] when initializing the rule.
441
- *
442
- * Do not override this, use the `setup` callback instead.
443
- *
444
- * @internal
445
- */
446
- init(parser: Parser, reporter: Reporter, severity: number, meta: MetaTable): void;
447
- /**
448
- * Validate rule options against schema. Throws error if object does not validate.
449
- *
450
- * For rules without schema this function does nothing.
451
- *
452
- * @throws {@link SchemaValidationError}
453
- * Thrown when provided options does not validate against rule schema.
454
- *
455
- * @param cls - Rule class (constructor)
456
- * @param ruleId - Rule identifier
457
- * @param jsonPath - JSON path from which [[options]] can be found in [[config]]
458
- * @param options - User configured options to be validated
459
- * @param filename - Filename from which options originated
460
- * @param config - Configuration from which options originated
461
- *
462
- * @internal
463
- */
464
- static validateOptions(cls: RuleConstructor<unknown, unknown> | undefined, ruleId: string, jsonPath: string, options: unknown, filename: string | null, config: ConfigData): void;
465
- /**
466
- * Rule setup callback.
467
- *
468
- * Override this to provide rule setup code.
469
- */
470
- abstract setup(): void;
471
- /**
472
- * Rule documentation callback.
473
- *
474
- * Called when requesting additional documentation for a rule. Some rules
475
- * provide additional context to provide context-aware suggestions.
476
- *
477
- * @param context - Error context given by a reported error.
478
- * @returns Rule documentation and url with additional details or `null` if no
479
- * additional documentation is available.
480
- */
481
- documentation(context?: ContextType): RuleDocumentation | null;
482
- }
483
-
484
- /**
485
- * @internal
486
- */
487
- interface Event {
488
- /** Event location. */
489
- location: Location | null;
490
- }
491
- /**
492
- * Configuration ready event.
493
- *
494
- * @public
495
- */
496
- interface ConfigReadyEvent extends Event {
497
- config: ResolvedConfig;
498
- rules: Record<string, Rule<unknown, unknown>>;
499
- }
500
- /**
501
- * Source ready event. Emitted after source has been transformed but before any
502
- * markup is processed.
503
- *
504
- * The source object must not be modified (use a transformer if modifications
505
- * are required)
506
- *
507
- * @public
508
- */
509
- interface SourceReadyEvent extends Event {
510
- source: Source;
511
- }
512
- /**
513
- * Token event.
514
- *
515
- * @public
516
- */
517
- interface TokenEvent extends Event {
518
- /** @deprecated use token property which is typesafe */
519
- type: TokenType;
520
- /** @deprecated use token property which is typesafe */
521
- data?: any;
522
- token: Token;
523
- }
524
- /**
525
- * Event emitted when starting tags are encountered.
526
- *
527
- * @public
528
- */
529
- interface TagStartEvent extends Event {
530
- /** Event location. */
531
- location: Location;
532
- /** The node being started. */
533
- target: HtmlElement;
534
- }
535
- /**
536
- * Deprecated alias for TagStartEvent
537
- *
538
- * @public
539
- * @deprecated Use TagStartEvent instead
540
- */
541
- type TagOpenEvent = TagStartEvent;
542
- /**
543
- * Event emitted when end tags `</..>` are encountered.
544
- *
545
- * @public
546
- */
547
- interface TagEndEvent extends Event {
548
- /** Event location. */
549
- location: Location;
550
- /** Temporary node for the end tag. Can be null for elements left unclosed
551
- * when document ends */
552
- target: HtmlElement | null;
553
- /** The node being closed. */
554
- previous: HtmlElement;
555
- }
556
- /**
557
- * Deprecated alias for TagEndEvent
558
- *
559
- * @public
560
- * @deprecated Use TagEndEvent instead
561
- */
562
- type TagCloseEvent = TagEndEvent;
563
- /**
564
- * Event emitted when a tag is ready (i.e. all the attributes has been
565
- * parsed). The children of the element will not yet be finished.
566
- *
567
- * @public
568
- */
569
- interface TagReadyEvent extends Event {
570
- /** Event location. */
571
- location: Location;
572
- /** The node that is finished parsing. */
573
- target: HtmlElement;
574
- }
575
- /**
576
- * Event emitted when an element is fully constructed (including its children).
577
- *
578
- * @public
579
- */
580
- interface ElementReadyEvent extends Event {
581
- /** Event location. */
582
- location: Location;
583
- /** HTML element */
584
- target: HtmlElement;
585
- }
586
- /**
587
- * Event emitted when attributes are encountered.
588
- *
589
- * @public
590
- */
591
- interface AttributeEvent extends Event {
592
- /** Location of the full attribute (key, quotes and value) */
593
- location: Location;
594
- /** Attribute name. */
595
- key: string;
596
- /** Attribute value. */
597
- value: string | DynamicValue | null;
598
- /** Quotemark used. */
599
- quote: '"' | "'" | null;
600
- /** Set to original attribute when a transformer dynamically added this
601
- * attribute. */
602
- originalAttribute?: string;
603
- /** HTML element this attribute belongs to. */
604
- target: HtmlElement;
605
- /** Location of the attribute key */
606
- keyLocation: Location;
607
- /** Location of the attribute value */
608
- valueLocation: Location | null;
609
- }
610
- /**
611
- * Event emitted when whitespace content is parsed.
612
- *
613
- * @public
614
- */
615
- interface WhitespaceEvent extends Event {
616
- /** Event location. */
617
- location: Location;
618
- /** Text content. */
619
- text: string;
620
- }
621
- /**
622
- * Event emitted when Internet Explorer conditionals `<![if ...]>` are
623
- * encountered.
624
- *
625
- * @public
626
- */
627
- interface ConditionalEvent extends Event {
628
- /** Event location. */
629
- location: Location;
630
- /** Condition including markers. */
631
- condition: string;
632
- /** The element containing the conditional, if any. */
633
- parent: HtmlElement | null;
634
- }
635
- /**
636
- * Event emitted when html-validate directives `<!-- [html-validate-...] -->`
637
- * are encountered.
638
- *
639
- * @public
640
- */
641
- interface DirectiveEvent extends Event {
642
- /** Event location. */
643
- location: Location;
644
- /** Action location */
645
- actionLocation: Location;
646
- /** Options location */
647
- optionsLocation?: Location;
648
- /** Comment location */
649
- commentLocation?: Location;
650
- /** Directive action. */
651
- action: "enable" | "disable" | "disable-block" | "disable-next";
652
- /** Directive options. */
653
- data: string;
654
- /** Directive comment. */
655
- comment: string;
656
- }
657
- /**
658
- * Event emitted when doctypes `<!DOCTYPE ..>` are encountered.
659
- *
660
- * @public
661
- */
662
- interface DoctypeEvent extends Event {
663
- /** Event location. */
664
- location: Location;
665
- /** Tag */
666
- tag: string;
667
- /** Selected doctype */
668
- value: string;
669
- /** Location of doctype value */
670
- valueLocation: Location;
671
- }
672
- /**
673
- * Event emitted after initialization but before tokenization and parsing occurs.
674
- * Can be used to initialize state in rules.
675
- *
676
- * @public
677
- */
678
- interface DOMLoadEvent extends Event {
679
- source: Source;
680
- }
681
- /**
682
- * Event emitted when DOM tree is fully constructed.
683
- *
684
- * @public
685
- */
686
- interface DOMReadyEvent extends Event {
687
- /** DOM Tree */
688
- document: DOMTree;
689
- source: Source;
690
- }
691
- /**
692
- * Event emitted when a rule triggers an error.
693
- *
694
- * @internal
695
- */
696
- interface RuleErrorEvent extends Event {
697
- ruleId: string;
698
- /** whenever the rule was enabled or not (i.e. if a user will see the error or not) */
699
- enabled: boolean;
700
- /** list of rule blockers active when this rule triggered an event */
701
- blockers: RuleBlocker[];
702
- }
703
- /**
704
- * Event emitted right before the parser begins parsing markup.
705
- *
706
- * @internal
707
- */
708
- interface ParseBeginEvent extends Event {
709
- location: null;
710
- }
711
- /**
712
- * Event emitted right after the parser finishes parsing markup.
713
- *
714
- * @internal
715
- */
716
- interface ParseEndEvent extends Event {
717
- location: null;
718
- }
719
- /**
720
- * @public
721
- */
722
- interface TriggerEventMap {
723
- "config:ready": ConfigReadyEvent;
724
- "source:ready": SourceReadyEvent;
725
- token: TokenEvent;
726
- "tag:start": TagStartEvent;
727
- "tag:end": TagEndEvent;
728
- "tag:ready": TagReadyEvent;
729
- "element:ready": ElementReadyEvent;
730
- "dom:load": DOMLoadEvent;
731
- "dom:ready": DOMReadyEvent;
732
- doctype: DoctypeEvent;
733
- attr: AttributeEvent;
734
- whitespace: WhitespaceEvent;
735
- conditional: ConditionalEvent;
736
- directive: DirectiveEvent;
737
- "rule:error": RuleErrorEvent;
738
- "parse:begin": ParseBeginEvent;
739
- "parse:end": ParseEndEvent;
740
- }
741
- /**
742
- * @public
743
- */
744
- interface ListenEventMap {
745
- "config:ready": ConfigReadyEvent;
746
- "source:ready": SourceReadyEvent;
747
- token: TokenEvent;
748
- "tag:open": TagOpenEvent;
749
- "tag:start": TagStartEvent;
750
- "tag:close": TagCloseEvent;
751
- "tag:end": TagEndEvent;
752
- "tag:ready": TagReadyEvent;
753
- "element:ready": ElementReadyEvent;
754
- "dom:load": DOMLoadEvent;
755
- "dom:ready": DOMReadyEvent;
756
- doctype: DoctypeEvent;
757
- attr: AttributeEvent;
758
- whitespace: WhitespaceEvent;
759
- conditional: ConditionalEvent;
760
- directive: DirectiveEvent;
761
- "rule:error": RuleErrorEvent;
762
- "parse:begin": ParseBeginEvent;
763
- "parse:end": ParseEndEvent;
764
- "*": Event;
765
- }
766
-
767
- /**
768
- * Parse HTML document into a DOM tree.
769
- *
770
- * @internal
771
- */
772
- declare class Parser {
773
- private readonly event;
774
- private readonly metaTable;
775
- private currentNamespace;
776
- private dom;
777
- /**
778
- * Create a new parser instance.
779
- *
780
- * @param config - Configuration
781
- */
782
- constructor(config: ResolvedConfig);
783
- /**
784
- * Parse HTML markup.
785
- *
786
- * @param source - HTML markup.
787
- * @returns DOM tree representing the HTML markup.
788
- */
789
- parseHtml(source: string | Source): HtmlElement;
790
- /**
791
- * Detect optional end tag.
792
- *
793
- * Some tags have optional end tags (e.g. <ul><li>foo<li>bar</ul> is
794
- * valid). The parser handles this by checking if the element on top of the
795
- * stack when is allowed to omit.
796
- */
797
- private closeOptional;
798
- protected consume(source: Source, token: Token, tokenStream: TokenStream): void;
799
- protected consumeTag(source: Source, startToken: TagOpenToken, tokenStream: TokenStream): void;
800
- protected closeElement(source: Source, node: HtmlElement | null, active: HtmlElement, location: Location): void;
801
- private processElement;
802
- /**
803
- * Discard tokens until the end tag for the foreign element is found.
804
- */
805
- protected discardForeignBody(source: Source, foreignTagName: string, tokenStream: TokenStream, errorLocation: Location): void;
806
- protected consumeAttribute(source: Source, node: HtmlElement, token: AttrNameToken, next?: Token): void;
807
- /**
808
- * Takes attribute key token an returns location.
809
- */
810
- private getAttributeKeyLocation;
811
- /**
812
- * Take attribute value token and return a new location referring to only the
813
- * value.
814
- *
815
- * foo="bar" foo='bar' foo=bar foo foo=""
816
- * ^^^ ^^^ ^^^ (null) (null)
817
- */
818
- private getAttributeValueLocation;
819
- /**
820
- * Take attribute key and value token an returns a new location referring to
821
- * an aggregate location covering key, quotes if present and value.
822
- */
823
- private getAttributeLocation;
824
- protected consumeDirective(token: DirectiveToken): void;
825
- /**
826
- * Consumes conditional comment in tag form.
827
- *
828
- * See also the related [[consumeCommend]] method.
829
- */
830
- protected consumeConditional(token: ConditionalToken): void;
831
- /**
832
- * Consumes comment token.
833
- *
834
- * Tries to find IE conditional comments and emits conditional token if
835
- * found. See also the related [[consumeConditional]] method.
836
- */
837
- protected consumeComment(token: CommentToken): void;
838
- /**
839
- * Consumes doctype tokens. Emits doctype event.
840
- */
841
- protected consumeDoctype(startToken: DoctypeOpenToken, tokenStream: TokenStream): void;
842
- /**
843
- * Return a list of tokens found until the expected token was found.
844
- *
845
- * @param errorLocation - What location to use if an error occurs
846
- */
847
- protected consumeUntil(tokenStream: TokenStream, search: TokenType, errorLocation: Location): IterableIterator<Token>;
848
- /**
849
- * Consumes tokens until a matching close-tag is found. Tags are appended to
850
- * the document.
851
- *
852
- * @internal
853
- */
854
- protected consumeUntilMatchingTag(source: Source, tokenStream: TokenStream, searchTag: string): void;
855
- private next;
856
- /**
857
- * Listen on events.
858
- *
859
- * @param event - Event name.
860
- * @param listener - Event callback.
861
- * @returns A function to unregister the listener.
862
- */
863
- on<K extends keyof ListenEventMap>(event: K, listener: (event: string, data: ListenEventMap[K]) => void): () => void;
864
- on(event: string, listener: EventCallback): () => void;
865
- /**
866
- * Listen on single event. The listener is automatically unregistered once the
867
- * event has been received.
868
- *
869
- * @param event - Event name.
870
- * @param listener - Event callback.
871
- * @returns A function to unregister the listener.
872
- */
873
- once<K extends keyof ListenEventMap>(event: K, listener: (event: string, data: ListenEventMap[K]) => void): () => void;
874
- once(event: string, listener: EventCallback): () => void;
875
- /**
876
- * Defer execution. Will call function sometime later.
877
- *
878
- * @param cb - Callback to execute later.
879
- */
880
- defer(cb: () => void): void;
881
- /**
882
- * Trigger event.
883
- *
884
- * @param event - Event name
885
- * @param data - Event data
886
- */
887
- trigger<K extends keyof TriggerEventMap>(event: K, data: TriggerEventMap[K]): void;
888
- /**
889
- * @internal
890
- */
891
- getEventHandler(): EventHandler;
892
- /**
893
- * Appends a text node to the current element on the stack.
894
- */
895
- private appendText;
896
- /**
897
- * Trigger close events for any still open elements.
898
- */
899
- private closeTree;
900
- }
901
-
902
- /**
903
- * Raw attribute data.
904
- *
905
- * @public
906
- */
907
- interface AttributeData {
908
- /** Attribute name */
909
- key: string;
910
- /** Attribute value */
911
- value: string | DynamicValue | null;
912
- /** Quotation mark (if present) */
913
- quote: '"' | "'" | null;
914
- /** Original attribute name (when a dynamic attribute is used), e.g
915
- * "ng-attr-foo" or "v-bind:foo" */
916
- originalAttribute?: string;
917
- }
918
-
919
- /**
920
- * @public
921
- */
922
- type ProcessAttributeCallback = (this: unknown, attr: AttributeData) => Iterable<AttributeData>;
923
- /**
924
- * @public
925
- */
926
- interface ProcessElementContext {
927
- getMetaFor(this: void, tagName: string): MetaElement | null;
928
- }
929
- /**
930
- * @public
931
- */
932
- type ProcessElementCallback = (this: ProcessElementContext, node: HtmlElement) => void;
933
- /**
934
- * @public
935
- */
936
- interface SourceHooks {
937
- /**
938
- * Called for every attribute.
939
- *
940
- * The original attribute must be yielded as well or no attribute will be
941
- * added.
942
- *
943
- * @returns Attribute data for an attribute to be added to the element.
944
- */
945
- processAttribute?: ProcessAttributeCallback | null;
946
- /**
947
- * Called for every element after element is created but before any children.
948
- *
949
- * May modify the element.
950
- */
951
- processElement?: ProcessElementCallback | null;
952
- }
953
- /**
954
- * Source interface.
955
- *
956
- * HTML source with file, line and column context.
957
- *
958
- * Optional hooks can be attached. This is usually added by transformers to
959
- * postprocess.
960
- *
961
- * @public
962
- */
963
- interface Source {
964
- data: string;
965
- filename: string;
966
- /**
967
- * Line in the original data.
968
- *
969
- * Starts at 1 (first line).
970
- */
971
- line: number;
972
- /**
973
- * Column in the original data.
974
- *
975
- * Starts at 1 (first column).
976
- */
977
- column: number;
978
- /**
979
- * Offset in the original data.
980
- *
981
- * Starts at 0 (first character).
982
- */
983
- offset: number;
984
- /**
985
- * Original data. When a transformer extracts a portion of the original source
986
- * this must be set to the full original source.
987
- *
988
- * Since the transformer might be chained always test if the input source
989
- * itself has `originalData` set, e.g.:
990
- *
991
- * `originalData = input.originalData || input.data`.
992
- */
993
- originalData?: string;
994
- /**
995
- * Hooks for processing the source as it is being parsed.
996
- */
997
- hooks?: SourceHooks;
998
- /**
999
- * Internal property to keep track of what transformers has run on this
1000
- * source. Entries are in reverse-order, e.g. the last applied transform is
1001
- * first.
1002
- */
1003
- transformedBy?: string[];
1004
- }
1005
-
1006
- /**
1007
- * @public
1008
- */
1009
- interface Location {
1010
- /**
1011
- * The filemane this location refers to.
1012
- */
1013
- readonly filename: string;
1014
- /**
1015
- * The string offset (number of characters into the string) this location
1016
- * refers to.
1017
- */
1018
- readonly offset: number;
1019
- /**
1020
- * The line number in the file.
1021
- */
1022
- readonly line: number;
1023
- /**
1024
- * The column number in the file. Tabs counts as 1 (not expanded).
1025
- */
1026
- readonly column: number;
1027
- /**
1028
- * The number of characters this location refers to. This includes any
1029
- * whitespace characters such as newlines.
1030
- */
1031
- readonly size: number;
1032
- }
1033
- /**
1034
- * Calculate a new location by offsetting this location.
1035
- *
1036
- * If the references text with newlines the wrap parameter must be set to
1037
- * properly calculate line and column information. If not given the text is
1038
- * assumed to contain no newlines.
1039
- *
1040
- * @public
1041
- * @param location - Source location
1042
- * @param begin - Start location. Default is 0.
1043
- * @param end - End location. Default is size of location. Negative values are
1044
- * counted from end, e.g. `-2` means `size - 2`.
1045
- * @param wrap - If given, line/column is wrapped for each newline occuring
1046
- * before location end.
1047
- */
1048
- declare function sliceLocation(location: Location, begin: number, end?: number, wrap?: string): Location;
1049
- declare function sliceLocation(location: Location | null | undefined, begin: number, end?: number, wrap?: string): Location | null;
1050
-
1051
- /**
1052
- * @public
1053
- */
1054
- declare class DynamicValue {
1055
- readonly expr: string;
1056
- constructor(expr: string);
1057
- toString(): string;
1058
- }
1059
-
1060
- /**
1061
- * DOM Attribute.
1062
- *
1063
- * Represents a HTML attribute. Can contain either a fixed static value or a
1064
- * placeholder for dynamic values (e.g. interpolated).
1065
- */
1066
- declare class Attribute {
1067
- /** Attribute name */
1068
- readonly key: string;
1069
- readonly value: string | DynamicValue | null;
1070
- readonly keyLocation: Location;
1071
- readonly valueLocation: Location | null;
1072
- readonly originalAttribute?: string;
1073
- /**
1074
- * @param key - Attribute name.
1075
- * @param value - Attribute value. Set to `null` for boolean attributes.
1076
- * @param keyLocation - Source location of attribute name.
1077
- * @param valueLocation - Source location of attribute value.
1078
- * @param originalAttribute - If this attribute was dynamically added via a
1079
- * transformation (e.g. vuejs `:id` generating the `id` attribute) this
1080
- * parameter should be set to the attribute name of the source attribute (`:id`).
1081
- */
1082
- constructor(key: string, value: null | string | DynamicValue | null, keyLocation: Location, valueLocation: Location | null, originalAttribute?: string);
1083
- /**
1084
- * Flag set to true if the attribute value is static.
1085
- */
1086
- get isStatic(): boolean;
1087
- /**
1088
- * Flag set to true if the attribute value is dynamic.
1089
- */
1090
- get isDynamic(): boolean;
1091
- /**
1092
- * Test attribute value.
1093
- *
1094
- * @param pattern - Pattern to match value against. Can be a RegExp, literal
1095
- * string or an array of strings (returns true if any value matches the
1096
- * array).
1097
- * @param dynamicMatches - If true `DynamicValue` will always match, if false
1098
- * it never matches.
1099
- * @returns `true` if attribute value matches pattern.
1100
- */
1101
- valueMatches(pattern: RegExp, dynamicMatches?: boolean): boolean;
1102
- valueMatches(pattern: string, dynamicMatches?: boolean): boolean;
1103
- valueMatches(pattern: string[], dynamicMatches?: boolean): boolean;
1104
- }
1105
-
1106
- interface CSSStyleDeclaration {
1107
- [key: string]: string;
1108
- }
1109
-
1110
- /**
1111
- * @public
1112
- */
1113
- interface TransformContext {
1114
- /**
1115
- * Test if an additional chainable transformer is present.
1116
- *
1117
- * Returns true only if there is a transformer configured for the given
1118
- * filename.
1119
- *
1120
- * @param filename - Filename to use to match next transformer.
1121
- */
1122
- hasChain(filename: string): boolean;
1123
- /**
1124
- * Chain transformations.
1125
- *
1126
- * Sometimes multiple transformers must be applied. For instance, a Markdown
1127
- * file with JSX in a code-block.
1128
- *
1129
- * @param source - Source to chain transformations on.
1130
- * @param filename - Filename to use to match next transformer (unrelated to
1131
- * filename set in source)
1132
- */
1133
- chain(source: Source, filename: string): Iterable<Source>;
1134
- }
1135
-
1136
- declare module "estree" {
1137
- interface TemplateElement {
1138
- start: number;
1139
- end: number;
1140
- }
1141
- }
1142
- /**
1143
- * @public
1144
- */
1145
- declare class TemplateExtractor {
1146
- private ast;
1147
- private filename;
1148
- private data;
1149
- private constructor();
1150
- static fromFilename(filename: string): TemplateExtractor;
1151
- /**
1152
- * Create a new [[TemplateExtractor]] from javascript source code.
1153
- *
1154
- * `Source` offsets will be relative to the string, i.e. offset 0 is the first
1155
- * character of the string. If the string is only a subset of a larger string
1156
- * the offsets must be adjusted manually.
1157
- *
1158
- * @param source - Source code.
1159
- * @param filename - Optional filename to set in the resulting
1160
- * `Source`. Defauls to `"inline"`.
1161
- */
1162
- static fromString(source: string, filename?: string): TemplateExtractor;
1163
- /**
1164
- * Convenience function to create a [[Source]] instance from an existing file.
1165
- *
1166
- * @param filename - Filename with javascript source code. The file must exist
1167
- * and be readable by the user.
1168
- * @returns An array of Source's suitable for passing to [[Engine]] linting
1169
- * functions.
1170
- */
1171
- static createSource(filename: string): Source[];
1172
- /**
1173
- * Extract object properties.
1174
- *
1175
- * Given a key `"template"` this method finds all objects literals with a
1176
- * `"template"` property and creates a [[Source]] instance with proper offsets
1177
- * with the value of the property. For instance:
1178
- *
1179
- * ```
1180
- * const myObj = {
1181
- * foo: 'bar',
1182
- * };
1183
- * ```
1184
- *
1185
- * The above snippet would yield a `Source` with the content `bar`.
1186
- *
1187
- */
1188
- extractObjectProperty(key: string): Source[];
1189
- }
1190
-
1191
- /**
1192
- * @public
1193
- */
1194
- type Transformer = (this: TransformContext, source: Source) => Iterable<Source>;
1195
-
1196
- interface SchemaValidationPatch {
1197
- properties?: Record<string, unknown>;
1198
- definitions?: Record<string, unknown>;
1199
- }
1200
- /**
1201
- * @public
1202
- */
1203
- interface Plugin {
1204
- /**
1205
- * Name of the plugin.
1206
- *
1207
- * If specified this is the name used when referring to the plugin. Default is
1208
- * to use the name/path the user used when loading the plugin. To be less
1209
- * confusing for users you should use the same name as your package.
1210
- *
1211
- * The name must be a valid package name according to NPM (basically lowercase
1212
- * characters, must not begin with dot, slash or non-url safe characters).
1213
- *
1214
- * Hint: import and use the name from `package.json`.
1215
- */
1216
- name?: string | null;
1217
- /**
1218
- * Initialization callback.
1219
- *
1220
- * Called once per plugin during initialization.
1221
- */
1222
- init?: () => void | null;
1223
- /**
1224
- * Setup callback.
1225
- *
1226
- * Called once per source after engine is initialized.
1227
- *
1228
- * @param source - The source about to be validated. Readonly.
1229
- * @param eventhandler - Eventhandler from parser. Can be used to listen for
1230
- * parser events.
1231
- */
1232
- setup?: (source: Source, eventhandler: EventHandler) => void | null;
1233
- /**
1234
- * Configuration presets.
1235
- *
1236
- * Each key should be the unprefixed name which a configuration later can
1237
- * access using `${plugin}:${key}`, e.g. if a plugin named "my-plugin" exposes
1238
- * a preset named "foobar" it can be accessed using:
1239
- *
1240
- * "extends": ["my-plugin:foobar"]
1241
- */
1242
- configs?: Record<string, ConfigData | null> | null;
1243
- /**
1244
- * List of new rules present.
1245
- */
1246
- rules?: Record<string, RuleConstructor<any, any> | null> | null;
1247
- /**
1248
- * Transformer available in this plugin.
1249
- *
1250
- * Can be given either as a single unnamed transformer or an object with
1251
- * multiple named.
1252
- *
1253
- * Unnamed transformers use the plugin name similar to how a standalone
1254
- * transformer would work:
1255
- *
1256
- * ```
1257
- * "transform": {
1258
- * "^.*\\.foo$": "my-plugin"
1259
- * }
1260
- * ```
1261
- *
1262
- * For named transformers each key should be the unprefixed name which a
1263
- * configuration later can access using `${plugin}:${key}`, e.g. if a plugin
1264
- * named "my-plugin" exposes a transformer named "foobar" it can be accessed
1265
- * using:
1266
- *
1267
- * ```
1268
- * "transform": {
1269
- * "^.*\\.foo$": "my-plugin:foobar"
1270
- * }
1271
- * ```
1272
- */
1273
- transformer?: Transformer | Record<string, Transformer | null> | null;
1274
- /**
1275
- * Extend metadata validation schema.
1276
- */
1277
- elementSchema?: SchemaValidationPatch | null;
1278
- }
1279
-
1280
- /**
1281
- * Helper function to assist IDE with completion and type-checking.
1282
- *
1283
- * @public
1284
- */
1285
- declare function definePlugin(plugin: Plugin): Plugin;
1286
-
1287
- /**
1288
- * @public
1289
- */
1290
- declare class MetaTable {
1291
- readonly elements: ElementTable;
1292
- private schema;
1293
- /**
1294
- * @internal
1295
- */
1296
- constructor();
1297
- /**
1298
- * @internal
1299
- */
1300
- init(): void;
1301
- /**
1302
- * Extend validation schema.
1303
- *
1304
- * @internal
1305
- */
1306
- extendValidationSchema(patch: SchemaValidationPatch): void;
1307
- /**
1308
- * Load metadata table from object.
1309
- *
1310
- * @internal
1311
- * @param obj - Object with metadata to load
1312
- * @param filename - Optional filename used when presenting validation error
1313
- */
1314
- loadFromObject(obj: unknown, filename?: string | null): void;
1315
- /**
1316
- * Load metadata table from filename
1317
- *
1318
- * @internal
1319
- * @param filename - Filename to load
1320
- */
1321
- loadFromFile(filename: string): void;
1322
- /**
1323
- * Get [[MetaElement]] for the given tag. If no specific metadata is present
1324
- * the global metadata is returned or null if no global is present.
1325
- *
1326
- * @public
1327
- * @returns A shallow copy of metadata.
1328
- */
1329
- getMetaFor(tagName: string): MetaElement | null;
1330
- /**
1331
- * Find all tags which has enabled given property.
1332
- *
1333
- * @public
1334
- */
1335
- getTagsWithProperty(propName: MetaLookupableProperty): string[];
1336
- /**
1337
- * Find tag matching tagName or inheriting from it.
1338
- *
1339
- * @public
1340
- */
1341
- getTagsDerivedFrom(tagName: string): string[];
1342
- private addEntry;
1343
- /**
1344
- * Construct a new AJV schema validator.
1345
- */
1346
- private getSchemaValidator;
1347
- /**
1348
- * @public
1349
- */
1350
- getJSONSchema(): SchemaObject;
1351
- /**
1352
- * Finds the global element definition and merges each known element with the
1353
- * global, e.g. to assign global attributes.
1354
- */
1355
- private resolveGlobal;
1356
- private mergeElement;
1357
- /**
1358
- * @internal
1359
- */
1360
- resolve(node: HtmlElement): void;
1361
- }
1362
-
1363
- /**
1364
- * @internal
1365
- */
1366
- interface EventDump {
1367
- event: string;
1368
- data: any;
1369
- }
1370
- /**
1371
- * @internal
1372
- */
1373
- interface TokenDump {
1374
- token: string;
1375
- data: string;
1376
- location: string;
1377
- }
1378
-
1379
- declare enum NodeType {
1380
- ELEMENT_NODE = 1,
1381
- TEXT_NODE = 3,
1382
- DOCUMENT_NODE = 9
1383
- }
1384
-
1385
- interface DOMNodeCache {
1386
- }
1387
-
1388
- type DOMInternalID = number;
1389
- declare const TEXT_CONTENT: unique symbol;
1390
- declare module "./cache" {
1391
- interface DOMNodeCache {
1392
- [TEXT_CONTENT]: string;
1393
- }
1394
- }
1395
- declare class DOMNode {
1396
- readonly nodeName: string;
1397
- readonly nodeType: NodeType;
1398
- readonly childNodes: DOMNode[];
1399
- readonly location: Location;
1400
- readonly unique: DOMInternalID;
1401
- private cache;
1402
- /**
1403
- * Set of disabled rules for this node.
1404
- *
1405
- * Rules disabled by using directives are added here.
1406
- */
1407
- private disabledRules;
1408
- /**
1409
- * Set of blocked rules for this node.
1410
- *
1411
- * Rules blocked by using directives are added here.
1412
- */
1413
- private blockedRules;
1414
- /**
1415
- * Create a new DOMNode.
1416
- *
1417
- * @param nodeType - What node type to create.
1418
- * @param nodeName - What node name to use. For `HtmlElement` this corresponds
1419
- * to the tagName but other node types have specific predefined values.
1420
- * @param location - Source code location of this node.
1421
- */
1422
- constructor(nodeType: NodeType, nodeName: string | undefined, location: Location);
1423
- /**
1424
- * Enable cache for this node.
1425
- *
1426
- * Should not be called before the node and all children are fully constructed.
1427
- */
1428
- cacheEnable(): void;
1429
- /**
1430
- * Fetch cached value from this DOM node.
1431
- *
1432
- * Cache is not enabled until `cacheEnable()` is called by [[Parser]] (when
1433
- * the element is fully constructed).
1434
- *
1435
- * @returns value or `undefined` if the value doesn't exist.
1436
- */
1437
- cacheGet<K extends keyof DOMNodeCache>(key: K): DOMNodeCache[K] | undefined;
1438
- cacheGet(key: string | number | symbol): any | undefined;
1439
- /**
1440
- * Store a value in cache.
1441
- *
1442
- * @returns the value itself is returned.
1443
- */
1444
- cacheSet<K extends keyof DOMNodeCache>(key: K, value: DOMNodeCache[K]): DOMNodeCache[K];
1445
- cacheSet<T>(key: string | number | symbol, value: T): T;
1446
- /**
1447
- * Remove a value by key from cache.
1448
- *
1449
- * @returns `true` if the entry existed and has been removed.
1450
- */
1451
- cacheRemove<K extends keyof DOMNodeCache>(key: K): boolean;
1452
- cacheRemove(key: string | number | symbol): boolean;
1453
- /**
1454
- * Check if key exists in cache.
1455
- */
1456
- cacheExists<K extends keyof DOMNodeCache>(key: K): boolean;
1457
- cacheExists(key: string | number | symbol): boolean;
1458
- /**
1459
- * Get the text (recursive) from all child nodes.
1460
- */
1461
- get textContent(): string;
1462
- append(node: DOMNode): void;
1463
- isRootElement(): boolean;
1464
- /**
1465
- * Tests if two nodes are the same (references the same object).
1466
- */
1467
- isSameNode(otherNode: DOMNode): boolean;
1468
- /**
1469
- * Returns a DOMNode representing the first direct child node or `null` if the
1470
- * node has no children.
1471
- */
1472
- get firstChild(): DOMNode;
1473
- /**
1474
- * Returns a DOMNode representing the last direct child node or `null` if the
1475
- * node has no children.
1476
- */
1477
- get lastChild(): DOMNode;
1478
- /**
1479
- * Block a rule for this node.
1480
- *
1481
- * @internal
1482
- */
1483
- blockRule(ruleId: string, blocker: RuleBlocker): void;
1484
- /**
1485
- * Blocks multiple rules.
1486
- *
1487
- * @internal
1488
- */
1489
- blockRules(rules: string[] | Set<string>, blocker: RuleBlocker): void;
1490
- /**
1491
- * Disable a rule for this node.
1492
- *
1493
- * @internal
1494
- */
1495
- disableRule(ruleId: string): void;
1496
- /**
1497
- * Disables multiple rules.
1498
- *
1499
- * @internal
1500
- */
1501
- disableRules(rules: string[] | Set<string>): void;
1502
- /**
1503
- * Enable a previously disabled rule for this node.
1504
- */
1505
- enableRule(ruleId: string): void;
1506
- /**
1507
- * Enables multiple rules.
1508
- */
1509
- enableRules(rules: string[]): void;
1510
- /**
1511
- * Test if a rule is enabled for this node.
1512
- *
1513
- * @internal
1514
- */
1515
- ruleEnabled(ruleId: string): boolean;
1516
- /**
1517
- * Test if a rule is blocked for this node.
1518
- *
1519
- * @internal
1520
- */
1521
- ruleBlockers(ruleId: string): RuleBlocker[];
1522
- generateSelector(): string | null;
1523
- }
1524
-
1525
- declare class DOMTokenList extends Array<string> {
1526
- readonly value: string;
1527
- private readonly locations;
1528
- constructor(value: string | DynamicValue | null, location: Location | null);
1529
- item(n: number): string | undefined;
1530
- location(n: number): Location | undefined;
1531
- contains(token: string): boolean;
1532
- iterator(): Generator<{
1533
- index: number;
1534
- item: string;
1535
- location: Location;
1536
- }>;
1537
- }
1538
-
1539
- /**
1540
- * @public
1541
- */
1542
- declare enum NodeClosed {
1543
- Open = 0,
1544
- EndTag = 1,
1545
- VoidOmitted = 2,
1546
- VoidSelfClosed = 3,
1547
- ImplicitClosed = 4
1548
- }
1549
- /**
1550
- * @public
1551
- */
1552
- declare class HtmlElement extends DOMNode {
1553
- readonly tagName: string;
1554
- readonly parent: HtmlElement | null;
1555
- readonly voidElement: boolean;
1556
- readonly depth: number;
1557
- closed: NodeClosed;
1558
- protected readonly attr: {
1559
- [key: string]: Attribute[];
1560
- };
1561
- private metaElement;
1562
- private annotation;
1563
- constructor(tagName: string | undefined, parent: HtmlElement | null, closed: NodeClosed, meta: MetaElement | null, location: Location);
1564
- /**
1565
- * @internal
1566
- */
1567
- static rootNode(location: Location): HtmlElement;
1568
- /**
1569
- * @internal
1570
- *
1571
- * @param namespace - If given it is appended to the tagName.
1572
- */
1573
- static fromTokens(startToken: TagOpenToken, endToken: TagCloseToken, parent: HtmlElement | null, metaTable: MetaTable | null, namespace?: string): HtmlElement;
1574
- /**
1575
- * Returns annotated name if set or defaults to `<tagName>`.
1576
- *
1577
- * E.g. `my-annotation` or `<div>`.
1578
- */
1579
- get annotatedName(): string;
1580
- /**
1581
- * Get list of IDs referenced by `aria-labelledby`.
1582
- *
1583
- * If the attribute is unset or empty this getter returns null.
1584
- * If the attribute is dynamic the original {@link DynamicValue} is returned.
1585
- *
1586
- * @public
1587
- */
1588
- get ariaLabelledby(): string[] | DynamicValue | null;
1589
- /**
1590
- * Similar to childNodes but only elements.
1591
- */
1592
- get childElements(): HtmlElement[];
1593
- /**
1594
- * Find the first ancestor matching a selector.
1595
- *
1596
- * Implementation of DOM specification of Element.closest(selectors).
1597
- */
1598
- closest(selectors: string): HtmlElement | null;
1599
- /**
1600
- * Generate a DOM selector for this element. The returned selector will be
1601
- * unique inside the current document.
1602
- */
1603
- generateSelector(): string | null;
1604
- /**
1605
- * Tests if this element has given tagname.
1606
- *
1607
- * If passing "*" this test will pass if any tagname is set.
1608
- */
1609
- is(tagName: string): boolean;
1610
- /**
1611
- * Load new element metadata onto this element.
1612
- *
1613
- * Do note that semantics such as `void` cannot be changed (as the element has
1614
- * already been created). In addition the element will still "be" the same
1615
- * element, i.e. even if loading meta for a `<p>` tag upon a `<div>` tag it
1616
- * will still be a `<div>` as far as the rest of the validator is concerned.
1617
- *
1618
- * In fact only certain properties will be copied onto the element:
1619
- *
1620
- * - content categories (flow, phrasing, etc)
1621
- * - required attributes
1622
- * - attribute allowed values
1623
- * - permitted/required elements
1624
- *
1625
- * Properties *not* loaded:
1626
- *
1627
- * - inherit
1628
- * - deprecated
1629
- * - foreign
1630
- * - void
1631
- * - implicitClosed
1632
- * - scriptSupporting
1633
- * - deprecatedAttributes
1634
- *
1635
- * Changes to element metadata will only be visible after `element:ready` (and
1636
- * the subsequent `dom:ready` event).
1637
- */
1638
- loadMeta(meta: MetaElement): void;
1639
- /**
1640
- * Match this element against given selectors. Returns true if any selector
1641
- * matches.
1642
- *
1643
- * Implementation of DOM specification of Element.matches(selectors).
1644
- */
1645
- matches(selector: string): boolean;
1646
- get meta(): MetaElement | null;
1647
- /**
1648
- * Set annotation for this element.
1649
- */
1650
- setAnnotation(text: string): void;
1651
- /**
1652
- * Set attribute. Stores all attributes set even with the same name.
1653
- *
1654
- * @param key - Attribute name
1655
- * @param value - Attribute value. Use `null` if no value is present.
1656
- * @param keyLocation - Location of the attribute name.
1657
- * @param valueLocation - Location of the attribute value (excluding quotation)
1658
- * @param originalAttribute - If attribute is an alias for another attribute
1659
- * (dynamic attributes) set this to the original attribute name.
1660
- */
1661
- setAttribute(key: string, value: string | DynamicValue | null, keyLocation: Location, valueLocation: Location | null, originalAttribute?: string): void;
1662
- /**
1663
- * Get a list of all attributes on this node.
1664
- */
1665
- get attributes(): Attribute[];
1666
- hasAttribute(key: string): boolean;
1667
- /**
1668
- * Get attribute.
1669
- *
1670
- * By default only the first attribute is returned but if the code needs to
1671
- * handle duplicate attributes the `all` parameter can be set to get all
1672
- * attributes with given key.
1673
- *
1674
- * This usually only happens when code contains duplicate attributes (which
1675
- * `no-dup-attr` will complain about) or when a static attribute is combined
1676
- * with a dynamic, consider:
1677
- *
1678
- * <p class="foo" dynamic-class="bar">
1679
- *
1680
- * @param key - Attribute name
1681
- * @param all - Return single or all attributes.
1682
- */
1683
- getAttribute(key: string): Attribute | null;
1684
- getAttribute(key: string, all: true): Attribute[];
1685
- /**
1686
- * Get attribute value.
1687
- *
1688
- * Returns the attribute value if present.
1689
- *
1690
- * - Missing attributes return `null`.
1691
- * - Boolean attributes return `null`.
1692
- * - `DynamicValue` returns attribute expression.
1693
- *
1694
- * @param key - Attribute name
1695
- * @returns Attribute value or null.
1696
- */
1697
- getAttributeValue(key: string): string | null;
1698
- /**
1699
- * Add text as a child node to this element.
1700
- *
1701
- * @param text - Text to add.
1702
- * @param location - Source code location of this text.
1703
- */
1704
- appendText(text: string | DynamicValue, location: Location): void;
1705
- /**
1706
- * Return a list of all known classes on the element. Dynamic values are
1707
- * ignored.
1708
- */
1709
- get classList(): DOMTokenList;
1710
- /**
1711
- * Get element ID if present.
1712
- */
1713
- get id(): string | null;
1714
- get style(): CSSStyleDeclaration;
1715
- /**
1716
- * Returns the first child element or null if there are no child elements.
1717
- */
1718
- get firstElementChild(): HtmlElement | null;
1719
- /**
1720
- * Returns the last child element or null if there are no child elements.
1721
- */
1722
- get lastElementChild(): HtmlElement | null;
1723
- get siblings(): HtmlElement[];
1724
- get previousSibling(): HtmlElement | null;
1725
- get nextSibling(): HtmlElement | null;
1726
- getElementsByTagName(tagName: string): HtmlElement[];
1727
- querySelector(selector: string): HtmlElement;
1728
- querySelectorAll(selector: string): HtmlElement[];
1729
- private querySelectorImpl;
1730
- /**
1731
- * Visit all nodes from this node and down. Depth first.
1732
- *
1733
- * @internal
1734
- */
1735
- visitDepthFirst(callback: (node: HtmlElement) => void): void;
1736
- /**
1737
- * Evaluates callbackk on all descendants, returning true if any are true.
1738
- *
1739
- * @internal
1740
- */
1741
- someChildren(callback: (node: HtmlElement) => boolean): boolean;
1742
- /**
1743
- * Evaluates callbackk on all descendants, returning true if all are true.
1744
- *
1745
- * @internal
1746
- */
1747
- everyChildren(callback: (node: HtmlElement) => boolean): boolean;
1748
- /**
1749
- * Visit all nodes from this node and down. Breadth first.
1750
- *
1751
- * The first node for which the callback evaluates to true is returned.
1752
- *
1753
- * @internal
1754
- */
1755
- find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
1756
- }
1757
-
1758
- declare class DOMTree {
1759
- readonly root: HtmlElement;
1760
- private active;
1761
- doctype: string | null;
1762
- constructor(location: Location);
1763
- pushActive(node: HtmlElement): void;
1764
- popActive(): void;
1765
- getActive(): HtmlElement;
1766
- /**
1767
- * Resolve dynamic meta expressions.
1768
- */
1769
- resolveMeta(table: MetaTable): void;
1770
- getElementsByTagName(tagName: string): HtmlElement[];
1771
- visitDepthFirst(callback: (node: HtmlElement) => void): void;
1772
- find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
1773
- querySelector(selector: string): HtmlElement;
1774
- querySelectorAll(selector: string): HtmlElement[];
1775
- }
1776
-
1777
- /**
1778
- * Represents a text in the HTML document.
1779
- *
1780
- * Text nodes are appended as children of `HtmlElement` and cannot have childen
1781
- * of its own.
1782
- *
1783
- * @public
1784
- */
1785
- declare class TextNode extends DOMNode {
1786
- private readonly text;
1787
- /**
1788
- * @param text - Text to add. When a `DynamicValue` is used the expression is
1789
- * used as "text".
1790
- * @param location - Source code location of this node.
1791
- */
1792
- constructor(text: string | DynamicValue, location: Location);
1793
- /**
1794
- * Get the text from node.
1795
- */
1796
- get textContent(): string;
1797
- /**
1798
- * Flag set to true if the attribute value is static.
1799
- */
1800
- get isStatic(): boolean;
1801
- /**
1802
- * Flag set to true if the attribute value is dynamic.
1803
- */
1804
- get isDynamic(): boolean;
1805
- }
1806
-
1807
- interface PermittedGroup {
1808
- exclude?: string | string[];
1809
- }
1810
- type CategoryOrTag = string;
1811
- type PropertyExpression = string | [string, any];
1812
- type PermittedEntry = CategoryOrTag | PermittedGroup | Array<CategoryOrTag | PermittedGroup>;
1813
- type Permitted = PermittedEntry[];
1814
- type PermittedOrder = string[];
1815
- type RequiredAncestors = string[];
1816
- type RequiredContent = string[];
1817
- declare enum TextContent {
1818
- NONE = "none",
1819
- DEFAULT = "default",
1820
- REQUIRED = "required",
1821
- ACCESSIBLE = "accessible"
1822
- }
1823
- /**
1824
- * Callback for the `allowed` property of `MetaAttribute`. It takes a node and
1825
- * should return `null` if there is no errors and a string with an error
1826
- * description if there is an error.
1827
- *
1828
- * @public
1829
- * @param node - The node the attribute belongs to.
1830
- * @param attr - The current attribute being validated.
1831
- */
1832
- type MetaAttributeAllowedCallback = (node: HtmlElement, attr: Attribute) => string | null | undefined;
1833
- /**
1834
- * @public
1835
- */
1836
- interface MetaAttribute {
1837
- allowed?: MetaAttributeAllowedCallback;
1838
- boolean?: boolean;
1839
- deprecated?: boolean | string;
1840
- enum?: Array<string | RegExp>;
1841
- list?: boolean;
1842
- omit?: boolean;
1843
- required?: boolean;
1844
- }
1845
- type PermittedAttribute = Record<string, MetaAttribute | Array<string | RegExp> | null>;
1846
- interface DeprecatedElement {
1847
- message?: string;
1848
- documentation?: string;
1849
- source?: string;
1850
- }
1851
- interface FormAssociated {
1852
- /** Listed elements have a name attribute and is listed in the form and fieldset elements property. */
1853
- listed: boolean;
1854
- }
1855
- /**
1856
- * @public
1857
- */
1858
- interface MetaData {
1859
- inherit?: string;
1860
- metadata?: boolean | PropertyExpression;
1861
- flow?: boolean | PropertyExpression;
1862
- sectioning?: boolean | PropertyExpression;
1863
- heading?: boolean | PropertyExpression;
1864
- phrasing?: boolean | PropertyExpression;
1865
- embedded?: boolean | PropertyExpression;
1866
- interactive?: boolean | PropertyExpression;
1867
- deprecated?: boolean | string | DeprecatedElement;
1868
- foreign?: boolean;
1869
- void?: boolean;
1870
- transparent?: boolean | string[];
1871
- implicitClosed?: string[];
1872
- scriptSupporting?: boolean;
1873
- form?: boolean;
1874
- /** Mark element as a form-associated element */
1875
- formAssociated?: Partial<FormAssociated>;
1876
- labelable?: boolean | PropertyExpression;
1877
- deprecatedAttributes?: string[];
1878
- requiredAttributes?: string[];
1879
- attributes?: PermittedAttribute;
1880
- permittedContent?: Permitted;
1881
- permittedDescendants?: Permitted;
1882
- permittedOrder?: PermittedOrder;
1883
- permittedParent?: Permitted;
1884
- requiredAncestors?: RequiredAncestors;
1885
- requiredContent?: RequiredContent;
1886
- textContent?: TextContent | `${TextContent}`;
1887
- }
1888
- /**
1889
- * Properties listed here can be used to reverse search elements with the given
1890
- * property enabled. See [[MetaTable.getTagsWithProperty]].
1891
- */
1892
- type MetaLookupableProperty = "metadata" | "flow" | "sectioning" | "heading" | "phrasing" | "embedded" | "interactive" | "deprecated" | "foreign" | "void" | "transparent" | "scriptSupporting" | "form" | "formAssociated" | "labelable";
1893
- /**
1894
- * Properties listed here can be copied (loaded) onto another element using
1895
- * [[HtmlElement.loadMeta]].
1896
- *
1897
- * @public
1898
- */
1899
- declare const MetaCopyableProperty: Array<keyof MetaElement>;
1900
- /**
1901
- * @public
1902
- */
1903
- interface MetaElement extends Omit<MetaData, "deprecatedAttributes" | "requiredAttributes"> {
1904
- tagName: string;
1905
- formAssociated?: FormAssociated;
1906
- attributes: Record<string, MetaAttribute>;
1907
- textContent?: TextContent;
1908
- }
1909
- interface MetaDataTable {
1910
- [tagName: string]: MetaData;
1911
- }
1912
- interface ElementTable {
1913
- [tagName: string]: MetaElement;
1914
- }
1915
-
1916
- /**
1917
- * Helper class to validate elements against metadata rules.
1918
- *
1919
- * @public
1920
- */
1921
- declare class Validator {
1922
- /**
1923
- * Test if element is used in a proper context.
1924
- *
1925
- * @param node - Element to test.
1926
- * @param rules - List of rules.
1927
- * @returns `true` if element passes all tests.
1928
- */
1929
- static validatePermitted(node: HtmlElement, rules: Permitted | null): boolean;
1930
- /**
1931
- * Test if an element is used the correct amount of times.
1932
- *
1933
- * For instance, a `<table>` element can only contain a single `<tbody>`
1934
- * child. If multiple `<tbody>` exists this test will fail both nodes.
1935
- * Note that this is called on the parent but will fail the children violating
1936
- * the rule.
1937
- *
1938
- * @param children - Array of children to validate.
1939
- * @param rules - List of rules of the parent element.
1940
- * @returns `true` if the parent element of the children passes the test.
1941
- */
1942
- static validateOccurrences(children: HtmlElement[], rules: Permitted | null, cb: (node: HtmlElement, category: string) => void): boolean;
1943
- /**
1944
- * Validate elements order.
1945
- *
1946
- * Given a parent element with children and metadata containing permitted
1947
- * order it will validate each children and ensure each one exists in the
1948
- * specified order.
1949
- *
1950
- * For instance, for a `<table>` element the `<caption>` element must come
1951
- * before a `<thead>` which must come before `<tbody>`.
1952
- *
1953
- * @param children - Array of children to validate.
1954
- */
1955
- static validateOrder(children: HtmlElement[], rules: PermittedOrder | null, cb: (node: HtmlElement, prev: HtmlElement) => void): boolean;
1956
- /**
1957
- * Validate element ancestors.
1958
- *
1959
- * Check if an element has the required set of elements. At least one of the
1960
- * selectors must match.
1961
- */
1962
- static validateAncestors(node: HtmlElement, rules: RequiredAncestors | null): boolean;
1963
- /**
1964
- * Validate element required content.
1965
- *
1966
- * Check if an element has the required set of elements. At least one of the
1967
- * selectors must match.
1968
- *
1969
- * Returns `[]` when valid or a list of required but missing tagnames or
1970
- * categories.
1971
- */
1972
- static validateRequiredContent(node: HtmlElement, rules: RequiredContent | null): CategoryOrTag[];
1973
- /**
1974
- * Test if an attribute has an allowed value and/or format.
1975
- *
1976
- * @param attr - Attribute to test.
1977
- * @param rules - Element attribute metadta.
1978
- * @returns `true` if attribute passes all tests.
1979
- */
1980
- static validateAttribute(attr: Attribute, rules: Record<string, MetaAttribute>): boolean;
1981
- private static validateAttributeValue;
1982
- private static validatePermittedRule;
1983
- /**
1984
- * Validate node against a content category.
1985
- *
1986
- * When matching parent nodes against permitted parents use the superset
1987
- * parameter to also match for `@flow`. E.g. if a node expects a `@phrasing`
1988
- * parent it should also allow `@flow` parent since `@phrasing` is a subset of
1989
- * `@flow`.
1990
- *
1991
- * @param node - The node to test against
1992
- * @param category - Name of category with `@` prefix or tag name.
1993
- * @param defaultMatch - The default return value when node categories is not known.
1994
- */
1995
- static validatePermittedCategory(node: HtmlElement, category: string, defaultMatch: boolean): boolean;
1996
- }
1997
-
1998
- /**
1999
- * @public
2000
- */
2001
- declare enum Severity {
2002
- DISABLED = 0,
2003
- WARN = 1,
2004
- ERROR = 2
2005
- }
2006
-
2007
- interface TransformerEntry {
2008
- pattern: RegExp;
2009
- name: string;
2010
- fn: Transformer;
2011
- }
2012
- interface ResolvedConfigData {
2013
- metaTable: MetaTable;
2014
- plugins: Plugin[];
2015
- rules: Map<string, [Severity, RuleOptions]>;
2016
- transformers: TransformerEntry[];
2017
- }
2018
- /**
2019
- * A resolved configuration is a normalized configuration with all extends,
2020
- * plugins etc resolved.
2021
- */
2022
- declare class ResolvedConfig {
2023
- private metaTable;
2024
- private plugins;
2025
- private rules;
2026
- private transformers;
2027
- constructor({ metaTable, plugins, rules, transformers }: ResolvedConfigData);
2028
- getMetaTable(): MetaTable;
2029
- getPlugins(): Plugin[];
2030
- getRules(): Map<string, [Severity, RuleOptions]>;
2031
- /**
2032
- * Transform a source.
2033
- *
2034
- * When transforming zero or more new sources will be generated.
2035
- *
2036
- * @param source - Current source to transform.
2037
- * @param filename - If set it is the filename used to match
2038
- * transformer. Default is to use filename from source.
2039
- * @returns A list of transformed sources ready for validation.
2040
- */
2041
- transformSource(source: Source, filename?: string): Source[];
2042
- /**
2043
- * Wrapper around [[transformSource]] which reads a file before passing it
2044
- * as-is to transformSource.
2045
- *
2046
- * @param filename - Filename to transform (according to configured
2047
- * transformations)
2048
- * @returns A list of transformed sources ready for validation.
2049
- */
2050
- transformFilename(filename: string): Source[];
2051
- /**
2052
- * Returns true if a transformer matches given filename.
2053
- */
2054
- canTransform(filename: string): boolean;
2055
- private findTransformer;
2056
- }
2057
-
2058
- /**
2059
- * Internal interface for a loaded plugin.
2060
- */
2061
- interface LoadedPlugin extends Plugin {
2062
- name: string;
2063
- originalName: string;
2064
- }
2065
- /**
2066
- * Configuration holder.
2067
- *
2068
- * Each file being validated will have a unique instance of this class.
2069
- *
2070
- * @public
2071
- */
2072
- declare class Config {
2073
- private config;
2074
- private configurations;
2075
- private initialized;
2076
- protected metaTable: MetaTable | null;
2077
- protected plugins: LoadedPlugin[];
2078
- protected transformers: TransformerEntry[];
2079
- protected rootDir: string;
2080
- /**
2081
- * Create a new blank configuration. See also `Config.defaultConfig()`.
2082
- */
2083
- static empty(): Config;
2084
- /**
2085
- * Create configuration from object.
2086
- */
2087
- static fromObject(options: ConfigData, filename?: string | null): Config;
2088
- /**
2089
- * Read configuration from filename.
2090
- *
2091
- * Note: this reads configuration data from a file. If you intent to load
2092
- * configuration for a file to validate use `ConfigLoader.fromTarget()`.
2093
- *
2094
- * @param filename - The file to read from or one of the presets such as
2095
- * `html-validate:recommended`.
2096
- */
2097
- static fromFile(filename: string): Config;
2098
- /**
2099
- * Validate configuration data.
2100
- *
2101
- * Throws SchemaValidationError if invalid.
2102
- *
2103
- * @internal
2104
- */
2105
- static validate(configData: ConfigData, filename?: string | null): void;
2106
- /**
2107
- * Load a default configuration object.
2108
- */
2109
- static defaultConfig(): Config;
2110
- /**
2111
- * @internal
2112
- */
2113
- constructor(options?: ConfigData);
2114
- /**
2115
- * Initialize plugins, transforms etc.
2116
- *
2117
- * Must be called before trying to use config. Can safely be called multiple
2118
- * times.
2119
- *
2120
- * @internal
2121
- */
2122
- init(): void;
2123
- /**
2124
- * Returns true if this configuration is marked as "root".
2125
- */
2126
- isRootFound(): boolean;
2127
- /**
2128
- * Returns a new configuration as a merge of the two. Entries from the passed
2129
- * object takes priority over this object.
2130
- *
2131
- * @internal
2132
- * @param rhs - Configuration to merge with this one.
2133
- */
2134
- merge(rhs: Config): Config;
2135
- private extendConfig;
2136
- /**
2137
- * Get element metadata.
2138
- */
2139
- getMetaTable(): MetaTable;
2140
- /**
2141
- * @internal exposed for testing only
2142
- */
2143
- static expandRelative(src: string, currentPath: string): string;
2144
- /**
2145
- * Get a copy of internal configuration data.
2146
- *
2147
- * @internal primary purpose is unittests
2148
- */
2149
- get(): ConfigData;
2150
- /**
2151
- * Get all configured rules, their severity and options.
2152
- *
2153
- * @internal
2154
- */
2155
- getRules(): Map<string, [Severity, RuleOptions]>;
2156
- private static getRulesObject;
2157
- /**
2158
- * Get all configured plugins.
2159
- *
2160
- * @internal
2161
- */
2162
- getPlugins(): Plugin[];
2163
- private loadPlugins;
2164
- private loadConfigurations;
2165
- private extendMeta;
2166
- /**
2167
- * Resolve all configuration and return a [[ResolvedConfig]] instance.
2168
- *
2169
- * A resolved configuration will merge all extended configs and load all
2170
- * plugins and transformers, and normalize the rest of the configuration.
2171
- *
2172
- * @internal
2173
- */
2174
- resolve(): ResolvedConfig;
2175
- /**
2176
- * Same as [[resolve]] but returns the raw configuration data instead of
2177
- * [[ResolvedConfig]] instance. Mainly used for testing.
2178
- *
2179
- * @internal
2180
- */
2181
- resolveData(): ResolvedConfigData;
2182
- private precompileTransformers;
2183
- /**
2184
- * Get transformation function requested by configuration.
2185
- *
2186
- * Searches:
2187
- *
2188
- * - Named transformers from plugins.
2189
- * - Unnamed transformer from plugin.
2190
- * - Standalone modules (local or node_modules)
2191
- *
2192
- * @param name - Key from configuration
2193
- */
2194
- private getTransformFunction;
2195
- /**
2196
- * @param name - Original name from configuration
2197
- * @param pluginName - Name of plugin
2198
- * @param key - Name of transform (from plugin)
2199
- */
2200
- private getNamedTransformerFromPlugin;
2201
- /**
2202
- * @param name - Original name from configuration
2203
- * @param plugin - Plugin instance
2204
- */
2205
- private getUnnamedTransformerFromPlugin;
2206
- private getTransformerFromModule;
2207
- /**
2208
- * @internal
2209
- */
2210
- protected get rootDirCache(): string | null;
2211
- protected set rootDirCache(value: string | null);
2212
- protected findRootDir(): string;
2213
- }
2214
-
2215
- /**
2216
- * @internal
2217
- */
2218
- interface ConfigFactory {
2219
- defaultConfig(): Config;
2220
- empty(): Config;
2221
- fromObject(options: ConfigData, filename?: string | null): Config;
2222
- fromFile(filename: string): Config;
2223
- }
2224
- /**
2225
- * Configuration loader interface.
2226
- *
2227
- * A configuration loader takes a handle (typically a filename) and returns a
2228
- * configuration for it.
2229
- *
2230
- * @public
2231
- */
2232
- declare abstract class ConfigLoader {
2233
- protected readonly configFactory: ConfigFactory;
2234
- protected readonly globalConfig: Config;
2235
- constructor(config?: ConfigData, configFactory?: ConfigFactory);
2236
- /**
2237
- * Get configuration for given handle.
2238
- *
2239
- * Handle is typically a filename but it is up to the loader to interpret the
2240
- * handle as something useful.
2241
- *
2242
- * If [[configOverride]] is set it is merged with the final result.
2243
- *
2244
- * @param handle - Unique handle to get configuration for.
2245
- * @param configOverride - Optional configuration to merge final results with.
2246
- */
2247
- abstract getConfigFor(handle: string, configOverride?: ConfigData): Config;
2248
- /**
2249
- * Flush configuration cache.
2250
- *
2251
- * Flushes all cached entries unless a specific handle is given.
2252
- *
2253
- * @param handle - If given only the cache for given handle will be flushed.
2254
- */
2255
- abstract flushCache(handle?: string): void;
2256
- /**
2257
- * Default configuration used when no explicit configuration is passed to constructor.
2258
- */
2259
- protected abstract defaultConfig(): Config;
2260
- protected empty(): Config;
2261
- protected loadFromObject(options: ConfigData, filename?: string | null): Config;
2262
- protected loadFromFile(filename: string): Config;
2263
- }
2264
-
2265
- declare class NestedError extends Error {
2266
- constructor(message: string, nested?: Error);
2267
- }
2268
-
2269
- /**
2270
- * @public
2271
- */
2272
- declare class UserError extends NestedError {
2273
- constructor(message: string, nested?: Error);
2274
- /**
2275
- * @public
2276
- */
2277
- prettyFormat(): string | undefined;
2278
- }
2279
-
2280
- /**
2281
- * @public
2282
- */
2283
- declare class SchemaValidationError extends UserError {
2284
- filename: string | null;
2285
- private obj;
2286
- private schema;
2287
- private errors;
2288
- constructor(filename: string | null, message: string, obj: unknown, schema: SchemaObject, errors: ErrorObject[]);
2289
- prettyError(): string;
2290
- private getRawJSON;
2291
- }
2292
-
2293
- /**
2294
- * Represents an `Error` created from arbitrary values.
2295
- *
2296
- * @public
2297
- */
2298
- declare class WrappedError<T> extends Error {
2299
- constructor(message: T);
2300
- }
2301
-
2302
- /**
2303
- * @public
2304
- */
2305
- declare class ConfigError extends UserError {
2306
- constructor(message: string, nested?: Error);
2307
- }
2308
-
2309
- /**
2310
- * @internal
2311
- */
2312
- declare const presets: Record<string, ConfigData>;
2313
-
2314
- /**
2315
- * Primary API for using HTML-validate.
2316
- *
2317
- * Provides high-level abstractions for common operations.
2318
- *
2319
- * @public
2320
- */
2321
- declare class HtmlValidate {
2322
- protected configLoader: ConfigLoader;
2323
- /**
2324
- * Create a new validator.
2325
- *
2326
- * @public
2327
- * @param configLoader - Use a custom configuration loader.
2328
- * @param config - If set it provides the global default configuration. By
2329
- * default `Config.defaultConfig()` is used.
2330
- */
2331
- constructor(config?: ConfigData);
2332
- constructor(configLoader: ConfigLoader);
2333
- /**
2334
- * Parse and validate HTML from string.
2335
- *
2336
- * @public
2337
- * @param str - Text to parse.
2338
- * @param filename - If set configuration is loaded for given filename.
2339
- * @param hooks - Optional hooks (see [[Source]]) for definition.
2340
- * @returns Report output.
2341
- */
2342
- validateString(str: string): Report;
2343
- validateString(str: string, filename: string): Report;
2344
- validateString(str: string, hooks: SourceHooks): Report;
2345
- validateString(str: string, options: ConfigData): Report;
2346
- validateString(str: string, filename: string, hooks: SourceHooks): Report;
2347
- validateString(str: string, filename: string, options: ConfigData): Report;
2348
- validateString(str: string, filename: string, options: ConfigData, hooks: SourceHooks): Report;
2349
- /**
2350
- * Parse and validate HTML from [[Source]].
2351
- *
2352
- * @public
2353
- * @param input - Source to parse.
2354
- * @returns Report output.
2355
- */
2356
- validateSource(input: Source, configOverride?: ConfigData): Report;
2357
- /**
2358
- * Parse and validate HTML from file.
2359
- *
2360
- * @public
2361
- * @param filename - Filename to read and parse.
2362
- * @returns Report output.
2363
- */
2364
- validateFile(filename: string): Report;
2365
- /**
2366
- * Parse and validate HTML from multiple files. Result is merged together to a
2367
- * single report.
2368
- *
2369
- * @param filenames - Filenames to read and parse.
2370
- * @returns Report output.
2371
- */
2372
- validateMultipleFiles(filenames: string[]): Report;
2373
- /**
2374
- * Returns true if the given filename can be validated.
2375
- *
2376
- * A file is considered to be validatable if the extension is `.html` or if a
2377
- * transformer matches the filename.
2378
- *
2379
- * This is mostly useful for tooling to determine whenever to validate the
2380
- * file or not. CLI tools will run on all the given files anyway.
2381
- */
2382
- canValidate(filename: string): boolean;
2383
- /**
2384
- * Tokenize filename and output all tokens.
2385
- *
2386
- * Using CLI this is enabled with `--dump-tokens`. Mostly useful for
2387
- * debugging.
2388
- *
2389
- * @param filename - Filename to tokenize.
2390
- */
2391
- dumpTokens(filename: string): TokenDump[];
2392
- /**
2393
- * Parse filename and output all events.
2394
- *
2395
- * Using CLI this is enabled with `--dump-events`. Mostly useful for
2396
- * debugging.
2397
- *
2398
- * @param filename - Filename to dump events from.
2399
- */
2400
- dumpEvents(filename: string): EventDump[];
2401
- /**
2402
- * Parse filename and output DOM tree.
2403
- *
2404
- * Using CLI this is enabled with `--dump-tree`. Mostly useful for
2405
- * debugging.
2406
- *
2407
- * @param filename - Filename to dump DOM tree from.
2408
- */
2409
- dumpTree(filename: string): string[];
2410
- /**
2411
- * Transform filename and output source data.
2412
- *
2413
- * Using CLI this is enabled with `--dump-source`. Mostly useful for
2414
- * debugging.
2415
- *
2416
- * @param filename - Filename to dump source from.
2417
- */
2418
- dumpSource(filename: string): string[];
2419
- /**
2420
- * Get effective configuration schema.
2421
- */
2422
- getConfigurationSchema(): SchemaObject;
2423
- /**
2424
- * Get effective metadata element schema.
2425
- *
2426
- * If a filename is given the configured plugins can extend the
2427
- * schema. Filename must not be an existing file or a filetype normally
2428
- * handled by html-validate but the path will be used when resolving
2429
- * configuration. As a rule-of-thumb, set it to the elements json file.
2430
- */
2431
- getElementsSchema(filename?: string): SchemaObject;
2432
- /**
2433
- * Get contextual documentation for the given rule.
2434
- *
2435
- * Typical usage:
2436
- *
2437
- * ```js
2438
- * const report = htmlvalidate.validateFile("my-file.html");
2439
- * for (const result of report.results){
2440
- * const config = htmlvalidate.getConfigFor(result.filePath);
2441
- * for (const message of result.messages){
2442
- * const documentation = htmlvalidate.getRuleDocumentation(message.ruleId, config, message.context);
2443
- * // do something with documentation
2444
- * }
2445
- * }
2446
- * ```
2447
- *
2448
- * @param ruleId - Rule to get documentation for.
2449
- * @param config - If set it provides more accurate description by using the
2450
- * correct configuration for the file.
2451
- * @param context - If set to `Message.context` some rules can provide
2452
- * contextual details and suggestions.
2453
- */
2454
- getRuleDocumentation(ruleId: string, config?: Config | null, context?: any | null): RuleDocumentation | null;
2455
- /**
2456
- * Create a parser configured for given filename.
2457
- *
2458
- * @internal
2459
- * @param source - Source to use.
2460
- */
2461
- getParserFor(source: Source): Parser;
2462
- /**
2463
- * Get configuration for given filename.
2464
- *
2465
- * See [[FileSystemConfigLoader]] for details.
2466
- *
2467
- * @public
2468
- * @param filename - Filename to get configuration for.
2469
- * @param configOverride - Configuration to apply last.
2470
- */
2471
- getConfigFor(filename: string, configOverride?: ConfigData): Config;
2472
- /**
2473
- * Flush configuration cache. Clears full cache unless a filename is given.
2474
- *
2475
- * See [[FileSystemConfigLoader]] for details.
2476
- *
2477
- * @public
2478
- * @param filename - If set, only flush cache for given filename.
2479
- */
2480
- flushConfigCache(filename?: string): void;
2481
- }
2482
-
2483
- /**
2484
- * The static configuration loader does not do any per-handle lookup. Only the
2485
- * global or per-call configuration is used.
2486
- *
2487
- * In practice this means no configuration is fetch by traversing the
2488
- * filesystem.
2489
- *
2490
- * @public
2491
- */
2492
- declare class StaticConfigLoader extends ConfigLoader {
2493
- getConfigFor(handle: string, configOverride?: ConfigData): Config;
2494
- flushCache(): void;
2495
- protected defaultConfig(): Config;
2496
- }
2497
-
2498
- /** @public */
2499
- declare const version: string;
2500
-
2501
- /**
2502
- * @public
2503
- */
2504
- interface CompatibilityOptions {
2505
- /** If `true` nothing no output will be generated on console. Default: `false` */
2506
- silent: boolean;
2507
- /** Use this version number instead of running version. Default: running version */
2508
- version: string;
2509
- /** Use custom logging callback. Default: `console.error` */
2510
- logger(message: string): void;
2511
- }
2512
- /**
2513
- * Tests if plugin is compatible with html-validate library. Unless the `silent`
2514
- * option is used a warning is displayed on the console.
2515
- *
2516
- * @public
2517
- * @param name - Name of plugin
2518
- * @param declared - What library versions the plugin support (e.g. declared peerDependencies)
2519
- * @returns - `true` if version is compatible
2520
- */
2521
- declare function compatibilityCheck(name: string, declared: string, options?: Partial<CompatibilityOptions>): boolean;
2522
-
2523
- /**
2524
- * Returns true if given ruleId is an existing builtin rule. It does not handle
2525
- * rules loaded via plugins.
2526
- *
2527
- * Can be used to create forward/backward compatibility by checking if a rule
2528
- * exists to enable/disable it.
2529
- *
2530
- * @public
2531
- * @param ruleId - Rule id to check
2532
- * @returns `true` if rule exists
2533
- */
2534
- declare function ruleExists(ruleId: string): boolean;
2535
-
2536
- /**
2537
- * Loads configuration by traversing filesystem.
2538
- *
2539
- * Configuration is read from three sources and in the following order:
2540
- *
2541
- * 1. Global configuration passed to constructor.
2542
- * 2. Configuration files found when traversing the directory structure.
2543
- * 3. Override passed to this function.
2544
- *
2545
- * The following configuration filenames are searched:
2546
- *
2547
- * - `.htmlvalidate.json`
2548
- * - `.htmlvalidate.js`
2549
- * - `.htmlvalidate.cjs`
2550
- *
2551
- * Global configuration is used when no configuration file is found. The
2552
- * result is always merged with override if present.
2553
- *
2554
- * The `root` property set to `true` affects the configuration as following:
2555
- *
2556
- * 1. If set in override the override is returned as-is.
2557
- * 2. If set in the global config the override is merged into global and
2558
- * returned. No configuration files are searched.
2559
- * 3. Setting `root` in configuration file only stops directory traversal.
2560
- *
2561
- * @public
2562
- */
2563
- declare class FileSystemConfigLoader extends ConfigLoader {
2564
- protected cache: Map<string, Config | null>;
2565
- /**
2566
- * @param config - Global configuration
2567
- * @param configFactory - Optional configuration factory
2568
- */
2569
- constructor(config?: ConfigData, configFactory?: ConfigFactory);
2570
- /**
2571
- * Get configuration for given filename.
2572
- *
2573
- * @param filename - Filename to get configuration for.
2574
- * @param configOverride - Configuration to merge final result with.
2575
- */
2576
- getConfigFor(filename: string, configOverride?: ConfigData): Config;
2577
- /**
2578
- * Flush configuration cache.
2579
- *
2580
- * @param filename - If given only the cache for that file is flushed.
2581
- */
2582
- flushCache(filename?: string): void;
2583
- /**
2584
- * Load raw configuration from directory traversal.
2585
- *
2586
- * This configuration is not merged with global configuration and may return
2587
- * `null` if no configuration files are found.
2588
- */
2589
- fromFilename(filename: string): Config | null;
2590
- protected defaultConfig(): Config;
2591
- }
2592
-
2593
- /**
2594
- * @public
2595
- */
2596
- type Formatter = (results: Result[]) => string;
2597
-
2598
- interface AvailableFormatters {
2599
- checkstyle: Formatter;
2600
- codeframe: Formatter;
2601
- json: Formatter;
2602
- stylish: Formatter;
2603
- text: Formatter;
2604
- }
2605
- /**
2606
- * Get formatter function by name.
2607
- *
2608
- * @internal
2609
- * @param name - Name of formatter.
2610
- * @returns Formatter function or null if it doesn't exist.
2611
- */
2612
- declare function getFormatter(name: keyof AvailableFormatters): Formatter;
2613
- declare function getFormatter(name: string): Formatter | null;
2614
-
2615
- export { EventHandler as $, AttributeData as A, Reporter as B, Config as C, DynamicValue as D, EventDump as E, Message as F, Result as G, HtmlValidate as H, DeferredMessage as I, TransformContext as J, Transformer as K, Location as L, MetaData as M, NodeClosed as N, TemplateExtractor as O, ProcessAttributeCallback as P, Plugin as Q, Rule as R, Severity as S, TextNode as T, UserError as U, Validator as V, WrappedError as W, SchemaValidationPatch as X, definePlugin as Y, Parser as Z, ruleExists as _, ConfigData as a, EventCallback as a0, Event as a1, ConfigReadyEvent as a2, SourceReadyEvent as a3, TokenEvent as a4, TagStartEvent as a5, TagOpenEvent as a6, TagEndEvent as a7, TagCloseEvent as a8, TagReadyEvent as a9, ElementReadyEvent as aa, AttributeEvent as ab, WhitespaceEvent as ac, ConditionalEvent as ad, DirectiveEvent as ae, DoctypeEvent as af, DOMLoadEvent as ag, DOMReadyEvent as ah, RuleErrorEvent as ai, ParseBeginEvent as aj, ParseEndEvent as ak, TriggerEventMap as al, ListenEventMap as am, FileSystemConfigLoader as an, Formatter as ao, getFormatter as ap, compatibilityCheck as aq, CompatibilityOptions as ar, ConfigError as b, ConfigLoader as c, StaticConfigLoader as d, Attribute as e, HtmlElement as f, CSSStyleDeclaration as g, TokenDump as h, SchemaValidationError as i, NestedError as j, MetaDataTable as k, MetaElement as l, MetaAttribute as m, MetaAttributeAllowedCallback as n, MetaTable as o, presets as p, MetaCopyableProperty as q, RuleConstructor as r, RuleDocumentation as s, Source as t, SourceHooks as u, version as v, ProcessElementCallback as w, ProcessElementContext as x, sliceLocation as y, Report as z };
1
+ import { ErrorObject } from 'ajv';
2
+ import { SchemaObject } from 'ajv';
3
+
4
+ /**
5
+ * DOM Attribute.
6
+ *
7
+ * Represents a HTML attribute. Can contain either a fixed static value or a
8
+ * placeholder for dynamic values (e.g. interpolated).
9
+ *
10
+ * @public
11
+ */
12
+ export declare class Attribute {
13
+ /** Attribute name */
14
+ readonly key: string;
15
+ readonly value: string | DynamicValue | null;
16
+ readonly keyLocation: Location_2;
17
+ readonly valueLocation: Location_2 | null;
18
+ readonly originalAttribute?: string;
19
+ /**
20
+ * @param key - Attribute name.
21
+ * @param value - Attribute value. Set to `null` for boolean attributes.
22
+ * @param keyLocation - Source location of attribute name.
23
+ * @param valueLocation - Source location of attribute value.
24
+ * @param originalAttribute - If this attribute was dynamically added via a
25
+ * transformation (e.g. vuejs `:id` generating the `id` attribute) this
26
+ * parameter should be set to the attribute name of the source attribute (`:id`).
27
+ */
28
+ constructor(key: string, value: null | string | DynamicValue | null, keyLocation: Location_2, valueLocation: Location_2 | null, originalAttribute?: string);
29
+ /**
30
+ * Flag set to true if the attribute value is static.
31
+ */
32
+ get isStatic(): boolean;
33
+ /**
34
+ * Flag set to true if the attribute value is dynamic.
35
+ */
36
+ get isDynamic(): boolean;
37
+ /**
38
+ * Test attribute value.
39
+ *
40
+ * @param pattern - Pattern to match value against. Can be a RegExp, literal
41
+ * string or an array of strings (returns true if any value matches the
42
+ * array).
43
+ * @param dynamicMatches - If true `DynamicValue` will always match, if false
44
+ * it never matches.
45
+ * @returns `true` if attribute value matches pattern.
46
+ */
47
+ valueMatches(pattern: RegExp, dynamicMatches?: boolean): boolean;
48
+ valueMatches(pattern: string, dynamicMatches?: boolean): boolean;
49
+ valueMatches(pattern: string[], dynamicMatches?: boolean): boolean;
50
+ }
51
+
52
+ /**
53
+ * Raw attribute data.
54
+ *
55
+ * @public
56
+ */
57
+ export declare interface AttributeData {
58
+ /** Attribute name */
59
+ key: string;
60
+ /** Attribute value */
61
+ value: string | DynamicValue | null;
62
+ /** Quotation mark (if present) */
63
+ quote: '"' | "'" | null;
64
+ /** Original attribute name (when a dynamic attribute is used), e.g
65
+ * "ng-attr-foo" or "v-bind:foo" */
66
+ originalAttribute?: string;
67
+ }
68
+
69
+ /**
70
+ * Event emitted when attributes are encountered.
71
+ *
72
+ * @public
73
+ */
74
+ export declare interface AttributeEvent extends Event_2 {
75
+ /** Location of the full attribute (key, quotes and value) */
76
+ location: Location_2;
77
+ /** Attribute name. */
78
+ key: string;
79
+ /** Attribute value. */
80
+ value: string | DynamicValue | null;
81
+ /** Quotemark used. */
82
+ quote: '"' | "'" | null;
83
+ /** Set to original attribute when a transformer dynamically added this
84
+ * attribute. */
85
+ originalAttribute?: string;
86
+ /** HTML element this attribute belongs to. */
87
+ target: HtmlElement;
88
+ /** Location of the attribute key */
89
+ keyLocation: Location_2;
90
+ /** Location of the attribute value */
91
+ valueLocation: Location_2 | null;
92
+ }
93
+
94
+ /* Excluded from this release type: AttrNameToken */
95
+
96
+ /* Excluded from this release type: AttrValueToken */
97
+
98
+ /**
99
+ * @public
100
+ */
101
+ export declare interface AvailableFormatters {
102
+ checkstyle: Formatter;
103
+ codeframe: Formatter;
104
+ json: Formatter;
105
+ stylish: Formatter;
106
+ text: Formatter;
107
+ }
108
+
109
+ /* Excluded from this release type: BaseToken */
110
+
111
+ /**
112
+ * @public
113
+ */
114
+ export declare type CategoryOrTag = string;
115
+
116
+ /**
117
+ * Checks text content of an element.
118
+ *
119
+ * Any text is considered including text from descendant elements. Whitespace is
120
+ * ignored.
121
+ *
122
+ * If any text is dynamic `TextClassification.DYNAMIC_TEXT` is returned.
123
+ *
124
+ * @public
125
+ */
126
+ export declare function classifyNodeText(node: HtmlElement, options?: TextClassificationOptions): TextClassification;
127
+
128
+ /**
129
+ * @public
130
+ */
131
+ export declare class CLI {
132
+ private options;
133
+ private config;
134
+ private loader;
135
+ private ignored;
136
+ /**
137
+ * Create new CLI helper.
138
+ *
139
+ * Can be used to create tooling with similar properties to bundled CLI
140
+ * script.
141
+ */
142
+ constructor(options?: CLIOptions);
143
+ /**
144
+ * Returns list of files matching patterns and are not ignored. Filenames will
145
+ * have absolute paths.
146
+ *
147
+ * @public
148
+ */
149
+ expandFiles(patterns: string[], options?: ExpandOptions): string[];
150
+ getFormatter(formatters: string): (report: Report) => string;
151
+ /**
152
+ * Initialize project with a new configuration.
153
+ *
154
+ * A new `.htmlvalidate.json` file will be placed in the path provided by
155
+ * `cwd`.
156
+ */
157
+ init(cwd: string): Promise<InitResult>;
158
+ /**
159
+ * Searches ".htmlvalidateignore" files from filesystem and returns `true` if
160
+ * one of them contains a pattern matching given filename.
161
+ */
162
+ isIgnored(filename: string): boolean;
163
+ /**
164
+ * Clear cache.
165
+ *
166
+ * Previously fetched [[HtmlValidate]] instances must either be fetched again
167
+ * or call [[HtmlValidate.flushConfigCache]].
168
+ */
169
+ clearCache(): void;
170
+ /* Excluded from this release type: getLoader */
171
+ /**
172
+ * Get HtmlValidate instance with configuration based on options passed to the
173
+ * constructor.
174
+ *
175
+ * @public
176
+ */
177
+ getValidator(): HtmlValidate;
178
+ /* Excluded from this release type: getConfig */
179
+ }
180
+
181
+ /**
182
+ * @public
183
+ */
184
+ export declare interface CLIOptions {
185
+ configFile?: string;
186
+ rules?: string | string[];
187
+ }
188
+
189
+ /* Excluded from this release type: CommentToken */
190
+
191
+ /**
192
+ * Tests if plugin is compatible with html-validate library. Unless the `silent`
193
+ * option is used a warning is displayed on the console.
194
+ *
195
+ * @public
196
+ * @param name - Name of plugin
197
+ * @param declared - What library versions the plugin support (e.g. declared peerDependencies)
198
+ * @returns - `true` if version is compatible
199
+ */
200
+ export declare function compatibilityCheck(name: string, declared: string, options?: Partial<CompatibilityOptions>): boolean;
201
+
202
+ /**
203
+ * @public
204
+ */
205
+ export declare interface CompatibilityOptions {
206
+ /** If `true` nothing no output will be generated on console. Default: `false` */
207
+ silent: boolean;
208
+ /** Use this version number instead of running version. Default: running version */
209
+ version: string;
210
+ /** Use custom logging callback. Default: `console.error` */
211
+ logger(message: string): void;
212
+ }
213
+
214
+ /**
215
+ * Event emitted when Internet Explorer conditionals `<![if ...]>` are
216
+ * encountered.
217
+ *
218
+ * @public
219
+ */
220
+ export declare interface ConditionalEvent extends Event_2 {
221
+ /** Event location. */
222
+ location: Location_2;
223
+ /** Condition including markers. */
224
+ condition: string;
225
+ /** The element containing the conditional, if any. */
226
+ parent: HtmlElement | null;
227
+ }
228
+
229
+ /* Excluded from this release type: ConditionalToken */
230
+
231
+ /**
232
+ * Configuration holder.
233
+ *
234
+ * Each file being validated will have a unique instance of this class.
235
+ *
236
+ * @public
237
+ */
238
+ export declare class Config {
239
+ private config;
240
+ private configurations;
241
+ private initialized;
242
+ private metaTable;
243
+ private plugins;
244
+ private transformers;
245
+ private rootDir;
246
+ /**
247
+ * Create a new blank configuration. See also `Config.defaultConfig()`.
248
+ */
249
+ static empty(): Config;
250
+ /**
251
+ * Create configuration from object.
252
+ */
253
+ static fromObject(options: ConfigData, filename?: string | null): Config;
254
+ /**
255
+ * Read configuration from filename.
256
+ *
257
+ * Note: this reads configuration data from a file. If you intent to load
258
+ * configuration for a file to validate use `ConfigLoader.fromTarget()`.
259
+ *
260
+ * @param filename - The file to read from or one of the presets such as
261
+ * `html-validate:recommended`.
262
+ */
263
+ static fromFile(filename: string): Config;
264
+ /* Excluded from this release type: validate */
265
+ /**
266
+ * Load a default configuration object.
267
+ */
268
+ static defaultConfig(): Config;
269
+ /* Excluded from this release type: __constructor */
270
+ /**
271
+ * Initialize plugins, transforms etc.
272
+ *
273
+ * Must be called before trying to use config. Can safely be called multiple
274
+ * times.
275
+ *
276
+ * @public
277
+ */
278
+ init(): void;
279
+ /**
280
+ * Returns true if this configuration is marked as "root".
281
+ */
282
+ isRootFound(): boolean;
283
+ /**
284
+ * Returns a new configuration as a merge of the two. Entries from the passed
285
+ * object takes priority over this object.
286
+ *
287
+ * @public
288
+ * @param rhs - Configuration to merge with this one.
289
+ */
290
+ merge(rhs: Config): Config;
291
+ private extendConfig;
292
+ /**
293
+ * Get element metadata.
294
+ */
295
+ getMetaTable(): MetaTable;
296
+ /* Excluded from this release type: expandRelative */
297
+ /* Excluded from this release type: get */
298
+ /* Excluded from this release type: getRules */
299
+ private static getRulesObject;
300
+ /* Excluded from this release type: getPlugins */
301
+ private loadPlugins;
302
+ private loadConfigurations;
303
+ private extendMeta;
304
+ /* Excluded from this release type: resolve */
305
+ /* Excluded from this release type: resolveData */
306
+ private precompileTransformers;
307
+ /**
308
+ * Get transformation function requested by configuration.
309
+ *
310
+ * Searches:
311
+ *
312
+ * - Named transformers from plugins.
313
+ * - Unnamed transformer from plugin.
314
+ * - Standalone modules (local or node_modules)
315
+ *
316
+ * @param name - Key from configuration
317
+ */
318
+ private getTransformFunction;
319
+ /**
320
+ * @param name - Original name from configuration
321
+ * @param pluginName - Name of plugin
322
+ * @param key - Name of transform (from plugin)
323
+ */
324
+ private getNamedTransformerFromPlugin;
325
+ /**
326
+ * @param name - Original name from configuration
327
+ * @param plugin - Plugin instance
328
+ */
329
+ private getUnnamedTransformerFromPlugin;
330
+ private getTransformerFromModule;
331
+ /* Excluded from this release type: rootDirCache */
332
+ /* Excluded from this release type: rootDirCache */
333
+ /* Excluded from this release type: findRootDir */
334
+ }
335
+
336
+ /**
337
+ * @public
338
+ */
339
+ export declare interface ConfigData {
340
+ /**
341
+ * If set to true no new configurations will be searched.
342
+ */
343
+ root?: boolean;
344
+ extends?: string[];
345
+ /**
346
+ * List of sources for element metadata.
347
+ *
348
+ * The following sources are allowed:
349
+ *
350
+ * - "html5" (default) for the builtin metadata.
351
+ * - node module which export metadata
352
+ * - local path to json or js file exporting metadata.
353
+ * - object with inline metadata
354
+ *
355
+ * If elements isn't specified it defaults to `["html5"]`
356
+ */
357
+ elements?: Array<string | Record<string, unknown>>;
358
+ /**
359
+ * List of plugins.
360
+ *
361
+ * Each plugin must be resolvable be require and export the plugin interface.
362
+ */
363
+ plugins?: string[];
364
+ /**
365
+ * List of source file transformations. A transformer takes a filename and
366
+ * returns Source instances with extracted HTML-templates.
367
+ *
368
+ * Example:
369
+ *
370
+ * ```js
371
+ * "transform": {
372
+ * "^.*\\.foo$": "my-transform"
373
+ * }
374
+ * ```
375
+ *
376
+ * To run the "my-transform" module on all .foo files.
377
+ */
378
+ transform?: TransformMap;
379
+ rules?: RuleConfig;
380
+ }
381
+
382
+ /**
383
+ * @public
384
+ */
385
+ export declare class ConfigError extends UserError {
386
+ constructor(message: string, nested?: Error);
387
+ }
388
+
389
+ /**
390
+ * @public
391
+ */
392
+ export declare interface ConfigFactory {
393
+ defaultConfig(): Config;
394
+ empty(): Config;
395
+ fromObject(options: ConfigData, filename?: string | null): Config;
396
+ fromFile(filename: string): Config;
397
+ }
398
+
399
+ /**
400
+ * Configuration loader interface.
401
+ *
402
+ * A configuration loader takes a handle (typically a filename) and returns a
403
+ * configuration for it.
404
+ *
405
+ * @public
406
+ */
407
+ export declare abstract class ConfigLoader {
408
+ protected readonly configFactory: ConfigFactory;
409
+ protected readonly globalConfig: Config;
410
+ constructor(config?: ConfigData, configFactory?: ConfigFactory);
411
+ /**
412
+ * Get configuration for given handle.
413
+ *
414
+ * Handle is typically a filename but it is up to the loader to interpret the
415
+ * handle as something useful.
416
+ *
417
+ * If [[configOverride]] is set it is merged with the final result.
418
+ *
419
+ * @param handle - Unique handle to get configuration for.
420
+ * @param configOverride - Optional configuration to merge final results with.
421
+ */
422
+ abstract getConfigFor(handle: string, configOverride?: ConfigData): Config;
423
+ /**
424
+ * Flush configuration cache.
425
+ *
426
+ * Flushes all cached entries unless a specific handle is given.
427
+ *
428
+ * @param handle - If given only the cache for given handle will be flushed.
429
+ */
430
+ abstract flushCache(handle?: string): void;
431
+ /**
432
+ * Default configuration used when no explicit configuration is passed to constructor.
433
+ */
434
+ protected abstract defaultConfig(): Config;
435
+ protected empty(): Config;
436
+ protected loadFromObject(options: ConfigData, filename?: string | null): Config;
437
+ protected loadFromFile(filename: string): Config;
438
+ }
439
+
440
+ /* Excluded from this release type: configPresets */
441
+
442
+ /**
443
+ * Configuration ready event.
444
+ *
445
+ * @public
446
+ */
447
+ export declare interface ConfigReadyEvent extends Event_2 {
448
+ config: ResolvedConfig;
449
+ rules: Record<string, Rule<unknown, unknown>>;
450
+ }
451
+
452
+ /**
453
+ * @public
454
+ */
455
+ declare interface CSSStyleDeclaration_2 {
456
+ [key: string]: string;
457
+ }
458
+ export { CSSStyleDeclaration_2 as CSSStyleDeclaration }
459
+
460
+ /**
461
+ * @public
462
+ */
463
+ export declare interface DeferredMessage extends Omit<Message, "selector"> {
464
+ selector: () => string | null;
465
+ }
466
+
467
+ /**
468
+ * Helper function to assist IDE with completion and type-checking.
469
+ *
470
+ * @public
471
+ */
472
+ export declare function defineMetadata(metatable: MetaDataTable): MetaDataTable;
473
+
474
+ /**
475
+ * Helper function to assist IDE with completion and type-checking.
476
+ *
477
+ * @public
478
+ */
479
+ export declare function definePlugin(plugin: Plugin_2): Plugin_2;
480
+
481
+ /**
482
+ * @public
483
+ */
484
+ export declare interface DeprecatedElement {
485
+ message?: string;
486
+ documentation?: string;
487
+ source?: string;
488
+ }
489
+
490
+ /**
491
+ * Event emitted when html-validate directives `<!-- [html-validate-...] -->`
492
+ * are encountered.
493
+ *
494
+ * @public
495
+ */
496
+ export declare interface DirectiveEvent extends Event_2 {
497
+ /** Event location. */
498
+ location: Location_2;
499
+ /** Action location */
500
+ actionLocation: Location_2;
501
+ /** Options location */
502
+ optionsLocation?: Location_2;
503
+ /** Comment location */
504
+ commentLocation?: Location_2;
505
+ /** Directive action. */
506
+ action: "enable" | "disable" | "disable-block" | "disable-next";
507
+ /** Directive options. */
508
+ data: string;
509
+ /** Directive comment. */
510
+ comment: string;
511
+ }
512
+
513
+ /* Excluded from this release type: DirectiveToken */
514
+
515
+ /* Excluded from this release type: DoctypeCloseToken */
516
+
517
+ /**
518
+ * Event emitted when doctypes `<!DOCTYPE ..>` are encountered.
519
+ *
520
+ * @public
521
+ */
522
+ export declare interface DoctypeEvent extends Event_2 {
523
+ /** Event location. */
524
+ location: Location_2;
525
+ /** Tag */
526
+ tag: string;
527
+ /** Selected doctype */
528
+ value: string;
529
+ /** Location of doctype value */
530
+ valueLocation: Location_2;
531
+ }
532
+
533
+ /* Excluded from this release type: DoctypeOpenToken */
534
+
535
+ /* Excluded from this release type: DoctypeValueToken */
536
+
537
+ /**
538
+ * @public
539
+ */
540
+ export declare type DOMInternalID = number;
541
+
542
+ /**
543
+ * Event emitted after initialization but before tokenization and parsing occurs.
544
+ * Can be used to initialize state in rules.
545
+ *
546
+ * @public
547
+ */
548
+ export declare interface DOMLoadEvent extends Event_2 {
549
+ source: Source;
550
+ }
551
+
552
+ /**
553
+ * @public
554
+ */
555
+ export declare class DOMNode {
556
+ readonly nodeName: string;
557
+ readonly nodeType: NodeType;
558
+ readonly childNodes: DOMNode[];
559
+ readonly location: Location_2;
560
+ /* Excluded from this release type: unique */
561
+ private cache;
562
+ /**
563
+ * Set of disabled rules for this node.
564
+ *
565
+ * Rules disabled by using directives are added here.
566
+ */
567
+ private disabledRules;
568
+ /**
569
+ * Set of blocked rules for this node.
570
+ *
571
+ * Rules blocked by using directives are added here.
572
+ */
573
+ private blockedRules;
574
+ /**
575
+ * Create a new DOMNode.
576
+ *
577
+ * @param nodeType - What node type to create.
578
+ * @param nodeName - What node name to use. For `HtmlElement` this corresponds
579
+ * to the tagName but other node types have specific predefined values.
580
+ * @param location - Source code location of this node.
581
+ */
582
+ constructor(nodeType: NodeType, nodeName: string | undefined, location: Location_2);
583
+ /* Excluded from this release type: cacheEnable */
584
+ /**
585
+ * Fetch cached value from this DOM node.
586
+ *
587
+ * Cache is not enabled until `cacheEnable()` is called by [[Parser]] (when
588
+ * the element is fully constructed).
589
+ *
590
+ * @returns value or `undefined` if the value doesn't exist.
591
+ */
592
+ cacheGet<K extends keyof DOMNodeCache>(key: K): DOMNodeCache[K] | undefined;
593
+ cacheGet(key: string | number | symbol): any | undefined;
594
+ /**
595
+ * Store a value in cache.
596
+ *
597
+ * @returns the value itself is returned.
598
+ */
599
+ cacheSet<K extends keyof DOMNodeCache>(key: K, value: DOMNodeCache[K]): DOMNodeCache[K];
600
+ cacheSet<T>(key: string | number | symbol, value: T): T;
601
+ /**
602
+ * Remove a value by key from cache.
603
+ *
604
+ * @returns `true` if the entry existed and has been removed.
605
+ */
606
+ cacheRemove<K extends keyof DOMNodeCache>(key: K): boolean;
607
+ cacheRemove(key: string | number | symbol): boolean;
608
+ /**
609
+ * Check if key exists in cache.
610
+ */
611
+ cacheExists<K extends keyof DOMNodeCache>(key: K): boolean;
612
+ cacheExists(key: string | number | symbol): boolean;
613
+ /**
614
+ * Get the text (recursive) from all child nodes.
615
+ */
616
+ get textContent(): string;
617
+ append(node: DOMNode): void;
618
+ isRootElement(): boolean;
619
+ /**
620
+ * Tests if two nodes are the same (references the same object).
621
+ */
622
+ isSameNode(otherNode: DOMNode): boolean;
623
+ /**
624
+ * Returns a DOMNode representing the first direct child node or `null` if the
625
+ * node has no children.
626
+ */
627
+ get firstChild(): DOMNode;
628
+ /**
629
+ * Returns a DOMNode representing the last direct child node or `null` if the
630
+ * node has no children.
631
+ */
632
+ get lastChild(): DOMNode;
633
+ /* Excluded from this release type: blockRule */
634
+ /* Excluded from this release type: blockRules */
635
+ /* Excluded from this release type: disableRule */
636
+ /* Excluded from this release type: disableRules */
637
+ /**
638
+ * Enable a previously disabled rule for this node.
639
+ */
640
+ enableRule(ruleId: string): void;
641
+ /**
642
+ * Enables multiple rules.
643
+ */
644
+ enableRules(rules: string[]): void;
645
+ /* Excluded from this release type: ruleEnabled */
646
+ /* Excluded from this release type: ruleBlockers */
647
+ generateSelector(): string | null;
648
+ }
649
+
650
+ /**
651
+ * @public
652
+ */
653
+ export declare interface DOMNodeCache {
654
+ }
655
+
656
+ /**
657
+ * Event emitted when DOM tree is fully constructed.
658
+ *
659
+ * @public
660
+ */
661
+ export declare interface DOMReadyEvent extends Event_2 {
662
+ /** DOM Tree */
663
+ document: DOMTree;
664
+ source: Source;
665
+ }
666
+
667
+ /**
668
+ * @public
669
+ */
670
+ declare class DOMTokenList_2 extends Array<string> {
671
+ readonly value: string;
672
+ private readonly locations;
673
+ constructor(value: string | DynamicValue | null, location: Location_2 | null);
674
+ item(n: number): string | undefined;
675
+ location(n: number): Location_2 | undefined;
676
+ contains(token: string): boolean;
677
+ iterator(): Generator<{
678
+ index: number;
679
+ item: string;
680
+ location: Location_2;
681
+ }>;
682
+ }
683
+ export { DOMTokenList_2 as DOMTokenList }
684
+
685
+ /**
686
+ * @public
687
+ */
688
+ export declare class DOMTree {
689
+ readonly root: HtmlElement;
690
+ private active;
691
+ doctype: string | null;
692
+ constructor(location: Location_2);
693
+ pushActive(node: HtmlElement): void;
694
+ popActive(): void;
695
+ getActive(): HtmlElement;
696
+ /**
697
+ * Resolve dynamic meta expressions.
698
+ */
699
+ resolveMeta(table: MetaTable): void;
700
+ getElementsByTagName(tagName: string): HtmlElement[];
701
+ visitDepthFirst(callback: (node: HtmlElement) => void): void;
702
+ find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
703
+ querySelector(selector: string): HtmlElement | null;
704
+ querySelectorAll(selector: string): HtmlElement[];
705
+ }
706
+
707
+ /**
708
+ * @public
709
+ */
710
+ export declare class DynamicValue {
711
+ readonly expr: string;
712
+ constructor(expr: string);
713
+ toString(): string;
714
+ }
715
+
716
+ /**
717
+ * Event emitted when an element is fully constructed (including its children).
718
+ *
719
+ * @public
720
+ */
721
+ export declare interface ElementReadyEvent extends Event_2 {
722
+ /** Event location. */
723
+ location: Location_2;
724
+ /** HTML element */
725
+ target: HtmlElement;
726
+ }
727
+
728
+ /**
729
+ * @public
730
+ */
731
+ export declare interface ElementTable {
732
+ [tagName: string]: MetaElement;
733
+ }
734
+
735
+ /* Excluded from this release type: EOFToken */
736
+
737
+ /**
738
+ * @public
739
+ */
740
+ export declare interface ErrorDescriptor<ContextType> {
741
+ node: DOMNode | null;
742
+ message: string;
743
+ location?: Location_2 | null | undefined;
744
+ context?: ContextType;
745
+ }
746
+
747
+ /**
748
+ * @public
749
+ */
750
+ declare interface Event_2 {
751
+ /** Event location. */
752
+ location: Location_2 | null;
753
+ }
754
+ export { Event_2 as Event }
755
+
756
+ /**
757
+ * @public
758
+ */
759
+ export declare type EventCallback = (event: string, data: any) => void;
760
+
761
+ /**
762
+ * @public
763
+ */
764
+ export declare interface EventDump {
765
+ event: string;
766
+ data: any;
767
+ }
768
+
769
+ /**
770
+ * @public
771
+ */
772
+ export declare class EventHandler {
773
+ listeners: {
774
+ [event: string]: EventCallback[];
775
+ };
776
+ constructor();
777
+ /**
778
+ * Add an event listener.
779
+ *
780
+ * @param event - Event names (comma separated) or '*' for any event.
781
+ * @param callback - Called any time even triggers.
782
+ * @returns Unregistration function.
783
+ */
784
+ on(event: string, callback: EventCallback): () => void;
785
+ /**
786
+ * Add a onetime event listener. The listener will automatically be removed
787
+ * after being triggered once.
788
+ *
789
+ * @param event - Event names (comma separated) or '*' for any event.
790
+ * @param callback - Called any time even triggers.
791
+ * @returns Unregistration function.
792
+ */
793
+ once(event: string, callback: EventCallback): () => void;
794
+ /**
795
+ * Trigger event causing all listeners to be called.
796
+ *
797
+ * @param event - Event name.
798
+ * @param data - Event data.
799
+ */
800
+ trigger(event: string, data: any): void;
801
+ }
802
+
803
+ /**
804
+ * @public
805
+ */
806
+ export declare interface ExpandOptions {
807
+ /**
808
+ * Working directory. Defaults to `process.cwd()`.
809
+ */
810
+ cwd?: string;
811
+ /**
812
+ * List of extensions to search for when expanding directories. Extensions
813
+ * should be passed without leading dot, e.g. "html" instead of ".html".
814
+ */
815
+ extensions?: string[];
816
+ }
817
+
818
+ /**
819
+ * Loads configuration by traversing filesystem.
820
+ *
821
+ * Configuration is read from three sources and in the following order:
822
+ *
823
+ * 1. Global configuration passed to constructor.
824
+ * 2. Configuration files found when traversing the directory structure.
825
+ * 3. Override passed to this function.
826
+ *
827
+ * The following configuration filenames are searched:
828
+ *
829
+ * - `.htmlvalidate.json`
830
+ * - `.htmlvalidate.js`
831
+ * - `.htmlvalidate.cjs`
832
+ *
833
+ * Global configuration is used when no configuration file is found. The
834
+ * result is always merged with override if present.
835
+ *
836
+ * The `root` property set to `true` affects the configuration as following:
837
+ *
838
+ * 1. If set in override the override is returned as-is.
839
+ * 2. If set in the global config the override is merged into global and
840
+ * returned. No configuration files are searched.
841
+ * 3. Setting `root` in configuration file only stops directory traversal.
842
+ *
843
+ * @public
844
+ */
845
+ export declare class FileSystemConfigLoader extends ConfigLoader {
846
+ protected cache: Map<string, Config | null>;
847
+ /**
848
+ * @param config - Global configuration
849
+ * @param configFactory - Optional configuration factory
850
+ */
851
+ constructor(config?: ConfigData, configFactory?: ConfigFactory);
852
+ /**
853
+ * Get configuration for given filename.
854
+ *
855
+ * @param filename - Filename to get configuration for.
856
+ * @param configOverride - Configuration to merge final result with.
857
+ */
858
+ getConfigFor(filename: string, configOverride?: ConfigData): Config;
859
+ /**
860
+ * Flush configuration cache.
861
+ *
862
+ * @param filename - If given only the cache for that file is flushed.
863
+ */
864
+ flushCache(filename?: string): void;
865
+ /**
866
+ * Load raw configuration from directory traversal.
867
+ *
868
+ * This configuration is not merged with global configuration and may return
869
+ * `null` if no configuration files are found.
870
+ */
871
+ fromFilename(filename: string): Config | null;
872
+ protected defaultConfig(): Config;
873
+ }
874
+
875
+ /**
876
+ * @public
877
+ */
878
+ export declare interface FormAssociated {
879
+ /** Listed elements have a name attribute and is listed in the form and fieldset elements property. */
880
+ listed: boolean;
881
+ }
882
+
883
+ /**
884
+ * @public
885
+ */
886
+ export declare type Formatter = (results: Result[]) => string;
887
+
888
+ /**
889
+ * Get formatter function by name.
890
+ *
891
+ * @public
892
+ * @param name - Name of formatter.
893
+ * @returns Formatter function or null if it doesn't exist.
894
+ */
895
+ export declare function formatterFactory(name: keyof AvailableFormatters): Formatter;
896
+
897
+ /**
898
+ * @public
899
+ */
900
+ export declare function formatterFactory(name: string): Formatter | null;
901
+
902
+ /**
903
+ * @public
904
+ */
905
+ export declare class HtmlElement extends DOMNode {
906
+ readonly tagName: string;
907
+ readonly parent: HtmlElement | null;
908
+ readonly voidElement: boolean;
909
+ readonly depth: number;
910
+ closed: NodeClosed;
911
+ protected readonly attr: {
912
+ [key: string]: Attribute[];
913
+ };
914
+ private metaElement;
915
+ private annotation;
916
+ constructor(tagName: string | undefined, parent: HtmlElement | null, closed: NodeClosed, meta: MetaElement | null, location: Location_2);
917
+ /* Excluded from this release type: rootNode */
918
+ /* Excluded from this release type: fromTokens */
919
+ /**
920
+ * Returns annotated name if set or defaults to `<tagName>`.
921
+ *
922
+ * E.g. `my-annotation` or `<div>`.
923
+ */
924
+ get annotatedName(): string;
925
+ /**
926
+ * Get list of IDs referenced by `aria-labelledby`.
927
+ *
928
+ * If the attribute is unset or empty this getter returns null.
929
+ * If the attribute is dynamic the original {@link DynamicValue} is returned.
930
+ *
931
+ * @public
932
+ */
933
+ get ariaLabelledby(): string[] | DynamicValue | null;
934
+ /**
935
+ * Similar to childNodes but only elements.
936
+ */
937
+ get childElements(): HtmlElement[];
938
+ /**
939
+ * Find the first ancestor matching a selector.
940
+ *
941
+ * Implementation of DOM specification of Element.closest(selectors).
942
+ */
943
+ closest(selectors: string): HtmlElement | null;
944
+ /**
945
+ * Generate a DOM selector for this element. The returned selector will be
946
+ * unique inside the current document.
947
+ */
948
+ generateSelector(): string | null;
949
+ /**
950
+ * Tests if this element has given tagname.
951
+ *
952
+ * If passing "*" this test will pass if any tagname is set.
953
+ */
954
+ is(tagName: string): boolean;
955
+ /**
956
+ * Load new element metadata onto this element.
957
+ *
958
+ * Do note that semantics such as `void` cannot be changed (as the element has
959
+ * already been created). In addition the element will still "be" the same
960
+ * element, i.e. even if loading meta for a `<p>` tag upon a `<div>` tag it
961
+ * will still be a `<div>` as far as the rest of the validator is concerned.
962
+ *
963
+ * In fact only certain properties will be copied onto the element:
964
+ *
965
+ * - content categories (flow, phrasing, etc)
966
+ * - required attributes
967
+ * - attribute allowed values
968
+ * - permitted/required elements
969
+ *
970
+ * Properties *not* loaded:
971
+ *
972
+ * - inherit
973
+ * - deprecated
974
+ * - foreign
975
+ * - void
976
+ * - implicitClosed
977
+ * - scriptSupporting
978
+ * - deprecatedAttributes
979
+ *
980
+ * Changes to element metadata will only be visible after `element:ready` (and
981
+ * the subsequent `dom:ready` event).
982
+ */
983
+ loadMeta(meta: MetaElement): void;
984
+ /**
985
+ * Match this element against given selectors. Returns true if any selector
986
+ * matches.
987
+ *
988
+ * Implementation of DOM specification of Element.matches(selectors).
989
+ */
990
+ matches(selector: string): boolean;
991
+ get meta(): MetaElement | null;
992
+ /**
993
+ * Set annotation for this element.
994
+ */
995
+ setAnnotation(text: string): void;
996
+ /**
997
+ * Set attribute. Stores all attributes set even with the same name.
998
+ *
999
+ * @param key - Attribute name
1000
+ * @param value - Attribute value. Use `null` if no value is present.
1001
+ * @param keyLocation - Location of the attribute name.
1002
+ * @param valueLocation - Location of the attribute value (excluding quotation)
1003
+ * @param originalAttribute - If attribute is an alias for another attribute
1004
+ * (dynamic attributes) set this to the original attribute name.
1005
+ */
1006
+ setAttribute(key: string, value: string | DynamicValue | null, keyLocation: Location_2, valueLocation: Location_2 | null, originalAttribute?: string): void;
1007
+ /**
1008
+ * Get a list of all attributes on this node.
1009
+ */
1010
+ get attributes(): Attribute[];
1011
+ hasAttribute(key: string): boolean;
1012
+ /**
1013
+ * Get attribute.
1014
+ *
1015
+ * By default only the first attribute is returned but if the code needs to
1016
+ * handle duplicate attributes the `all` parameter can be set to get all
1017
+ * attributes with given key.
1018
+ *
1019
+ * This usually only happens when code contains duplicate attributes (which
1020
+ * `no-dup-attr` will complain about) or when a static attribute is combined
1021
+ * with a dynamic, consider:
1022
+ *
1023
+ * <p class="foo" dynamic-class="bar">
1024
+ *
1025
+ * @param key - Attribute name
1026
+ * @param all - Return single or all attributes.
1027
+ */
1028
+ getAttribute(key: string): Attribute | null;
1029
+ getAttribute(key: string, all: true): Attribute[];
1030
+ /**
1031
+ * Get attribute value.
1032
+ *
1033
+ * Returns the attribute value if present.
1034
+ *
1035
+ * - Missing attributes return `null`.
1036
+ * - Boolean attributes return `null`.
1037
+ * - `DynamicValue` returns attribute expression.
1038
+ *
1039
+ * @param key - Attribute name
1040
+ * @returns Attribute value or null.
1041
+ */
1042
+ getAttributeValue(key: string): string | null;
1043
+ /**
1044
+ * Add text as a child node to this element.
1045
+ *
1046
+ * @param text - Text to add.
1047
+ * @param location - Source code location of this text.
1048
+ */
1049
+ appendText(text: string | DynamicValue, location: Location_2): void;
1050
+ /**
1051
+ * Return a list of all known classes on the element. Dynamic values are
1052
+ * ignored.
1053
+ */
1054
+ get classList(): DOMTokenList_2;
1055
+ /**
1056
+ * Get element ID if present.
1057
+ */
1058
+ get id(): string | null;
1059
+ get style(): CSSStyleDeclaration_2;
1060
+ /**
1061
+ * Returns the first child element or null if there are no child elements.
1062
+ */
1063
+ get firstElementChild(): HtmlElement | null;
1064
+ /**
1065
+ * Returns the last child element or null if there are no child elements.
1066
+ */
1067
+ get lastElementChild(): HtmlElement | null;
1068
+ get siblings(): HtmlElement[];
1069
+ get previousSibling(): HtmlElement | null;
1070
+ get nextSibling(): HtmlElement | null;
1071
+ getElementsByTagName(tagName: string): HtmlElement[];
1072
+ querySelector(selector: string): HtmlElement | null;
1073
+ querySelectorAll(selector: string): HtmlElement[];
1074
+ private querySelectorImpl;
1075
+ /* Excluded from this release type: visitDepthFirst */
1076
+ /* Excluded from this release type: someChildren */
1077
+ /* Excluded from this release type: everyChildren */
1078
+ /* Excluded from this release type: find */
1079
+ }
1080
+
1081
+ /**
1082
+ * Primary API for using HTML-validate.
1083
+ *
1084
+ * Provides high-level abstractions for common operations.
1085
+ *
1086
+ * @public
1087
+ */
1088
+ export declare class HtmlValidate {
1089
+ protected configLoader: ConfigLoader;
1090
+ /**
1091
+ * Create a new validator.
1092
+ *
1093
+ * @public
1094
+ * @param configLoader - Use a custom configuration loader.
1095
+ * @param config - If set it provides the global default configuration. By
1096
+ * default `Config.defaultConfig()` is used.
1097
+ */
1098
+ constructor(config?: ConfigData);
1099
+ constructor(configLoader: ConfigLoader);
1100
+ /**
1101
+ * Parse and validate HTML from string.
1102
+ *
1103
+ * @public
1104
+ * @param str - Text to parse.
1105
+ * @param filename - If set configuration is loaded for given filename.
1106
+ * @param hooks - Optional hooks (see [[Source]]) for definition.
1107
+ * @returns Report output.
1108
+ */
1109
+ validateString(str: string): Report;
1110
+ validateString(str: string, filename: string): Report;
1111
+ validateString(str: string, hooks: SourceHooks): Report;
1112
+ validateString(str: string, options: ConfigData): Report;
1113
+ validateString(str: string, filename: string, hooks: SourceHooks): Report;
1114
+ validateString(str: string, filename: string, options: ConfigData): Report;
1115
+ validateString(str: string, filename: string, options: ConfigData, hooks: SourceHooks): Report;
1116
+ /**
1117
+ * Parse and validate HTML from [[Source]].
1118
+ *
1119
+ * @public
1120
+ * @param input - Source to parse.
1121
+ * @returns Report output.
1122
+ */
1123
+ validateSource(input: Source, configOverride?: ConfigData): Report;
1124
+ /**
1125
+ * Parse and validate HTML from file.
1126
+ *
1127
+ * @public
1128
+ * @param filename - Filename to read and parse.
1129
+ * @returns Report output.
1130
+ */
1131
+ validateFile(filename: string): Report;
1132
+ /**
1133
+ * Parse and validate HTML from multiple files. Result is merged together to a
1134
+ * single report.
1135
+ *
1136
+ * @param filenames - Filenames to read and parse.
1137
+ * @returns Report output.
1138
+ */
1139
+ validateMultipleFiles(filenames: string[]): Report;
1140
+ /**
1141
+ * Returns true if the given filename can be validated.
1142
+ *
1143
+ * A file is considered to be validatable if the extension is `.html` or if a
1144
+ * transformer matches the filename.
1145
+ *
1146
+ * This is mostly useful for tooling to determine whenever to validate the
1147
+ * file or not. CLI tools will run on all the given files anyway.
1148
+ */
1149
+ canValidate(filename: string): boolean;
1150
+ /**
1151
+ * Tokenize filename and output all tokens.
1152
+ *
1153
+ * Using CLI this is enabled with `--dump-tokens`. Mostly useful for
1154
+ * debugging.
1155
+ *
1156
+ * @param filename - Filename to tokenize.
1157
+ */
1158
+ dumpTokens(filename: string): TokenDump[];
1159
+ /**
1160
+ * Parse filename and output all events.
1161
+ *
1162
+ * Using CLI this is enabled with `--dump-events`. Mostly useful for
1163
+ * debugging.
1164
+ *
1165
+ * @param filename - Filename to dump events from.
1166
+ */
1167
+ dumpEvents(filename: string): EventDump[];
1168
+ /**
1169
+ * Parse filename and output DOM tree.
1170
+ *
1171
+ * Using CLI this is enabled with `--dump-tree`. Mostly useful for
1172
+ * debugging.
1173
+ *
1174
+ * @param filename - Filename to dump DOM tree from.
1175
+ */
1176
+ dumpTree(filename: string): string[];
1177
+ /**
1178
+ * Transform filename and output source data.
1179
+ *
1180
+ * Using CLI this is enabled with `--dump-source`. Mostly useful for
1181
+ * debugging.
1182
+ *
1183
+ * @param filename - Filename to dump source from.
1184
+ */
1185
+ dumpSource(filename: string): string[];
1186
+ /**
1187
+ * Get effective configuration schema.
1188
+ */
1189
+ getConfigurationSchema(): SchemaObject;
1190
+ /**
1191
+ * Get effective metadata element schema.
1192
+ *
1193
+ * If a filename is given the configured plugins can extend the
1194
+ * schema. Filename must not be an existing file or a filetype normally
1195
+ * handled by html-validate but the path will be used when resolving
1196
+ * configuration. As a rule-of-thumb, set it to the elements json file.
1197
+ */
1198
+ getElementsSchema(filename?: string): SchemaObject;
1199
+ /**
1200
+ * Get contextual documentation for the given rule.
1201
+ *
1202
+ * Typical usage:
1203
+ *
1204
+ * ```js
1205
+ * const report = htmlvalidate.validateFile("my-file.html");
1206
+ * for (const result of report.results){
1207
+ * const config = htmlvalidate.getConfigFor(result.filePath);
1208
+ * for (const message of result.messages){
1209
+ * const documentation = htmlvalidate.getRuleDocumentation(message.ruleId, config, message.context);
1210
+ * // do something with documentation
1211
+ * }
1212
+ * }
1213
+ * ```
1214
+ *
1215
+ * @param ruleId - Rule to get documentation for.
1216
+ * @param config - If set it provides more accurate description by using the
1217
+ * correct configuration for the file.
1218
+ * @param context - If set to `Message.context` some rules can provide
1219
+ * contextual details and suggestions.
1220
+ */
1221
+ getRuleDocumentation(ruleId: string, config?: Config | null, context?: any | null): RuleDocumentation | null;
1222
+ /* Excluded from this release type: getParserFor */
1223
+ /**
1224
+ * Get configuration for given filename.
1225
+ *
1226
+ * See [[FileSystemConfigLoader]] for details.
1227
+ *
1228
+ * @public
1229
+ * @param filename - Filename to get configuration for.
1230
+ * @param configOverride - Configuration to apply last.
1231
+ */
1232
+ getConfigFor(filename: string, configOverride?: ConfigData): Config;
1233
+ /**
1234
+ * Flush configuration cache. Clears full cache unless a filename is given.
1235
+ *
1236
+ * See [[FileSystemConfigLoader]] for details.
1237
+ *
1238
+ * @public
1239
+ * @param filename - If set, only flush cache for given filename.
1240
+ */
1241
+ flushConfigCache(filename?: string): void;
1242
+ }
1243
+
1244
+ /**
1245
+ * @public
1246
+ */
1247
+ export declare interface IncludeExcludeOptions {
1248
+ include: string[] | null;
1249
+ exclude: string[] | null;
1250
+ }
1251
+
1252
+ /**
1253
+ * @public
1254
+ */
1255
+ export declare interface InitResult {
1256
+ filename: string;
1257
+ }
1258
+
1259
+ /* Excluded from this release type: keywordPatternMatcher */
1260
+
1261
+ /**
1262
+ * @public
1263
+ */
1264
+ export declare interface ListenEventMap {
1265
+ "config:ready": ConfigReadyEvent;
1266
+ "source:ready": SourceReadyEvent;
1267
+ /* Excluded from this release type: token */
1268
+ "tag:open": TagOpenEvent;
1269
+ "tag:start": TagStartEvent;
1270
+ "tag:close": TagCloseEvent;
1271
+ "tag:end": TagEndEvent;
1272
+ "tag:ready": TagReadyEvent;
1273
+ "element:ready": ElementReadyEvent;
1274
+ "dom:load": DOMLoadEvent;
1275
+ "dom:ready": DOMReadyEvent;
1276
+ doctype: DoctypeEvent;
1277
+ attr: AttributeEvent;
1278
+ whitespace: WhitespaceEvent;
1279
+ conditional: ConditionalEvent;
1280
+ directive: DirectiveEvent;
1281
+ /* Excluded from this release type: "rule:error" */
1282
+ /* Excluded from this release type: "parse:begin" */
1283
+ /* Excluded from this release type: "parse:end" */
1284
+ "*": Event_2;
1285
+ }
1286
+
1287
+ /* Excluded from this release type: LoadedPlugin */
1288
+
1289
+ /**
1290
+ * @public
1291
+ */
1292
+ declare interface Location_2 {
1293
+ /**
1294
+ * The filemane this location refers to.
1295
+ */
1296
+ readonly filename: string;
1297
+ /**
1298
+ * The string offset (number of characters into the string) this location
1299
+ * refers to.
1300
+ */
1301
+ readonly offset: number;
1302
+ /**
1303
+ * The line number in the file.
1304
+ */
1305
+ readonly line: number;
1306
+ /**
1307
+ * The column number in the file. Tabs counts as 1 (not expanded).
1308
+ */
1309
+ readonly column: number;
1310
+ /**
1311
+ * The number of characters this location refers to. This includes any
1312
+ * whitespace characters such as newlines.
1313
+ */
1314
+ readonly size: number;
1315
+ }
1316
+ export { Location_2 as Location }
1317
+
1318
+ /**
1319
+ * Reported error message.
1320
+ *
1321
+ * @public
1322
+ */
1323
+ export declare interface Message {
1324
+ /** Rule that triggered this message */
1325
+ ruleId: string;
1326
+ /** URL to description of error */
1327
+ ruleUrl?: string;
1328
+ /** Severity of the message */
1329
+ severity: number;
1330
+ /** Message text */
1331
+ message: string;
1332
+ /** Offset (number of characters) into the source */
1333
+ offset: number;
1334
+ /** Line number */
1335
+ line: number;
1336
+ /** Column number */
1337
+ column: number;
1338
+ /** From start offset, how many characters is this message relevant for */
1339
+ size: number;
1340
+ /** DOM selector */
1341
+ selector: string | null;
1342
+ /**
1343
+ * Optional error context used to provide context-aware documentation.
1344
+ *
1345
+ * This context can be passed to [[HtmlValidate#getRuleDocumentation]].
1346
+ */
1347
+ context?: any;
1348
+ }
1349
+
1350
+ /**
1351
+ * @public
1352
+ */
1353
+ export declare interface MetaAttribute {
1354
+ allowed?: MetaAttributeAllowedCallback;
1355
+ boolean?: boolean;
1356
+ deprecated?: boolean | string;
1357
+ enum?: Array<string | RegExp>;
1358
+ list?: boolean;
1359
+ omit?: boolean;
1360
+ required?: boolean;
1361
+ }
1362
+
1363
+ /**
1364
+ * Callback for the `allowed` property of `MetaAttribute`. It takes a node and
1365
+ * should return `null` if there is no errors and a string with an error
1366
+ * description if there is an error.
1367
+ *
1368
+ * @public
1369
+ * @param node - The node the attribute belongs to.
1370
+ * @param attr - The current attribute being validated.
1371
+ */
1372
+ export declare type MetaAttributeAllowedCallback = (node: HtmlElement, attr: Attribute) => string | null | undefined;
1373
+
1374
+ /**
1375
+ * Properties listed here can be copied (loaded) onto another element using
1376
+ * [[HtmlElement.loadMeta]].
1377
+ *
1378
+ * @public
1379
+ */
1380
+ export declare const MetaCopyableProperty: Array<keyof MetaElement>;
1381
+
1382
+ /**
1383
+ * @public
1384
+ */
1385
+ export declare interface MetaData {
1386
+ inherit?: string;
1387
+ metadata?: boolean | PropertyExpression;
1388
+ flow?: boolean | PropertyExpression;
1389
+ sectioning?: boolean | PropertyExpression;
1390
+ heading?: boolean | PropertyExpression;
1391
+ phrasing?: boolean | PropertyExpression;
1392
+ embedded?: boolean | PropertyExpression;
1393
+ interactive?: boolean | PropertyExpression;
1394
+ deprecated?: boolean | string | DeprecatedElement;
1395
+ foreign?: boolean;
1396
+ void?: boolean;
1397
+ transparent?: boolean | string[];
1398
+ implicitClosed?: string[];
1399
+ scriptSupporting?: boolean;
1400
+ form?: boolean;
1401
+ /** Mark element as a form-associated element */
1402
+ formAssociated?: Partial<FormAssociated>;
1403
+ labelable?: boolean | PropertyExpression;
1404
+ deprecatedAttributes?: string[];
1405
+ requiredAttributes?: string[];
1406
+ attributes?: PermittedAttribute;
1407
+ permittedContent?: Permitted;
1408
+ permittedDescendants?: Permitted;
1409
+ permittedOrder?: PermittedOrder;
1410
+ permittedParent?: Permitted;
1411
+ requiredAncestors?: RequiredAncestors;
1412
+ requiredContent?: RequiredContent;
1413
+ textContent?: TextContent | `${TextContent}`;
1414
+ }
1415
+
1416
+ /**
1417
+ * Helpers when writing element metadata.
1418
+ *
1419
+ * @public
1420
+ */
1421
+ export declare interface MetadataHelper {
1422
+ /** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */
1423
+ allowedIfAttributeIsPresent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;
1424
+ /** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */
1425
+ allowedIfAttributeIsAbsent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;
1426
+ /** Returns an error if another attribute does not have one of the listed values */
1427
+ allowedIfAttributeHasValue(this: void, attr: string, value: string[], options?: {
1428
+ defaultValue?: string | null;
1429
+ }): MetaAttributeAllowedCallback;
1430
+ }
1431
+
1432
+ /**
1433
+ * @public
1434
+ */
1435
+ export declare const metadataHelper: MetadataHelper;
1436
+
1437
+ /**
1438
+ * @public
1439
+ */
1440
+ export declare interface MetaDataTable {
1441
+ [tagName: string]: MetaData;
1442
+ }
1443
+
1444
+ /**
1445
+ * @public
1446
+ */
1447
+ export declare interface MetaElement extends Omit<MetaData, "deprecatedAttributes" | "requiredAttributes"> {
1448
+ tagName: string;
1449
+ formAssociated?: FormAssociated;
1450
+ attributes: Record<string, MetaAttribute>;
1451
+ textContent?: TextContent;
1452
+ }
1453
+
1454
+ /**
1455
+ * Properties listed here can be used to reverse search elements with the given
1456
+ * property enabled. See [[MetaTable.getTagsWithProperty]].
1457
+ *
1458
+ * @public
1459
+ */
1460
+ export declare type MetaLookupableProperty = "metadata" | "flow" | "sectioning" | "heading" | "phrasing" | "embedded" | "interactive" | "deprecated" | "foreign" | "void" | "transparent" | "scriptSupporting" | "form" | "formAssociated" | "labelable";
1461
+
1462
+ /**
1463
+ * @public
1464
+ */
1465
+ export declare class MetaTable {
1466
+ readonly elements: ElementTable;
1467
+ private schema;
1468
+ /* Excluded from this release type: __constructor */
1469
+ /* Excluded from this release type: init */
1470
+ /* Excluded from this release type: extendValidationSchema */
1471
+ /* Excluded from this release type: loadFromObject */
1472
+ /* Excluded from this release type: loadFromFile */
1473
+ /**
1474
+ * Get [[MetaElement]] for the given tag. If no specific metadata is present
1475
+ * the global metadata is returned or null if no global is present.
1476
+ *
1477
+ * @public
1478
+ * @returns A shallow copy of metadata.
1479
+ */
1480
+ getMetaFor(tagName: string): MetaElement | null;
1481
+ /**
1482
+ * Find all tags which has enabled given property.
1483
+ *
1484
+ * @public
1485
+ */
1486
+ getTagsWithProperty(propName: MetaLookupableProperty): string[];
1487
+ /**
1488
+ * Find tag matching tagName or inheriting from it.
1489
+ *
1490
+ * @public
1491
+ */
1492
+ getTagsDerivedFrom(tagName: string): string[];
1493
+ private addEntry;
1494
+ /**
1495
+ * Construct a new AJV schema validator.
1496
+ */
1497
+ private getSchemaValidator;
1498
+ /**
1499
+ * @public
1500
+ */
1501
+ getJSONSchema(): SchemaObject;
1502
+ /**
1503
+ * Finds the global element definition and merges each known element with the
1504
+ * global, e.g. to assign global attributes.
1505
+ */
1506
+ private resolveGlobal;
1507
+ private mergeElement;
1508
+ /* Excluded from this release type: resolve */
1509
+ }
1510
+
1511
+ /**
1512
+ * @public
1513
+ */
1514
+ export declare class NestedError extends Error {
1515
+ constructor(message: string, nested?: Error);
1516
+ }
1517
+
1518
+ /**
1519
+ * @public
1520
+ */
1521
+ export declare enum NodeClosed {
1522
+ Open = 0,
1523
+ EndTag = 1,
1524
+ VoidOmitted = 2,
1525
+ VoidSelfClosed = 3,
1526
+ ImplicitClosed = 4
1527
+ }
1528
+
1529
+ /**
1530
+ * @public
1531
+ */
1532
+ export declare enum NodeType {
1533
+ ELEMENT_NODE = 1,
1534
+ TEXT_NODE = 3,
1535
+ DOCUMENT_NODE = 9
1536
+ }
1537
+
1538
+ /* Excluded from this release type: ParseBeginEvent */
1539
+
1540
+ /* Excluded from this release type: ParseEndEvent */
1541
+
1542
+ /* Excluded from this release type: Parser */
1543
+
1544
+ /**
1545
+ * @public
1546
+ */
1547
+ export declare type Permitted = PermittedEntry[];
1548
+
1549
+ /**
1550
+ * @public
1551
+ */
1552
+ export declare type PermittedAttribute = Record<string, MetaAttribute | Array<string | RegExp> | null>;
1553
+
1554
+ /**
1555
+ * @public
1556
+ */
1557
+ export declare type PermittedEntry = CategoryOrTag | PermittedGroup | Array<CategoryOrTag | PermittedGroup>;
1558
+
1559
+ /**
1560
+ * @public
1561
+ */
1562
+ export declare interface PermittedGroup {
1563
+ exclude?: string | string[];
1564
+ }
1565
+
1566
+ /**
1567
+ * @public
1568
+ */
1569
+ export declare type PermittedOrder = string[];
1570
+
1571
+ /**
1572
+ * @public
1573
+ */
1574
+ declare interface Plugin_2 {
1575
+ /**
1576
+ * Name of the plugin.
1577
+ *
1578
+ * If specified this is the name used when referring to the plugin. Default is
1579
+ * to use the name/path the user used when loading the plugin. To be less
1580
+ * confusing for users you should use the same name as your package.
1581
+ *
1582
+ * The name must be a valid package name according to NPM (basically lowercase
1583
+ * characters, must not begin with dot, slash or non-url safe characters).
1584
+ *
1585
+ * Hint: import and use the name from `package.json`.
1586
+ */
1587
+ name?: string | null;
1588
+ /**
1589
+ * Initialization callback.
1590
+ *
1591
+ * Called once per plugin during initialization.
1592
+ */
1593
+ init?: () => void | null;
1594
+ /**
1595
+ * Setup callback.
1596
+ *
1597
+ * Called once per source after engine is initialized.
1598
+ *
1599
+ * @param source - The source about to be validated. Readonly.
1600
+ * @param eventhandler - Eventhandler from parser. Can be used to listen for
1601
+ * parser events.
1602
+ */
1603
+ setup?: (source: Source, eventhandler: EventHandler) => void | null;
1604
+ /**
1605
+ * Configuration presets.
1606
+ *
1607
+ * Each key should be the unprefixed name which a configuration later can
1608
+ * access using `${plugin}:${key}`, e.g. if a plugin named "my-plugin" exposes
1609
+ * a preset named "foobar" it can be accessed using:
1610
+ *
1611
+ * "extends": ["my-plugin:foobar"]
1612
+ */
1613
+ configs?: Record<string, ConfigData | null> | null;
1614
+ /**
1615
+ * List of new rules present.
1616
+ */
1617
+ rules?: Record<string, RuleConstructor<any, any> | null> | null;
1618
+ /**
1619
+ * Transformer available in this plugin.
1620
+ *
1621
+ * Can be given either as a single unnamed transformer or an object with
1622
+ * multiple named.
1623
+ *
1624
+ * Unnamed transformers use the plugin name similar to how a standalone
1625
+ * transformer would work:
1626
+ *
1627
+ * ```
1628
+ * "transform": {
1629
+ * "^.*\\.foo$": "my-plugin"
1630
+ * }
1631
+ * ```
1632
+ *
1633
+ * For named transformers each key should be the unprefixed name which a
1634
+ * configuration later can access using `${plugin}:${key}`, e.g. if a plugin
1635
+ * named "my-plugin" exposes a transformer named "foobar" it can be accessed
1636
+ * using:
1637
+ *
1638
+ * ```
1639
+ * "transform": {
1640
+ * "^.*\\.foo$": "my-plugin:foobar"
1641
+ * }
1642
+ * ```
1643
+ */
1644
+ transformer?: Transformer_2 | Record<string, Transformer_2 | null> | null;
1645
+ /**
1646
+ * Extend metadata validation schema.
1647
+ */
1648
+ elementSchema?: SchemaValidationPatch | null;
1649
+ }
1650
+ export { Plugin_2 as Plugin }
1651
+
1652
+ /**
1653
+ * @public
1654
+ */
1655
+ export declare type ProcessAttributeCallback = (this: unknown, attr: AttributeData) => Iterable<AttributeData>;
1656
+
1657
+ /**
1658
+ * @public
1659
+ */
1660
+ export declare type ProcessElementCallback = (this: ProcessElementContext, node: HtmlElement) => void;
1661
+
1662
+ /**
1663
+ * @public
1664
+ */
1665
+ export declare interface ProcessElementContext {
1666
+ getMetaFor(this: void, tagName: string): MetaElement | null;
1667
+ }
1668
+
1669
+ /**
1670
+ * @public
1671
+ */
1672
+ export declare type PropertyExpression = string | [string, any];
1673
+
1674
+ /**
1675
+ * Report object returned by [[HtmlValidate]].
1676
+ *
1677
+ * @public
1678
+ */
1679
+ export declare interface Report {
1680
+ /** `true` if validation was successful */
1681
+ valid: boolean;
1682
+ /** Detailed results per validated source */
1683
+ results: Result[];
1684
+ /** Total number of errors across all sources */
1685
+ errorCount: number;
1686
+ /** Total warnings of errors across all sources */
1687
+ warningCount: number;
1688
+ }
1689
+
1690
+ /**
1691
+ * @public
1692
+ */
1693
+ export declare class Reporter {
1694
+ protected result: Record<string, DeferredMessage[]>;
1695
+ constructor();
1696
+ /**
1697
+ * Merge two or more reports into a single one.
1698
+ */
1699
+ static merge(reports: Report[]): Report;
1700
+ add<ContextType, OptionsType>(rule: Rule<ContextType, OptionsType>, message: string, severity: number, node: DOMNode | null, location: Location_2, context?: ContextType): void;
1701
+ addManual(filename: string, message: DeferredMessage): void;
1702
+ save(sources?: Source[]): Report;
1703
+ protected isValid(): boolean;
1704
+ }
1705
+
1706
+ /**
1707
+ * @public
1708
+ */
1709
+ export declare type RequiredAncestors = string[];
1710
+
1711
+ /**
1712
+ * @public
1713
+ */
1714
+ export declare type RequiredContent = string[];
1715
+
1716
+ /**
1717
+ * A resolved configuration is a normalized configuration with all extends,
1718
+ * plugins etc resolved.
1719
+ *
1720
+ * @public
1721
+ */
1722
+ export declare class ResolvedConfig {
1723
+ private metaTable;
1724
+ private plugins;
1725
+ private rules;
1726
+ private transformers;
1727
+ constructor({ metaTable, plugins, rules, transformers }: ResolvedConfigData);
1728
+ getMetaTable(): MetaTable;
1729
+ getPlugins(): Plugin_2[];
1730
+ getRules(): Map<string, [Severity, RuleOptions]>;
1731
+ /**
1732
+ * Transform a source.
1733
+ *
1734
+ * When transforming zero or more new sources will be generated.
1735
+ *
1736
+ * @param source - Current source to transform.
1737
+ * @param filename - If set it is the filename used to match
1738
+ * transformer. Default is to use filename from source.
1739
+ * @returns A list of transformed sources ready for validation.
1740
+ */
1741
+ transformSource(source: Source, filename?: string): Source[];
1742
+ /**
1743
+ * Wrapper around [[transformSource]] which reads a file before passing it
1744
+ * as-is to transformSource.
1745
+ *
1746
+ * @param filename - Filename to transform (according to configured
1747
+ * transformations)
1748
+ * @returns A list of transformed sources ready for validation.
1749
+ */
1750
+ transformFilename(filename: string): Source[];
1751
+ /**
1752
+ * Returns true if a transformer matches given filename.
1753
+ */
1754
+ canTransform(filename: string): boolean;
1755
+ private findTransformer;
1756
+ }
1757
+
1758
+ /**
1759
+ * @public
1760
+ */
1761
+ export declare interface ResolvedConfigData {
1762
+ metaTable: MetaTable;
1763
+ plugins: Plugin_2[];
1764
+ rules: Map<string, [Severity, RuleOptions]>;
1765
+ transformers: TransformerEntry[];
1766
+ }
1767
+
1768
+ /**
1769
+ * @public
1770
+ */
1771
+ export declare interface Result {
1772
+ messages: Message[];
1773
+ filePath: string;
1774
+ errorCount: number;
1775
+ warningCount: number;
1776
+ source: string | null;
1777
+ }
1778
+
1779
+ /**
1780
+ * @public
1781
+ */
1782
+ export declare abstract class Rule<ContextType = void, OptionsType = void> {
1783
+ private reporter;
1784
+ private parser;
1785
+ private meta;
1786
+ private enabled;
1787
+ private blockers;
1788
+ private severity;
1789
+ private event;
1790
+ /**
1791
+ * Rule name. Defaults to filename without extension but can be overwritten by
1792
+ * subclasses.
1793
+ */
1794
+ name: string;
1795
+ /**
1796
+ * Rule options.
1797
+ */
1798
+ readonly options: OptionsType;
1799
+ constructor(options: OptionsType);
1800
+ getSeverity(): number;
1801
+ setServerity(severity: number): void;
1802
+ /* Excluded from this release type: block */
1803
+ /* Excluded from this release type: unblock */
1804
+ setEnabled(enabled: boolean): void;
1805
+ /**
1806
+ * Returns `true` if rule is deprecated.
1807
+ *
1808
+ * Overridden by subclasses.
1809
+ */
1810
+ get deprecated(): boolean;
1811
+ /* Excluded from this release type: isEnabled */
1812
+ /* Excluded from this release type: isBlocked */
1813
+ /* Excluded from this release type: getBlockers */
1814
+ /**
1815
+ * Check if keyword is being ignored by the current rule configuration.
1816
+ *
1817
+ * This method requires the [[RuleOption]] type to include two properties:
1818
+ *
1819
+ * - include: string[] | null
1820
+ * - exclude: string[] | null
1821
+ *
1822
+ * This methods checks if the given keyword is included by "include" but not
1823
+ * excluded by "exclude". If any property is unset it is skipped by the
1824
+ * condition. Usually the user would use either one but not both but there is
1825
+ * no limitation to use both but the keyword must satisfy both conditions. If
1826
+ * either condition fails `true` is returned.
1827
+ *
1828
+ * For instance, given `{ include: ["foo"] }` the keyword `"foo"` would match
1829
+ * but not `"bar"`.
1830
+ *
1831
+ * Similarly, given `{ exclude: ["foo"] }` the keyword `"bar"` would match but
1832
+ * not `"foo"`.
1833
+ *
1834
+ * @param keyword - Keyword to match against `include` and `exclude` options.
1835
+ * @param matcher - Optional function to compare items with.
1836
+ * @returns `true` if keyword is not present in `include` or is present in
1837
+ * `exclude`.
1838
+ */
1839
+ isKeywordIgnored<T extends IncludeExcludeOptions>(this: {
1840
+ options: T;
1841
+ }, keyword: string, matcher?: (list: string[], it: string) => boolean): boolean;
1842
+ /**
1843
+ * Get [[MetaElement]] for the given tag. If no specific metadata is present
1844
+ * the global metadata is returned or null if no global is present.
1845
+ *
1846
+ * @public
1847
+ * @returns A shallow copy of metadata.
1848
+ */
1849
+ getMetaFor(tagName: string): MetaElement | null;
1850
+ /**
1851
+ * Find all tags which has enabled given property.
1852
+ */
1853
+ getTagsWithProperty(propName: MetaLookupableProperty): string[];
1854
+ /**
1855
+ * Find tag matching tagName or inheriting from it.
1856
+ */
1857
+ getTagsDerivedFrom(tagName: string): string[];
1858
+ /**
1859
+ * JSON schema for rule options.
1860
+ *
1861
+ * Rules should override this to return an object with JSON schema to validate
1862
+ * rule options. If `null` or `undefined` is returned no validation is
1863
+ * performed.
1864
+ */
1865
+ static schema(): SchemaObject | null | undefined;
1866
+ /**
1867
+ * Report a new error.
1868
+ *
1869
+ * Rule must be enabled both globally and on the specific node for this to
1870
+ * have any effect.
1871
+ */
1872
+ report(error: ErrorDescriptor<ContextType>): void;
1873
+ report(node: DOMNode | null, message: string): void;
1874
+ report(node: DOMNode | null, message: string, location: Location_2 | null | undefined): void;
1875
+ report(node: DOMNode | null, message: string, location: Location_2 | null | undefined, context: ContextType): void;
1876
+ private findLocation;
1877
+ /**
1878
+ * Listen for events.
1879
+ *
1880
+ * Adding listeners can be done even if the rule is disabled but for the
1881
+ * events to be delivered the rule must be enabled.
1882
+ *
1883
+ * If the optional filter callback is used it must be a function taking an
1884
+ * event of the same type as the listener. The filter is called before the
1885
+ * listener and if the filter returns false the event is discarded.
1886
+ *
1887
+ * @param event - Event name
1888
+ * @param filter - Optional filter function. Callback is only called if filter functions return true.
1889
+ * @param callback - Callback to handle event.
1890
+ * @returns A function to unregister the listener
1891
+ */
1892
+ on<K extends keyof ListenEventMap>(event: K, callback: (event: ListenEventMap[K]) => void): () => void;
1893
+ on<K extends keyof ListenEventMap>(event: K, filter: (event: ListenEventMap[K]) => boolean, callback: (event: ListenEventMap[K]) => void): () => void;
1894
+ /* Excluded from this release type: init */
1895
+ /* Excluded from this release type: validateOptions */
1896
+ /**
1897
+ * Rule setup callback.
1898
+ *
1899
+ * Override this to provide rule setup code.
1900
+ */
1901
+ abstract setup(): void;
1902
+ /**
1903
+ * Rule documentation callback.
1904
+ *
1905
+ * Called when requesting additional documentation for a rule. Some rules
1906
+ * provide additional context to provide context-aware suggestions.
1907
+ *
1908
+ * @param context - Error context given by a reported error.
1909
+ * @returns Rule documentation and url with additional details or `null` if no
1910
+ * additional documentation is available.
1911
+ */
1912
+ documentation(context?: ContextType): RuleDocumentation | null;
1913
+ }
1914
+
1915
+ /* Excluded from this release type: RuleBlocker */
1916
+
1917
+ /**
1918
+ * @public
1919
+ */
1920
+ export declare type RuleConfig = Record<string, RuleSeverity | [RuleSeverity] | [RuleSeverity, RuleOptions]>;
1921
+
1922
+ /**
1923
+ * @public
1924
+ */
1925
+ export declare interface RuleConstructor<T, U> {
1926
+ new (options?: any): Rule<T, U>;
1927
+ schema(): SchemaObject | null | undefined;
1928
+ }
1929
+
1930
+ /**
1931
+ * @public
1932
+ */
1933
+ export declare interface RuleDocumentation {
1934
+ description: string;
1935
+ url?: string;
1936
+ }
1937
+
1938
+ /* Excluded from this release type: RuleErrorEvent */
1939
+
1940
+ /**
1941
+ * Returns true if given ruleId is an existing builtin rule. It does not handle
1942
+ * rules loaded via plugins.
1943
+ *
1944
+ * Can be used to create forward/backward compatibility by checking if a rule
1945
+ * exists to enable/disable it.
1946
+ *
1947
+ * @public
1948
+ * @param ruleId - Rule id to check
1949
+ * @returns `true` if rule exists
1950
+ */
1951
+ export declare function ruleExists(ruleId: string): boolean;
1952
+
1953
+ /**
1954
+ * @public
1955
+ */
1956
+ export declare type RuleOptions = string | number | Record<string, any>;
1957
+
1958
+ /**
1959
+ * @public
1960
+ */
1961
+ export declare type RuleSeverity = "off" | "warn" | "error" | number;
1962
+
1963
+ export { SchemaObject }
1964
+
1965
+ /**
1966
+ * @public
1967
+ */
1968
+ export declare class SchemaValidationError extends UserError {
1969
+ filename: string | null;
1970
+ private obj;
1971
+ private schema;
1972
+ private errors;
1973
+ constructor(filename: string | null, message: string, obj: unknown, schema: SchemaObject, errors: ErrorObject[]);
1974
+ prettyError(): string;
1975
+ private getRawJSON;
1976
+ }
1977
+
1978
+ /**
1979
+ * @public
1980
+ */
1981
+ export declare interface SchemaValidationPatch {
1982
+ properties?: Record<string, unknown>;
1983
+ definitions?: Record<string, unknown>;
1984
+ }
1985
+
1986
+ /* Excluded from this release type: ScriptToken */
1987
+
1988
+ /**
1989
+ * @public
1990
+ */
1991
+ export declare enum Severity {
1992
+ DISABLED = 0,
1993
+ WARN = 1,
1994
+ ERROR = 2
1995
+ }
1996
+
1997
+ /**
1998
+ * Calculate a new location by offsetting this location.
1999
+ *
2000
+ * If the references text with newlines the wrap parameter must be set to
2001
+ * properly calculate line and column information. If not given the text is
2002
+ * assumed to contain no newlines.
2003
+ *
2004
+ * @public
2005
+ * @param location - Source location
2006
+ * @param begin - Start location. Default is 0.
2007
+ * @param end - End location. Default is size of location. Negative values are
2008
+ * counted from end, e.g. `-2` means `size - 2`.
2009
+ * @param wrap - If given, line/column is wrapped for each newline occuring
2010
+ * before location end.
2011
+ */
2012
+ export declare function sliceLocation(location: Location_2, begin: number, end?: number, wrap?: string): Location_2;
2013
+
2014
+ /**
2015
+ * @public
2016
+ */
2017
+ export declare function sliceLocation(location: Location_2 | null | undefined, begin: number, end?: number, wrap?: string): Location_2 | null;
2018
+
2019
+ /**
2020
+ * Source interface.
2021
+ *
2022
+ * HTML source with file, line and column context.
2023
+ *
2024
+ * Optional hooks can be attached. This is usually added by transformers to
2025
+ * postprocess.
2026
+ *
2027
+ * @public
2028
+ */
2029
+ export declare interface Source {
2030
+ data: string;
2031
+ filename: string;
2032
+ /**
2033
+ * Line in the original data.
2034
+ *
2035
+ * Starts at 1 (first line).
2036
+ */
2037
+ line: number;
2038
+ /**
2039
+ * Column in the original data.
2040
+ *
2041
+ * Starts at 1 (first column).
2042
+ */
2043
+ column: number;
2044
+ /**
2045
+ * Offset in the original data.
2046
+ *
2047
+ * Starts at 0 (first character).
2048
+ */
2049
+ offset: number;
2050
+ /**
2051
+ * Original data. When a transformer extracts a portion of the original source
2052
+ * this must be set to the full original source.
2053
+ *
2054
+ * Since the transformer might be chained always test if the input source
2055
+ * itself has `originalData` set, e.g.:
2056
+ *
2057
+ * `originalData = input.originalData || input.data`.
2058
+ */
2059
+ originalData?: string;
2060
+ /**
2061
+ * Hooks for processing the source as it is being parsed.
2062
+ */
2063
+ hooks?: SourceHooks;
2064
+ /**
2065
+ * Internal property to keep track of what transformers has run on this
2066
+ * source. Entries are in reverse-order, e.g. the last applied transform is
2067
+ * first.
2068
+ */
2069
+ transformedBy?: string[];
2070
+ }
2071
+
2072
+ /**
2073
+ * @public
2074
+ */
2075
+ export declare interface SourceHooks {
2076
+ /**
2077
+ * Called for every attribute.
2078
+ *
2079
+ * The original attribute must be yielded as well or no attribute will be
2080
+ * added.
2081
+ *
2082
+ * @returns Attribute data for an attribute to be added to the element.
2083
+ */
2084
+ processAttribute?: ProcessAttributeCallback | null;
2085
+ /**
2086
+ * Called for every element after element is created but before any children.
2087
+ *
2088
+ * May modify the element.
2089
+ */
2090
+ processElement?: ProcessElementCallback | null;
2091
+ }
2092
+
2093
+ /**
2094
+ * Source ready event. Emitted after source has been transformed but before any
2095
+ * markup is processed.
2096
+ *
2097
+ * The source object must not be modified (use a transformer if modifications
2098
+ * are required)
2099
+ *
2100
+ * @public
2101
+ */
2102
+ export declare interface SourceReadyEvent extends Event_2 {
2103
+ source: Source;
2104
+ }
2105
+
2106
+ /**
2107
+ * The static configuration loader does not do any per-handle lookup. Only the
2108
+ * global or per-call configuration is used.
2109
+ *
2110
+ * In practice this means no configuration is fetch by traversing the
2111
+ * filesystem.
2112
+ *
2113
+ * @public
2114
+ */
2115
+ export declare class StaticConfigLoader extends ConfigLoader {
2116
+ getConfigFor(handle: string, configOverride?: ConfigData): Config;
2117
+ flushCache(): void;
2118
+ protected defaultConfig(): Config;
2119
+ }
2120
+
2121
+ /* Excluded from this release type: StyleToken */
2122
+
2123
+ /**
2124
+ * Deprecated alias for TagEndEvent
2125
+ *
2126
+ * @public
2127
+ * @deprecated Use TagEndEvent instead
2128
+ */
2129
+ export declare type TagCloseEvent = TagEndEvent;
2130
+
2131
+ /* Excluded from this release type: TagCloseToken */
2132
+
2133
+ /**
2134
+ * Event emitted when end tags `</..>` are encountered.
2135
+ *
2136
+ * @public
2137
+ */
2138
+ export declare interface TagEndEvent extends Event_2 {
2139
+ /** Event location. */
2140
+ location: Location_2;
2141
+ /** Temporary node for the end tag. Can be null for elements left unclosed
2142
+ * when document ends */
2143
+ target: HtmlElement | null;
2144
+ /** The node being closed. */
2145
+ previous: HtmlElement;
2146
+ }
2147
+
2148
+ /**
2149
+ * Deprecated alias for TagStartEvent
2150
+ *
2151
+ * @public
2152
+ * @deprecated Use TagStartEvent instead
2153
+ */
2154
+ export declare type TagOpenEvent = TagStartEvent;
2155
+
2156
+ /* Excluded from this release type: TagOpenToken */
2157
+
2158
+ /**
2159
+ * Event emitted when a tag is ready (i.e. all the attributes has been
2160
+ * parsed). The children of the element will not yet be finished.
2161
+ *
2162
+ * @public
2163
+ */
2164
+ export declare interface TagReadyEvent extends Event_2 {
2165
+ /** Event location. */
2166
+ location: Location_2;
2167
+ /** The node that is finished parsing. */
2168
+ target: HtmlElement;
2169
+ }
2170
+
2171
+ /**
2172
+ * Event emitted when starting tags are encountered.
2173
+ *
2174
+ * @public
2175
+ */
2176
+ export declare interface TagStartEvent extends Event_2 {
2177
+ /** Event location. */
2178
+ location: Location_2;
2179
+ /** The node being started. */
2180
+ target: HtmlElement;
2181
+ }
2182
+
2183
+ /**
2184
+ * @public
2185
+ */
2186
+ export declare class TemplateExtractor {
2187
+ private ast;
2188
+ private filename;
2189
+ private data;
2190
+ private constructor();
2191
+ static fromFilename(filename: string): TemplateExtractor;
2192
+ /**
2193
+ * Create a new [[TemplateExtractor]] from javascript source code.
2194
+ *
2195
+ * `Source` offsets will be relative to the string, i.e. offset 0 is the first
2196
+ * character of the string. If the string is only a subset of a larger string
2197
+ * the offsets must be adjusted manually.
2198
+ *
2199
+ * @param source - Source code.
2200
+ * @param filename - Optional filename to set in the resulting
2201
+ * `Source`. Defauls to `"inline"`.
2202
+ */
2203
+ static fromString(source: string, filename?: string): TemplateExtractor;
2204
+ /**
2205
+ * Convenience function to create a [[Source]] instance from an existing file.
2206
+ *
2207
+ * @param filename - Filename with javascript source code. The file must exist
2208
+ * and be readable by the user.
2209
+ * @returns An array of Source's suitable for passing to [[Engine]] linting
2210
+ * functions.
2211
+ */
2212
+ static createSource(filename: string): Source[];
2213
+ /**
2214
+ * Extract object properties.
2215
+ *
2216
+ * Given a key `"template"` this method finds all objects literals with a
2217
+ * `"template"` property and creates a [[Source]] instance with proper offsets
2218
+ * with the value of the property. For instance:
2219
+ *
2220
+ * ```
2221
+ * const myObj = {
2222
+ * foo: 'bar',
2223
+ * };
2224
+ * ```
2225
+ *
2226
+ * The above snippet would yield a `Source` with the content `bar`.
2227
+ *
2228
+ */
2229
+ extractObjectProperty(key: string): Source[];
2230
+ }
2231
+
2232
+ /* Excluded from this release type: TemplatingToken */
2233
+
2234
+ /**
2235
+ * @public
2236
+ */
2237
+ export declare enum TextClassification {
2238
+ EMPTY_TEXT = 0,
2239
+ DYNAMIC_TEXT = 1,
2240
+ STATIC_TEXT = 2
2241
+ }
2242
+
2243
+ /**
2244
+ * @public
2245
+ */
2246
+ export declare interface TextClassificationOptions {
2247
+ /** If `true` only accessible text is considered (default false) */
2248
+ accessible?: boolean;
2249
+ /** If `true` the `hidden` and `aria-hidden` attribute is ignored on the root
2250
+ * (and parents) elements (default false) */
2251
+ ignoreHiddenRoot?: boolean;
2252
+ }
2253
+
2254
+ /**
2255
+ * @public
2256
+ */
2257
+ export declare enum TextContent {
2258
+ NONE = "none",
2259
+ DEFAULT = "default",
2260
+ REQUIRED = "required",
2261
+ ACCESSIBLE = "accessible"
2262
+ }
2263
+
2264
+ /**
2265
+ * Represents a text in the HTML document.
2266
+ *
2267
+ * Text nodes are appended as children of `HtmlElement` and cannot have childen
2268
+ * of its own.
2269
+ *
2270
+ * @public
2271
+ */
2272
+ export declare class TextNode extends DOMNode {
2273
+ private readonly text;
2274
+ /**
2275
+ * @param text - Text to add. When a `DynamicValue` is used the expression is
2276
+ * used as "text".
2277
+ * @param location - Source code location of this node.
2278
+ */
2279
+ constructor(text: string | DynamicValue, location: Location_2);
2280
+ /**
2281
+ * Get the text from node.
2282
+ */
2283
+ get textContent(): string;
2284
+ /**
2285
+ * Flag set to true if the attribute value is static.
2286
+ */
2287
+ get isStatic(): boolean;
2288
+ /**
2289
+ * Flag set to true if the attribute value is dynamic.
2290
+ */
2291
+ get isDynamic(): boolean;
2292
+ }
2293
+
2294
+ /* Excluded from this release type: TextToken */
2295
+
2296
+ /* Excluded from this release type: Token */
2297
+
2298
+ /**
2299
+ * @public
2300
+ */
2301
+ export declare interface TokenDump {
2302
+ token: string;
2303
+ data: string;
2304
+ location: string;
2305
+ }
2306
+
2307
+ /* Excluded from this release type: TokenEvent */
2308
+
2309
+ /* Excluded from this release type: TokenStream */
2310
+
2311
+ /* Excluded from this release type: TokenType */
2312
+
2313
+ /**
2314
+ * @public
2315
+ */
2316
+ export declare interface TransformContext {
2317
+ /**
2318
+ * Test if an additional chainable transformer is present.
2319
+ *
2320
+ * Returns true only if there is a transformer configured for the given
2321
+ * filename.
2322
+ *
2323
+ * @param filename - Filename to use to match next transformer.
2324
+ */
2325
+ hasChain(filename: string): boolean;
2326
+ /**
2327
+ * Chain transformations.
2328
+ *
2329
+ * Sometimes multiple transformers must be applied. For instance, a Markdown
2330
+ * file with JSX in a code-block.
2331
+ *
2332
+ * @param source - Source to chain transformations on.
2333
+ * @param filename - Filename to use to match next transformer (unrelated to
2334
+ * filename set in source)
2335
+ */
2336
+ chain(source: Source, filename: string): Iterable<Source>;
2337
+ }
2338
+
2339
+ /**
2340
+ * @public
2341
+ */
2342
+ declare type Transformer_2 = (this: TransformContext, source: Source) => Iterable<Source>;
2343
+ export { Transformer_2 as Transformer }
2344
+
2345
+ /**
2346
+ * @public
2347
+ */
2348
+ export declare interface TransformerEntry {
2349
+ pattern: RegExp;
2350
+ name: string;
2351
+ fn: Transformer_2;
2352
+ }
2353
+
2354
+ /**
2355
+ * @public
2356
+ */
2357
+ export declare interface TransformMap {
2358
+ [key: string]: string;
2359
+ }
2360
+
2361
+ /**
2362
+ * @public
2363
+ */
2364
+ export declare interface TriggerEventMap {
2365
+ "config:ready": ConfigReadyEvent;
2366
+ "source:ready": SourceReadyEvent;
2367
+ /* Excluded from this release type: token */
2368
+ "tag:start": TagStartEvent;
2369
+ "tag:end": TagEndEvent;
2370
+ "tag:ready": TagReadyEvent;
2371
+ "element:ready": ElementReadyEvent;
2372
+ "dom:load": DOMLoadEvent;
2373
+ "dom:ready": DOMReadyEvent;
2374
+ doctype: DoctypeEvent;
2375
+ attr: AttributeEvent;
2376
+ whitespace: WhitespaceEvent;
2377
+ conditional: ConditionalEvent;
2378
+ directive: DirectiveEvent;
2379
+ /* Excluded from this release type: "rule:error" */
2380
+ /* Excluded from this release type: "parse:begin" */
2381
+ /* Excluded from this release type: "parse:end" */
2382
+ }
2383
+
2384
+ /* Excluded from this release type: UnicodeBOMToken */
2385
+
2386
+ /**
2387
+ * @public
2388
+ */
2389
+ export declare class UserError extends NestedError {
2390
+ constructor(message: string, nested?: Error);
2391
+ /**
2392
+ * @public
2393
+ */
2394
+ prettyFormat(): string | undefined;
2395
+ }
2396
+
2397
+ /**
2398
+ * Helper class to validate elements against metadata rules.
2399
+ *
2400
+ * @public
2401
+ */
2402
+ export declare class Validator {
2403
+ /**
2404
+ * Test if element is used in a proper context.
2405
+ *
2406
+ * @param node - Element to test.
2407
+ * @param rules - List of rules.
2408
+ * @returns `true` if element passes all tests.
2409
+ */
2410
+ static validatePermitted(node: HtmlElement, rules: Permitted | null): boolean;
2411
+ /**
2412
+ * Test if an element is used the correct amount of times.
2413
+ *
2414
+ * For instance, a `<table>` element can only contain a single `<tbody>`
2415
+ * child. If multiple `<tbody>` exists this test will fail both nodes.
2416
+ * Note that this is called on the parent but will fail the children violating
2417
+ * the rule.
2418
+ *
2419
+ * @param children - Array of children to validate.
2420
+ * @param rules - List of rules of the parent element.
2421
+ * @returns `true` if the parent element of the children passes the test.
2422
+ */
2423
+ static validateOccurrences(children: HtmlElement[], rules: Permitted | null, cb: (node: HtmlElement, category: string) => void): boolean;
2424
+ /**
2425
+ * Validate elements order.
2426
+ *
2427
+ * Given a parent element with children and metadata containing permitted
2428
+ * order it will validate each children and ensure each one exists in the
2429
+ * specified order.
2430
+ *
2431
+ * For instance, for a `<table>` element the `<caption>` element must come
2432
+ * before a `<thead>` which must come before `<tbody>`.
2433
+ *
2434
+ * @param children - Array of children to validate.
2435
+ */
2436
+ static validateOrder(children: HtmlElement[], rules: PermittedOrder | null, cb: (node: HtmlElement, prev: HtmlElement) => void): boolean;
2437
+ /**
2438
+ * Validate element ancestors.
2439
+ *
2440
+ * Check if an element has the required set of elements. At least one of the
2441
+ * selectors must match.
2442
+ */
2443
+ static validateAncestors(node: HtmlElement, rules: RequiredAncestors | null): boolean;
2444
+ /**
2445
+ * Validate element required content.
2446
+ *
2447
+ * Check if an element has the required set of elements. At least one of the
2448
+ * selectors must match.
2449
+ *
2450
+ * Returns `[]` when valid or a list of required but missing tagnames or
2451
+ * categories.
2452
+ */
2453
+ static validateRequiredContent(node: HtmlElement, rules: RequiredContent | null): CategoryOrTag[];
2454
+ /**
2455
+ * Test if an attribute has an allowed value and/or format.
2456
+ *
2457
+ * @param attr - Attribute to test.
2458
+ * @param rules - Element attribute metadta.
2459
+ * @returns `true` if attribute passes all tests.
2460
+ */
2461
+ static validateAttribute(attr: Attribute, rules: Record<string, MetaAttribute>): boolean;
2462
+ private static validateAttributeValue;
2463
+ private static validatePermittedRule;
2464
+ /**
2465
+ * Validate node against a content category.
2466
+ *
2467
+ * When matching parent nodes against permitted parents use the superset
2468
+ * parameter to also match for `@flow`. E.g. if a node expects a `@phrasing`
2469
+ * parent it should also allow `@flow` parent since `@phrasing` is a subset of
2470
+ * `@flow`.
2471
+ *
2472
+ * @param node - The node to test against
2473
+ * @param category - Name of category with `@` prefix or tag name.
2474
+ * @param defaultMatch - The default return value when node categories is not known.
2475
+ */
2476
+ static validatePermittedCategory(node: HtmlElement, category: string, defaultMatch: boolean): boolean;
2477
+ }
2478
+
2479
+ /** @public */
2480
+ export declare const version: string;
2481
+
2482
+ /**
2483
+ * Event emitted when whitespace content is parsed.
2484
+ *
2485
+ * @public
2486
+ */
2487
+ export declare interface WhitespaceEvent extends Event_2 {
2488
+ /** Event location. */
2489
+ location: Location_2;
2490
+ /** Text content. */
2491
+ text: string;
2492
+ }
2493
+
2494
+ /* Excluded from this release type: WhitespaceToken */
2495
+
2496
+ /**
2497
+ * Represents an `Error` created from arbitrary values.
2498
+ *
2499
+ * @public
2500
+ */
2501
+ export declare class WrappedError<T> extends Error {
2502
+ constructor(message: T);
2503
+ }
2504
+
2505
+ export { }