tomasbjerre / violations-lib

Java library for parsing report files from static code analysis.
Apache License 2.0
148 stars 39 forks source link

Checkstyle: don't fail if line attribute is not present #107

Closed fouadchamoun closed 4 years ago

fouadchamoun commented 4 years ago

Hi !

I'm having trouble parsing scalastyle (checkstyle) files as some of the errors don't have the "line" attribute. For example :

java.lang.RuntimeException: "line" not found in "<error source="org.scalastyle.file.NewLineAtEofChecker" severity="error" message="File must end with newline character"/>"
        at shadow.se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute(ViolationParserUtils.java:81)
        at shadow.se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute(ViolationParserUtils.java:128)
        at shadow.se.bjurr.violations.lib.parsers.CheckStyleParser.parseReportOutput(CheckStyleParser.java:35)
        at shadow.se.bjurr.violations.lib.reports.Parser.findViolations(Parser.java:122)
        at shadow.se.bjurr.violations.lib.ViolationsApi.violations(ViolationsApi.java:85)
        at se.bjurr.violations.main.Runner.getAllParsedViolations(Runner.java:398)
        at se.bjurr.violations.main.Runner.performTask(Runner.java:270)
        at se.bjurr.violations.main.Runner.main(Runner.java:259)
        at se.bjurr.violations.main.Main.main(Main.java:6)

Could we make it optional like the "column" attribute ?

https://github.com/tomasbjerre/violations-lib/blob/28da15daf35478ca72256be269bee5804c5d2ed6/src/main/java/se/bjurr/violations/lib/parsers/CheckStyleParser.java#L35

Thank you 😃

fouadchamoun commented 4 years ago

btw, i'm using the library through violations-command-line npm package

tomasbjerre commented 4 years ago

Do you have a sample xml?

fouadchamoun commented 4 years ago

there you go:

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
 <file name="/home/fchamoun/work/data-analytics/databricks/apps/data-streaming/src/main/scala/com/work/spark/dynamoDb/utils/KafkaDataReader.scala">
  <error source="org.scalastyle.file.NewLineAtEofChecker" severity="error" message="File must end with newline character"/>
 </file>
</checkstyle>
tomasbjerre commented 4 years ago

released in 1.10 of violations-command-line

fouadchamoun commented 4 years ago

thank you very much @tomasbjerre !