Skip to content

Commit

Permalink
Replace ignored content with empty content of same length/height for …
Browse files Browse the repository at this point in the history
…proper error reporting
  • Loading branch information
kangax committed Sep 12, 2014
1 parent e496983 commit 5c10fb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/jshint.js
Expand Up @@ -4798,12 +4798,14 @@ var JSHINT = (function () {
return;

reIgnoreStr = escapeRegex(delimiterPair.start) +
".*?" +
"[\\s\\S]*?" +
escapeRegex(delimiterPair.end);

reIgnore = new RegExp(reIgnoreStr, "ig");

s = s.replace(reIgnore, "");
s = s.replace(reIgnore, function(match) {
return match.replace(/./g, " ");
});
});
}

Expand Down
8 changes: 6 additions & 2 deletions tests/unit/fixtures/ignoreDelimiters.js
@@ -1,5 +1,9 @@
(function foo() {
'use strict';
someMethod('<?php foo('test') ?>');
return '<%= asset_path('test.png') %>' + '<% some_method() %>';
<%
if someCondition do
%>
someMethod('<?php foo('test') ?>')
<% end %>
return '<%= asset_path('foo.png') %>' + '<% some_method() %>';
})();
3 changes: 3 additions & 0 deletions tests/unit/options.js
Expand Up @@ -1652,11 +1652,14 @@ exports.ignoreDelimiters = function (test) {
var src = fs.readFileSync(__dirname + "/fixtures/ignoreDelimiters.js", "utf8");

TestRun(test)
// make sure line/column are still reported properly
.addError(6, "Missing semicolon.", { character: 37 })
.test(src, {
ignoreDelimiters: [
{ start: "<%=", end: "%>" },
{ start: "<%", end: "%>" },
{ start: "<?php", end: "?>" },
// make sure single tokens are ignored
{ start: "foo" },
{ end: "bar" }
]
Expand Down

0 comments on commit 5c10fb3

Please sign in to comment.