ant-jshint icon indicating copy to clipboard operation
ant-jshint copied to clipboard

Plain Reporter prints Error Message for result even if there are no errors

Open ojintoad opened this issue 12 years ago • 3 comments
trafficstars

for(JsHintResult result : report.getResults()) {
   output.append("\n");
   output.append(getFileFailureMessage((result.getFile()) + "\n"));
   for(JsHintError error : result.getErrors()) {
        output.append(getIssueMessage(error.getReason(), error.getEvidence(), error.getLine(), error.getCharacter()) + "\n");
   }
}

The above code block is from https://github.com/philmander/ant-jshint/blob/master/src/main/java/com/philmander/jshint/report/PlainJsHintReporter.java

When the reporter runs, it just checks once if the entire report has errors and then assumes all results are errors. It would be nice to have logic that distinguishes results with errors from results with successes. I.e. : if(results.getNumErrors() > 0) { error logic } else { success logic }

This might be nice for some of the xml reporters as well but they don't write language that indicates an error but rather just print out all result files by name with no error report. The PlainJsHintReporter uses the getFileFailureMessage every time, no matter if the individual file failed or not, which is confusing.

Thank you very much for this library, it is by far the easiest way to get JSHint integrated into a build system on multiple platforms (windows and linux). I'm using it through Gradle and it works wonderfully.

ojintoad avatar Jan 07 '13 22:01 ojintoad

Hi, I'm glad to hear you find the task useful!

Specifically, what 'non-error' result data would you expect to see?

Currently a JSHintResult object is just a wrapper for a Javascript file name and any JSHint errors found. And I think the only data I can get out of JSHint after it has evaluated a JS file are the errors, if any.

Phil

philmander avatar Jan 08 '13 01:01 philmander

Oh, I'm thinking you'd just like to see an exact list of the files which were actually validated right?

philmander avatar Jan 08 '13 01:01 philmander

Right, I'd like to either see no data or a success message.

Just to make sure I'm not communicating poorly:

I have 10 js files. 5 of them have errors. I run jshint on all 10. The plain reporter prints the getFileFailure message ("JSHint validation failed for " + file;) for all the files (10 times), which isn't correct for 5 of the files. Instead it should either print out only the message for the 5 files that fail or print out 5 success messages and 5 failure messages.

for(JsHintResult result : report.getResults()) {
   if(result.getNumErrors() > 0) { //print error results
      output.append("\n");
      output.append(getFileFailureMessage((result.getFile()) + "\n"));
      for(JsHintError error : result.getErrors()) {
        output.append(getIssueMessage(error.getReason(), error.getEvidence(), error.getLine(), error.getCharacter()) + "\n");
      }
   } else {
      //optionally print a success message for this result
   }
}

ojintoad avatar Jan 08 '13 16:01 ojintoad