-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. add rule: space-tab-mixed-disabled 2. add default rule: attr-no-duplication
- Loading branch information
Showing
14 changed files
with
158 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
"browser": true, | ||
"wsh": true, | ||
"-W099": true, | ||
|
||
"predef": [ | ||
"HTMLHint", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
TODO | ||
================== | ||
|
||
1. reporter support | ||
2. w3c rule | ||
1. add rule: Relative path | ||
2. add rule: Absolute path | ||
3. add rule: adblock | ||
4. add comment support: `<!-- htmlhint doctype-first:false-->` | ||
4. reporter support | ||
5. w3c rule |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> | ||
* MIT Licensed | ||
*/ | ||
HTMLHint.addRule({ | ||
id: 'attr-no-duplication', | ||
description: 'Attribute name can not been duplication.', | ||
init: function(parser, reporter){ | ||
var self = this; | ||
parser.addListener('tagstart', function(event){ | ||
var attrs = event.attrs; | ||
var attr; | ||
var attrName; | ||
var col = event.col + event.tagName.length + 1; | ||
|
||
var mapAttrName = {}; | ||
for(var i=0, l=attrs.length;i<l;i++){ | ||
attr = attrs[i]; | ||
attrName = attr.name; | ||
if(mapAttrName[attrName] === true){ | ||
reporter.error('The name of attribute [ '+attr.name+' ] been duplication.', event.line, col + attr.index, self, attr.raw); | ||
} | ||
mapAttrName[attrName] = true; | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> | ||
* MIT Licensed | ||
*/ | ||
HTMLHint.addRule({ | ||
id: 'space-tab-mixed-disabled', | ||
description: 'Spaces and tabs can not mixed in front of line.', | ||
init: function(parser, reporter){ | ||
var self = this; | ||
parser.addListener('text', function(event){ | ||
if(event.pos === 0 && /^( +\t|\t+ )/.test(event.raw) === true){ | ||
reporter.warn('Mixed spaces and tabs in front of line.', event.line, 0, self, event.raw); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
var expect = require("expect.js"); | ||
|
||
var HTMLHint = require("../../index").HTMLHint; | ||
|
||
var ruldId = 'attr-no-duplication', | ||
ruleOptions = {}; | ||
|
||
ruleOptions[ruldId] = true; | ||
|
||
describe('Rules: '+ruldId, function(){ | ||
|
||
it('Attribute name been duplication should result in an error', function(){ | ||
var code = '<a href="a" href="b">bbb</a>'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(1); | ||
expect(messages[0].rule.id).to.be(ruldId); | ||
expect(messages[0].line).to.be(1); | ||
expect(messages[0].col).to.be(12); | ||
}); | ||
|
||
it('Attribute name not been duplication should not result in an error', function(){ | ||
var code = '<a href="a">bbb</a>'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(0); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2014, Yanis Wang <yanis.wang@gmail.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
var expect = require("expect.js"); | ||
|
||
var HTMLHint = require("../../index").HTMLHint; | ||
|
||
var ruldId = 'space-tab-mixed-disabled', | ||
ruleOptions = {}; | ||
|
||
ruleOptions[ruldId] = true; | ||
|
||
describe('Rules: '+ruldId, function(){ | ||
|
||
it('Spaces and tabs mixed in front of line should result in an error', function(){ | ||
// space before tab | ||
var code = ' <a href="a">bbb</a>'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(1); | ||
expect(messages[0].rule.id).to.be(ruldId); | ||
expect(messages[0].line).to.be(1); | ||
expect(messages[0].col).to.be(0); | ||
// tab before space | ||
code = ' <a href="a">bbb</a>'; | ||
messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(1); | ||
expect(messages[0].rule.id).to.be(ruldId); | ||
expect(messages[0].line).to.be(1); | ||
expect(messages[0].col).to.be(0); | ||
}); | ||
|
||
it('Only spaces in front of line should not result in an error', function(){ | ||
var code = ' <a href="a">bbb</a>'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(0); | ||
}); | ||
|
||
it('Only tabs in front of line should not result in an error', function(){ | ||
var code = ' <a href="a">bbb</a>'; | ||
var messages = HTMLHint.verify(code, ruleOptions); | ||
expect(messages.length).to.be(0); | ||
}); | ||
|
||
}); |