diff options
author | mattab <matthieu.aubry@gmail.com> | 2016-07-13 02:36:43 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2016-07-13 05:37:17 +0300 |
commit | 4807614e301d218fd0da109ee8c7372fd5a053cf (patch) | |
tree | c62569d5c1ab8dca12567ef79296c0c7ebee09af /tests/javascript/index.php | |
parent | dd6e07bb0cbe2238bc186f5671e494c426ea589f (diff) |
Make JSlint errors output actually useful to developers
Diffstat (limited to 'tests/javascript/index.php')
-rw-r--r-- | tests/javascript/index.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/javascript/index.php b/tests/javascript/index.php index 57cbd4d086..9b4d9464d3 100644 --- a/tests/javascript/index.php +++ b/tests/javascript/index.php @@ -435,14 +435,31 @@ function PiwikTest() { test("JSLint", function() { expect(1); var src = '<?php + $src = file_get_contents('../../js/piwik.js'); + + //Once we use JSHint instead of jslint, we could remove this code and use the following feature instead: +// /* jshint ignore:start */ +// // Code here will be linted with ignored by JSHint. +// /* jshint ignore:end */ $src = strtr($src, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/')); - $src = substr($src, strpos($src, '/* startjslint */')); - echo "$src"; ?>'; + $contentRemovedFromPos = strpos($src, '/* startjslint */'); + $contentRemoved=substr($src, 0, $contentRemovedFromPos); + $contentToJslint = substr($src, $contentRemovedFromPos); + + $countOfLinesRemoved = count(explode('\n', $contentRemoved)); + echo "$contentToJslint"; ?>'; var result = JSLINT(src); ok( result, "JSLint did not validate, please check the browser console for the list of jslint errors." ); if (console && console.log && !result) { + var countOfLinesRemoved = <?php echo $countOfLinesRemoved; ?>; + // to find the real line number, add countOfLinesRemoved to the line number from JSLint + JSLINT.errors.forEach( function (item, index) { + item.line += countOfLinesRemoved; + console.log(item); + }); + console.log('JSLINT errors', JSLINT.errors); } // alert(JSLINT.report(true)); |