格式化scalastyle结果
(self, output_file)
| 138 | return config_file |
| 139 | |
| 140 | def format_issues(self, output_file): |
| 141 | """格式化scalastyle结果 |
| 142 | """ |
| 143 | if not os.path.exists(output_file): |
| 144 | LogPrinter.info("分析失败") |
| 145 | return [] |
| 146 | issues = [] |
| 147 | root = ET.parse(output_file).getroot() |
| 148 | files = root.findall("file") |
| 149 | for file_node in files: |
| 150 | errors = file_node.findall("error") |
| 151 | for error in errors: |
| 152 | path = file_node.get("name") |
| 153 | rule = error.get("source") |
| 154 | line = error.get("line") |
| 155 | # 有些是文件层级错误没有line信息 |
| 156 | if not line: |
| 157 | line = 1 |
| 158 | column = error.get("column") |
| 159 | if not column: |
| 160 | column = "1" |
| 161 | msg = error.get("message") |
| 162 | if rule not in self.rules: |
| 163 | continue |
| 164 | issues.append( |
| 165 | { |
| 166 | "path": path[self.pos :], |
| 167 | "line": int(line), |
| 168 | "column": column, |
| 169 | "msg": msg, |
| 170 | "rule": rule, |
| 171 | } |
| 172 | ) |
| 173 | return issues |
| 174 | |
| 175 | |
| 176 | tool = ScalaStyle |