Skip to content

Commit

Permalink
head-script-disabled(fule): No head not result error
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniswang committed Oct 7, 2015
1 parent 8576cd4 commit 96abbe2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fix:

1. Fix issue: #77 `<link rel=icon><link rel=icon>`
2. Made the descriptions and error messages of rules more clear to people
3. head-script-disabled(fule): No head not result error

## ver 0.9.7 (2015-3-8)

Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ module.exports = function(grunt) {
browser: {
src: ['src/**/*.js'],
options: {
jshintrc: ".jshintrc1"
jshintrc: ".jshintrc-browser"
}
},
node: {
src: ['Gruntfile.js', 'test/**/*.js', 'bin/*'],
options: {
jshintrc: ".jshintrc2"
jshintrc: ".jshintrc-node"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/htmlhint.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/rules/head-script-disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ HTMLHint.addRule({
init: function(parser, reporter){
var self = this;
var reScript = /^(text\/javascript|application\/javascript)$/i;
var isInHead = false;
function onTagStart(event){
var mapAttrs = parser.getMapAttrs(event.attrs);
var type = mapAttrs.type;
if(event.tagName.toLowerCase() === 'script' &&
var 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, self, event.raw);
}
Expand All @@ -25,4 +31,4 @@ HTMLHint.addRule({
parser.addListener('tagstart', onTagStart);
parser.addListener('tagend', onTagEnd);
}
});
});
8 changes: 7 additions & 1 deletion test/rules/head-script-disabled.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ describe('Rules: '+ruldId, function(){
expect(messages.length).to.be(0);
});

});
it('No head not result in an error', function(){
var code = '<html><script src="test.js"></script></html>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});

});

0 comments on commit 96abbe2

Please sign in to comment.