-
-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathhtmlhint.js
1626 lines (1546 loc) · 65.8 KB
/
htmlhint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTMLHint = factory());
})(this, (function () { 'use strict';
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var core$1 = {};
var htmlparser = {};
Object.defineProperty(htmlparser, "__esModule", { value: true });
class HTMLParser {
constructor() {
this._listeners = {};
this._mapCdataTags = this.makeMap('script,style');
this._arrBlocks = [];
this.lastEvent = null;
}
makeMap(str) {
const obj = {};
const items = str.split(',');
for (let i = 0; i < items.length; i++) {
obj[items[i]] = true;
}
return obj;
}
parse(html) {
const mapCdataTags = this._mapCdataTags;
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g;
const regAttr = /\s*([^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+)(?:\s*=\s*(?:(")([^"]*)"|(')([^']*)'|([^\s"'>]*)))?/g;
const regLine = /\r?\n/g;
let match;
let matchIndex;
let lastIndex = 0;
let tagName;
let arrAttrs;
let tagCDATA = null;
let attrsCDATA;
let arrCDATA = [];
let lastCDATAIndex = 0;
let text;
let lastLineIndex = 0;
let line = 1;
const arrBlocks = this._arrBlocks;
this.fire('start', {
pos: 0,
line: 1,
col: 1,
});
const isMapCdataTagsRequired = () => {
const attrType = arrAttrs.find((attr) => attr.name === 'type') || {
value: '',
};
return (mapCdataTags[tagName] &&
attrType.value.indexOf('text/ng-template') === -1);
};
const saveBlock = (type, raw, pos, data) => {
const col = pos - lastLineIndex + 1;
if (data === undefined) {
data = {};
}
data.raw = raw;
data.pos = pos;
data.line = line;
data.col = col;
arrBlocks.push(data);
this.fire(type, data);
while (regLine.exec(raw)) {
line++;
lastLineIndex = pos + regLine.lastIndex;
}
};
while ((match = regTag.exec(html))) {
matchIndex = match.index;
if (matchIndex > lastIndex) {
text = html.substring(lastIndex, matchIndex);
if (tagCDATA) {
arrCDATA.push(text);
}
else {
saveBlock('text', text, lastIndex);
}
}
lastIndex = regTag.lastIndex;
if ((tagName = match[1])) {
if (tagCDATA && tagName === tagCDATA) {
text = arrCDATA.join('');
saveBlock('cdata', text, lastCDATAIndex, {
tagName: tagCDATA,
attrs: attrsCDATA,
});
tagCDATA = null;
attrsCDATA = undefined;
arrCDATA = [];
}
if (!tagCDATA) {
saveBlock('tagend', match[0], matchIndex, {
tagName: tagName,
});
continue;
}
}
if (tagCDATA) {
arrCDATA.push(match[0]);
}
else {
if ((tagName = match[4])) {
arrAttrs = [];
const attrs = match[5];
let attrMatch;
let attrMatchCount = 0;
while ((attrMatch = regAttr.exec(attrs))) {
const name = attrMatch[1];
const quote = attrMatch[2]
? attrMatch[2]
: attrMatch[4]
? attrMatch[4]
: '';
const value = attrMatch[3]
? attrMatch[3]
: attrMatch[5]
? attrMatch[5]
: attrMatch[6]
? attrMatch[6]
: '';
arrAttrs.push({
name: name,
value: value,
quote: quote,
index: attrMatch.index,
raw: attrMatch[0],
});
attrMatchCount += attrMatch[0].length;
}
if (attrMatchCount === attrs.length) {
saveBlock('tagstart', match[0], matchIndex, {
tagName: tagName,
attrs: arrAttrs,
close: match[6],
});
if (isMapCdataTagsRequired()) {
tagCDATA = tagName;
attrsCDATA = arrAttrs.concat();
arrCDATA = [];
lastCDATAIndex = lastIndex;
}
}
else {
saveBlock('text', match[0], matchIndex);
}
}
else if (match[2] || match[3]) {
saveBlock('comment', match[0], matchIndex, {
content: match[2] || match[3],
long: match[2] ? true : false,
});
}
}
}
if (html.length > lastIndex) {
text = html.substring(lastIndex, html.length);
saveBlock('text', text, lastIndex);
}
this.fire('end', {
pos: lastIndex,
line: line,
col: html.length - lastLineIndex + 1,
});
}
addListener(types, listener) {
const _listeners = this._listeners;
const arrTypes = types.split(/[,\s]/);
let type;
for (let i = 0, l = arrTypes.length; i < l; i++) {
type = arrTypes[i];
if (_listeners[type] === undefined) {
_listeners[type] = [];
}
_listeners[type].push(listener);
}
}
fire(type, data) {
if (data === undefined) {
data = {};
}
data.type = type;
let listeners = [];
const listenersType = this._listeners[type];
const listenersAll = this._listeners['all'];
if (listenersType !== undefined) {
listeners = listeners.concat(listenersType);
}
if (listenersAll !== undefined) {
listeners = listeners.concat(listenersAll);
}
const lastEvent = this.lastEvent;
if (lastEvent !== null) {
delete lastEvent['lastEvent'];
data.lastEvent = lastEvent;
}
this.lastEvent = data;
for (let i = 0, l = listeners.length; i < l; i++) {
listeners[i].call(this, data);
}
}
removeListener(type, listener) {
const listenersType = this._listeners[type];
if (listenersType !== undefined) {
for (let i = 0, l = listenersType.length; i < l; i++) {
if (listenersType[i] === listener) {
listenersType.splice(i, 1);
break;
}
}
}
}
fixPos(event, index) {
const text = event.raw.substr(0, index);
const arrLines = text.split(/\r?\n/);
const lineCount = arrLines.length - 1;
let line = event.line;
let col;
if (lineCount > 0) {
line += lineCount;
col = arrLines[lineCount].length + 1;
}
else {
col = event.col + index;
}
return {
line: line,
col: col,
};
}
getMapAttrs(arrAttrs) {
const mapAttrs = {};
let attr;
for (let i = 0, l = arrAttrs.length; i < l; i++) {
attr = arrAttrs[i];
mapAttrs[attr.name] = attr.value;
}
return mapAttrs;
}
}
htmlparser.default = HTMLParser;
var reporter = {};
Object.defineProperty(reporter, "__esModule", { value: true });
class Reporter {
constructor(html, ruleset) {
this.html = html;
this.lines = html.split(/\r?\n/);
const match = /\r?\n/.exec(html);
this.brLen = match !== null ? match[0].length : 0;
this.ruleset = ruleset;
this.messages = [];
}
info(message, line, col, rule, raw) {
this.report("info", message, line, col, rule, raw);
}
warn(message, line, col, rule, raw) {
this.report("warning", message, line, col, rule, raw);
}
error(message, line, col, rule, raw) {
this.report("error", message, line, col, rule, raw);
}
report(type, message, line, col, rule, raw) {
const lines = this.lines;
const brLen = this.brLen;
let evidence = '';
let evidenceLen = 0;
for (let i = line - 1, lineCount = lines.length; i < lineCount; i++) {
evidence = lines[i];
evidenceLen = evidence.length;
if (col > evidenceLen && line < lineCount) {
line++;
col -= evidenceLen;
if (col !== 1) {
col -= brLen;
}
}
else {
break;
}
}
this.messages.push({
type: type,
message: message,
raw: raw,
evidence: evidence,
line: line,
col: col,
rule: {
id: rule.id,
description: rule.description,
link: `https://htmlhint.com/docs/user-guide/rules/${rule.id}`,
},
});
}
}
reporter.default = Reporter;
var rules = {};
var altRequire = {};
Object.defineProperty(altRequire, "__esModule", { value: true });
altRequire.default = {
id: 'alt-require',
description: 'The alt attribute of an <img> element must be present and alt attribute of area[href] and input[type=image] must have a value.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const tagName = event.tagName.toLowerCase();
const mapAttrs = parser.getMapAttrs(event.attrs);
const col = event.col + tagName.length + 1;
let selector;
if (tagName === 'img' && !('alt' in mapAttrs)) {
reporter.warn('An alt attribute must be present on <img> elements.', event.line, col, this, event.raw);
}
else if ((tagName === 'area' && 'href' in mapAttrs) ||
(tagName === 'input' && mapAttrs['type'] === 'image')) {
if (!('alt' in mapAttrs) || mapAttrs['alt'] === '') {
selector = tagName === 'area' ? 'area[href]' : 'input[type=image]';
reporter.warn(`The alt attribute of ${selector} must have a value.`, event.line, col, this, event.raw);
}
}
});
},
};
var attrLowercase = {};
Object.defineProperty(attrLowercase, "__esModule", { value: true });
const svgIgnores = [
'allowReorder',
'attributeName',
'attributeType',
'autoReverse',
'baseFrequency',
'baseProfile',
'calcMode',
'clipPath',
'clipPathUnits',
'contentScriptType',
'contentStyleType',
'diffuseConstant',
'edgeMode',
'externalResourcesRequired',
'filterRes',
'filterUnits',
'glyphRef',
'gradientTransform',
'gradientUnits',
'kernelMatrix',
'kernelUnitLength',
'keyPoints',
'keySplines',
'keyTimes',
'lengthAdjust',
'limitingConeAngle',
'markerHeight',
'markerUnits',
'markerWidth',
'maskContentUnits',
'maskUnits',
'numOctaves',
'onBlur',
'onChange',
'onClick',
'onFocus',
'onKeyUp',
'onLoad',
'pathLength',
'patternContentUnits',
'patternTransform',
'patternUnits',
'pointsAtX',
'pointsAtY',
'pointsAtZ',
'preserveAlpha',
'preserveAspectRatio',
'primitiveUnits',
'refX',
'refY',
'repeatCount',
'repeatDur',
'requiredExtensions',
'requiredFeatures',
'specularConstant',
'specularExponent',
'spreadMethod',
'startOffset',
'stdDeviation',
'stitchTiles',
'surfaceScale',
'systemLanguage',
'tableValues',
'targetX',
'targetY',
'textLength',
'viewBox',
'viewTarget',
'xChannelSelector',
'yChannelSelector',
'zoomAndPan',
];
function testAgainstStringOrRegExp(value, comparison) {
if (comparison instanceof RegExp) {
return comparison.test(value)
? { match: value, pattern: comparison }
: false;
}
const firstComparisonChar = comparison[0];
const lastComparisonChar = comparison[comparison.length - 1];
const secondToLastComparisonChar = comparison[comparison.length - 2];
const comparisonIsRegex = firstComparisonChar === '/' &&
(lastComparisonChar === '/' ||
(secondToLastComparisonChar === '/' && lastComparisonChar === 'i'));
const hasCaseInsensitiveFlag = comparisonIsRegex && lastComparisonChar === 'i';
if (comparisonIsRegex) {
const valueMatches = hasCaseInsensitiveFlag
? new RegExp(comparison.slice(1, -2), 'i').test(value)
: new RegExp(comparison.slice(1, -1)).test(value);
return valueMatches;
}
return value === comparison;
}
attrLowercase.default = {
id: 'attr-lowercase',
description: 'All attribute names must be in lowercase.',
init(parser, reporter, options) {
const exceptions = (Array.isArray(options) ? options : []).concat(svgIgnores);
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
const attrName = attr.name;
if (!exceptions.find((exp) => testAgainstStringOrRegExp(attrName, exp)) &&
attrName !== attrName.toLowerCase()) {
reporter.error(`The attribute name of [ ${attrName} ] must be in lowercase.`, event.line, col + attr.index, this, attr.raw);
}
}
});
},
};
var attrSorted = {};
Object.defineProperty(attrSorted, "__esModule", { value: true });
attrSorted.default = {
id: 'attr-sorted',
description: 'Attribute tags must be in proper order.',
init(parser, reporter) {
const orderMap = {};
const sortOrder = [
'class',
'id',
'name',
'src',
'for',
'type',
'href',
'value',
'title',
'alt',
'role',
];
for (let i = 0; i < sortOrder.length; i++) {
orderMap[sortOrder[i]] = i;
}
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
const listOfAttributes = [];
for (let i = 0; i < attrs.length; i++) {
listOfAttributes.push(attrs[i].name);
}
const originalAttrs = JSON.stringify(listOfAttributes);
listOfAttributes.sort((a, b) => {
if (orderMap[a] == undefined && orderMap[b] == undefined) {
return 0;
}
if (orderMap[a] == undefined) {
return 1;
}
else if (orderMap[b] == undefined) {
return -1;
}
return orderMap[a] - orderMap[b] || a.localeCompare(b);
});
if (originalAttrs !== JSON.stringify(listOfAttributes)) {
reporter.error(`Inaccurate order ${originalAttrs} should be in hierarchy ${JSON.stringify(listOfAttributes)} `, event.line, event.col, this, event.raw);
}
});
},
};
var attrNoDuplication = {};
Object.defineProperty(attrNoDuplication, "__esModule", { value: true });
attrNoDuplication.default = {
id: 'attr-no-duplication',
description: 'Elements cannot have duplicate attributes.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
let attrName;
const col = event.col + event.tagName.length + 1;
const mapAttrName = {};
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
attrName = attr.name;
if (mapAttrName[attrName] === true) {
reporter.error(`Duplicate of attribute name [ ${attr.name} ] was found.`, event.line, col + attr.index, this, attr.raw);
}
mapAttrName[attrName] = true;
}
});
},
};
var attrUnsafeChars = {};
Object.defineProperty(attrUnsafeChars, "__esModule", { value: true });
attrUnsafeChars.default = {
id: 'attr-unsafe-chars',
description: 'Attribute values cannot contain unsafe chars.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
const regUnsafe = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/;
let match;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
match = regUnsafe.exec(attr.value);
if (match !== null) {
const unsafeCode = escape(match[0])
.replace(/%u/, '\\u')
.replace(/%/, '\\x');
reporter.warn(`The value of attribute [ ${attr.name} ] cannot contain an unsafe char [ ${unsafeCode} ].`, event.line, col + attr.index, this, attr.raw);
}
}
});
},
};
var attrValueDoubleQuotes = {};
Object.defineProperty(attrValueDoubleQuotes, "__esModule", { value: true });
attrValueDoubleQuotes.default = {
id: 'attr-value-double-quotes',
description: 'Attribute values must be in double quotes.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
if ((attr.value !== '' && attr.quote !== '"') ||
(attr.value === '' && attr.quote === "'")) {
reporter.error(`The value of attribute [ ${attr.name} ] must be in double quotes.`, event.line, col + attr.index, this, attr.raw);
}
}
});
},
};
var attrValueNotEmpty = {};
Object.defineProperty(attrValueNotEmpty, "__esModule", { value: true });
attrValueNotEmpty.default = {
id: 'attr-value-not-empty',
description: 'All attributes must have values.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
if (attr.quote === '' && attr.value === '') {
reporter.warn(`The attribute [ ${attr.name} ] must have a value.`, event.line, col + attr.index, this, attr.raw);
}
}
});
},
};
var attrValueSingleQuotes = {};
Object.defineProperty(attrValueSingleQuotes, "__esModule", { value: true });
attrValueSingleQuotes.default = {
id: 'attr-value-single-quotes',
description: 'Attribute values must be in single quotes.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
if ((attr.value !== '' && attr.quote !== "'") ||
(attr.value === '' && attr.quote === '"')) {
reporter.error(`The value of attribute [ ${attr.name} ] must be in single quotes.`, event.line, col + attr.index, this, attr.raw);
}
}
});
},
};
var attrWhitespace = {};
Object.defineProperty(attrWhitespace, "__esModule", { value: true });
attrWhitespace.default = {
id: 'attr-whitespace',
description: 'All attributes should be separated by only one space and not have leading/trailing whitespace.',
init(parser, reporter, options) {
const exceptions = Array.isArray(options)
? options
: [];
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
attrs.forEach((elem) => {
attr = elem;
const attrName = elem.name;
if (exceptions.indexOf(attrName) !== -1) {
return;
}
if (elem.value.trim() !== elem.value) {
reporter.error(`The attributes of [ ${attrName} ] must not have leading or trailing whitespace.`, event.line, col + attr.index, this, attr.raw);
}
if (elem.value.replace(/ +(?= )/g, '') !== elem.value) {
reporter.error(`The attributes of [ ${attrName} ] must be separated by only one space.`, event.line, col + attr.index, this, attr.raw);
}
});
});
},
};
var doctypeFirst = {};
Object.defineProperty(doctypeFirst, "__esModule", { value: true });
doctypeFirst.default = {
id: 'doctype-first',
description: 'Doctype must be declared first.',
init(parser, reporter) {
const allEvent = (event) => {
if (event.type === 'start' ||
(event.type === 'text' && /^\s*$/.test(event.raw))) {
return;
}
if ((event.type !== 'comment' && event.long === false) ||
/^DOCTYPE\s+/i.test(event.content) === false) {
reporter.error('Doctype must be declared first.', event.line, event.col, this, event.raw);
}
parser.removeListener('all', allEvent);
};
parser.addListener('all', allEvent);
},
};
var doctypeHtml5 = {};
Object.defineProperty(doctypeHtml5, "__esModule", { value: true });
doctypeHtml5.default = {
id: 'doctype-html5',
description: 'Invalid doctype. Use: "<!DOCTYPE html>"',
init(parser, reporter) {
const onComment = (event) => {
if (event.long === false &&
event.content.toLowerCase() !== 'doctype html') {
reporter.warn('Invalid doctype. Use: "<!DOCTYPE html>"', event.line, event.col, this, event.raw);
}
};
const onTagStart = () => {
parser.removeListener('comment', onComment);
parser.removeListener('tagstart', onTagStart);
};
parser.addListener('all', onComment);
parser.addListener('tagstart', onTagStart);
},
};
var headScriptDisabled = {};
Object.defineProperty(headScriptDisabled, "__esModule", { value: true });
headScriptDisabled.default = {
id: 'head-script-disabled',
description: 'The <script> tag cannot be used in a <head> tag.',
init(parser, reporter) {
const reScript = /^(text\/javascript|application\/javascript)$/i;
let isInHead = false;
const onTagStart = (event) => {
const mapAttrs = parser.getMapAttrs(event.attrs);
const type = mapAttrs.type;
const tagName = event.tagName.toLowerCase();
if (tagName === 'head') {
isInHead = true;
}
if (isInHead === true &&
tagName === 'script' &&
(!type || reScript.test(type) === true)) {
reporter.warn('The <script> tag cannot be used in a <head> tag.', event.line, event.col, this, event.raw);
}
};
const onTagEnd = (event) => {
if (event.tagName.toLowerCase() === 'head') {
parser.removeListener('tagstart', onTagStart);
parser.removeListener('tagend', onTagEnd);
}
};
parser.addListener('tagstart', onTagStart);
parser.addListener('tagend', onTagEnd);
},
};
var hrefAbsOrRel = {};
Object.defineProperty(hrefAbsOrRel, "__esModule", { value: true });
hrefAbsOrRel.default = {
id: 'href-abs-or-rel',
description: 'An href attribute must be either absolute or relative.',
init(parser, reporter, options) {
const hrefMode = options === 'abs' ? 'absolute' : 'relative';
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
if (attr.name === 'href') {
if ((hrefMode === 'absolute' && /^\w+?:/.test(attr.value) === false) ||
(hrefMode === 'relative' &&
/^https?:\/\//.test(attr.value) === true)) {
reporter.warn(`The value of the href attribute [ ${attr.value} ] must be ${hrefMode}.`, event.line, col + attr.index, this, attr.raw);
}
break;
}
}
});
},
};
var htmlLangRequire = {};
Object.defineProperty(htmlLangRequire, "__esModule", { value: true });
const regular = '(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)';
const irregular = '(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)';
const grandfathered = `(?<grandfathered>${irregular}|${regular})`;
const privateUse = '(?<privateUse>x(-[A-Za-z0-9]{1,8})+)';
const privateUse2 = '(?<privateUse2>x(-[A-Za-z0-9]{1,8})+)';
const singleton = '[0-9A-WY-Za-wy-z]';
const extension = `(?<extension>${singleton}(-[A-Za-z0-9]{2,8})+)`;
const variant = '(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3})';
const region = '(?<region>[A-Za-z]{2}|[0-9]{3})';
const script = '(?<script>[A-Za-z]{4})';
const extlang = '(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2})';
const language = `(?<language>([A-Za-z]{2,3}(-${extlang})?)|[A-Za-z]{4}|[A-Za-z]{5,8})`;
const langtag = `(${language}(-${script})?` +
`(-${region})?` +
`(-${variant})*` +
`(-${extension})*` +
`(-${privateUse})?` +
')';
const languageTag = `(${grandfathered}|${langtag}|${privateUse2})`;
htmlLangRequire.default = {
id: 'html-lang-require',
description: 'The lang attribute of an <html> element must be present and should be valid.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const tagName = event.tagName.toLowerCase();
const mapAttrs = parser.getMapAttrs(event.attrs);
const col = event.col + tagName.length + 1;
const langValidityPattern = new RegExp(languageTag, 'g');
if (tagName === 'html') {
if ('lang' in mapAttrs) {
if (!mapAttrs['lang']) {
reporter.warn('The lang attribute of <html> element must have a value.', event.line, col, this, event.raw);
}
else if (!langValidityPattern.test(mapAttrs['lang'])) {
reporter.warn('The lang attribute value of <html> element must be a valid BCP47.', event.line, col, this, event.raw);
}
}
else {
reporter.warn('An lang attribute must be present on <html> elements.', event.line, col, this, event.raw);
}
}
});
},
};
var idClassAdDisabled = {};
Object.defineProperty(idClassAdDisabled, "__esModule", { value: true });
idClassAdDisabled.default = {
id: 'id-class-ad-disabled',
description: 'The id and class attributes cannot use the ad keyword, it will be blocked by adblock software.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
let attrName;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
attrName = attr.name;
if (/^(id|class)$/i.test(attrName)) {
if (/(^|[-_])ad([-_]|$)/i.test(attr.value)) {
reporter.warn(`The value of attribute ${attrName} cannot use the ad keyword.`, event.line, col + attr.index, this, attr.raw);
}
}
}
});
},
};
var idClassValue = {};
Object.defineProperty(idClassValue, "__esModule", { value: true });
idClassValue.default = {
id: 'id-class-value',
description: 'The id and class attribute values must meet the specified rules.',
init(parser, reporter, options) {
const arrRules = {
underline: {
regId: /^[a-z\d]+(_[a-z\d]+)*$/,
message: 'The id and class attribute values must be in lowercase and split by an underscore.',
},
dash: {
regId: /^[a-z\d]+(-[a-z\d]+)*$/,
message: 'The id and class attribute values must be in lowercase and split by a dash.',
},
hump: {
regId: /^[a-z][a-zA-Z\d]*([A-Z][a-zA-Z\d]*)*$/,
message: 'The id and class attribute values must meet the camelCase style.',
},
};
let rule;
if (typeof options === 'string') {
rule = arrRules[options];
}
else {
rule = options;
}
if (typeof rule === 'object' && rule.regId) {
let regId = rule.regId;
const message = rule.message;
if (!(regId instanceof RegExp)) {
regId = new RegExp(regId);
}
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l1 = attrs.length; i < l1; i++) {
attr = attrs[i];
if (attr.name.toLowerCase() === 'id') {
if (regId.test(attr.value) === false) {
reporter.warn(message, event.line, col + attr.index, this, attr.raw);
}
}
if (attr.name.toLowerCase() === 'class') {
const arrClass = attr.value.split(/\s+/g);
let classValue;
for (let j = 0, l2 = arrClass.length; j < l2; j++) {
classValue = arrClass[j];
if (classValue && regId.test(classValue) === false) {
reporter.warn(message, event.line, col + attr.index, this, classValue);
}
}
}
}
});
}
},
};
var idUnique = {};
Object.defineProperty(idUnique, "__esModule", { value: true });
idUnique.default = {
id: 'id-unique',
description: 'The value of id attributes must be unique.',
init(parser, reporter) {
const mapIdCount = {};
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
let id;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
if (attr.name.toLowerCase() === 'id') {
id = attr.value;
if (id) {
if (mapIdCount[id] === undefined) {
mapIdCount[id] = 1;
}
else {
mapIdCount[id]++;
}
if (mapIdCount[id] > 1) {
reporter.error(`The id value [ ${id} ] must be unique.`, event.line, col + attr.index, this, attr.raw);
}
}
break;
}
}
});
},
};
var inlineScriptDisabled = {};
Object.defineProperty(inlineScriptDisabled, "__esModule", { value: true });
inlineScriptDisabled.default = {
id: 'inline-script-disabled',
description: 'Inline script cannot be used.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
let attrName;
const reEvent = /^on(unload|message|submit|select|scroll|resize|mouseover|mouseout|mousemove|mouseleave|mouseenter|mousedown|load|keyup|keypress|keydown|focus|dblclick|click|change|blur|error)$/i;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
attrName = attr.name.toLowerCase();
if (reEvent.test(attrName) === true) {
reporter.warn(`Inline script [ ${attr.raw} ] cannot be used.`, event.line, col + attr.index, this, attr.raw);
}
else if (attrName === 'src' || attrName === 'href') {
if (/^\s*javascript:/i.test(attr.value)) {
reporter.warn(`Inline script [ ${attr.raw} ] cannot be used.`, event.line, col + attr.index, this, attr.raw);
}
}
}
});
},
};
var inlineStyleDisabled = {};
Object.defineProperty(inlineStyleDisabled, "__esModule", { value: true });
inlineStyleDisabled.default = {
id: 'inline-style-disabled',
description: 'Inline style cannot be used.',
init(parser, reporter) {
parser.addListener('tagstart', (event) => {
const attrs = event.attrs;
let attr;
const col = event.col + event.tagName.length + 1;
for (let i = 0, l = attrs.length; i < l; i++) {
attr = attrs[i];
if (attr.name.toLowerCase() === 'style') {
reporter.warn(`Inline style [ ${attr.raw} ] cannot be used.`, event.line, col + attr.index, this, attr.raw);
}
}
});
},
};
var inputRequiresLabel = {};
Object.defineProperty(inputRequiresLabel, "__esModule", { value: true });
inputRequiresLabel.default = {
id: 'input-requires-label',
description: 'All [ input ] tags must have a corresponding [ label ] tag. ',
init(parser, reporter) {
const labelTags = [];
const inputTags = [];
parser.addListener('tagstart', (event) => {
const tagName = event.tagName.toLowerCase();
const mapAttrs = parser.getMapAttrs(event.attrs);
const col = event.col + tagName.length + 1;
if (tagName === 'input') {
if (mapAttrs['type'] !== 'hidden') {
inputTags.push({ event: event, col: col, id: mapAttrs['id'] });
}
}
if (tagName === 'label') {
if ('for' in mapAttrs && mapAttrs['for'] !== '') {
labelTags.push({ event: event, col: col, forValue: mapAttrs['for'] });
}
}
});
parser.addListener('end', () => {
inputTags.forEach((inputTag) => {