Skip to content

Commit

Permalink
fix col position
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniswang committed Oct 30, 2015
1 parent 86adde1 commit 99aceeb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/htmlhint.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var HTMLHint = (function (undefined) {
}

var parser = new HTMLParser();
var reporter = new HTMLHint.Reporter(html.split(/\r?\n/), ruleset);
var reporter = new HTMLHint.Reporter(html, ruleset);

var rules = HTMLHint.rules,
rule;
Expand Down
11 changes: 9 additions & 2 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
};

Reporter.prototype = {
_init: function(lines, ruleset){
_init: function(html, ruleset){
var self = this;
self.lines = lines;
self.html = html;
self.lines = html.split(/\r?\n/);
var match = html.match(/\r?\n/);
self.brLen = match !== null ? match[0].length : 0;
self.ruleset = ruleset;
self.messages = [];
},
Expand All @@ -32,13 +35,17 @@
report: function(type, message, line, col, rule, raw){
var self = this;
var lines = self.lines;
var brLen = self.brLen;
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;
if(col !== 1){
col -= brLen;
}
}
else{
break;
Expand Down
7 changes: 5 additions & 2 deletions test/rules/attr-lowercase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ describe('Rules: '+ruldId, function(){
expect(messages[0].line).to.be(1);
expect(messages[0].col).to.be(3);

code = '<p id=""\r\n TEST="abc">';
code = '<p id=""\r\n TEST1="abc" TEST2="abc">';
messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(1);
expect(messages.length).to.be(2);
expect(messages[0].rule.id).to.be(ruldId);
expect(messages[0].line).to.be(2);
expect(messages[0].col).to.be(1);
expect(messages[1].rule.id).to.be(ruldId);
expect(messages[1].line).to.be(2);
expect(messages[1].col).to.be(13);
});

it('Lowercase attr should not result in an error', function(){
Expand Down

0 comments on commit 99aceeb

Please sign in to comment.