html-validate 7.14.0 → 7.15.1

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