-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
head-script-disabled.js
28 lines (28 loc) · 1.06 KB
/
head-script-disabled.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
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
HTMLHint.addRule({
id: 'head-script-disabled',
description: 'The <script> tag cannot be used in a <head> tag.',
init: function(parser, reporter){
var self = this;
var reScript = /^(text\/javascript|application\/javascript)$/i;
function onTagStart(event){
var mapAttrs = parser.getMapAttrs(event.attrs);
var type = mapAttrs.type;
if(event.tagName.toLowerCase() === 'script' &&
(!type || reScript.test(type) === true)){
reporter.warn('The <script> tag cannot be used in a <head> tag.', event.line, event.col, self, event.raw);
}
}
function onTagEnd(event){
if(event.tagName.toLowerCase() === 'head'){
parser.removeListener('tagstart', onTagStart);
parser.removeListener('tagstart', onTagEnd);
}
}
parser.addListener('tagstart', onTagStart);
parser.addListener('tagend', onTagEnd);
}
});