Skip to content

Commit

Permalink
fix: report error evidence if tag attrs include \r\n
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniswang committed Oct 30, 2015
1 parent 91fe82a commit 86adde1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HTMLHint change log
====================

## ver 0.9.13 (2015-10-25)
## ver 0.9.13 (2015-10-30)

add:

Expand All @@ -10,6 +10,10 @@ add:
3. add formatters: compact, markdown
4. add cli parameter:`--nocolor`, disable color in cli

fix:

1. fix: report error evidence if tag attrs include `\r\n`

## ver 0.9.10 (2015-10-12)

add:
Expand Down
2 changes: 1 addition & 1 deletion lib/htmlhint.js

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,39 @@
self.ruleset = ruleset;
self.messages = [];
},
//错误
// error message
error: function(message, line, col, rule, raw){
this.report('error', message, line, col, rule, raw);
},
//警告
// warning message
warn: function(message, line, col, rule, raw){
this.report('warning', message, line, col, rule, raw);
},
//信息
// info message
info: function(message, line, col, rule, raw){
this.report('info', message, line, col, rule, raw);
},
//报告
// save report
report: function(type, message, line, col, rule, raw){
var self = this;
var lines = self.lines;
var evidence, evidenceLen;
for(var i=line-1, lineCount=lines.length;i<lineCount;i++){
evidence = lines[i];
evidenceLen = evidence.length;
if(col > evidenceLen && line < lineCount){
line ++;
col -= evidenceLen;
}
else{
break;
}
}
self.messages.push({
type: type,
message: message,
raw: raw,
evidence: self.lines[line-1],
evidence: evidence,
line: line,
col: col,
rule: {
Expand All @@ -49,4 +62,4 @@

HTMLHint.Reporter = Reporter;

})(HTMLHint);
})(HTMLHint);
9 changes: 8 additions & 1 deletion test/rules/attr-lowercase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ describe('Rules: '+ruldId, function(){
expect(messages[0].rule.id).to.be(ruldId);
expect(messages[0].line).to.be(1);
expect(messages[0].col).to.be(3);

code = '<p id=""\r\n TEST="abc">';
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(2);
expect(messages[0].col).to.be(1);
});

it('Lowercase attr should not result in an error', function(){
Expand All @@ -35,4 +42,4 @@ describe('Rules: '+ruldId, function(){
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});
});
});

0 comments on commit 86adde1

Please sign in to comment.