@@ -252,6 +252,44 @@ rstudio_source_markers <- function(lints) {
252252 autoSelect = " first" )
253253}
254254
255+ # ' Checkstyle Report for lint results
256+ # '
257+ # ' Generate a report of the linting results using the Checkstyle xml format
258+ # ' @param lints the linting results.
259+ # ' @param reportName the name of the output report. It will be generated and stored
260+ # ' in a reports/ directory.
261+ # ' @export
262+ checkstyle_output <- function (lints , reportName = " lint_checkstyle_results.xml" ) {
263+
264+ # Auto-create a results directory, if one has no existed previously
265+ if (! dir.exists(" results" )) {
266+ dir.create(" results" )
267+ }
268+ reportPath = paste(" results/" , reportName , sep = " " )
269+ file.create(reportPath )
270+
271+ # setup file
272+ cat(" <?xml version=\" 1.0\" encoding=\" utf-8\" ?>" , file = reportPath , sep = " \n " , append = TRUE )
273+ cat(" <checkstyle version=\" 4.3\" >" , file = reportPath , sep = " \n " , append = TRUE )
274+
275+ # output the style markers to the file
276+ lapply(lints , function (x ) {
277+ # Need to replace left carat for xml report
278+ msg <- sub(" <" , " >" , x $ message )
279+
280+ filemsg = paste(" \t <file name=\" " , x $ filename , " \" >" , sep = " " )
281+ cat(filemsg , file = reportPath , " \n " , append = TRUE )
282+
283+ errmsg = paste(" \t\t <error line=\" " , x $ line_number ," \" column=\" " , x $ column ,
284+ " \" severity=\" error\" message=\" " ,msg ," \" />" , sep = " " )
285+ cat(errmsg , file = reportPath , sep = " \n " , append = TRUE )
286+
287+ cat(" \t </file>" , file = reportPath , sep = " \n " , append = TRUE )
288+ })
289+
290+ cat(" </checkstyle>" , file = reportPath , sep = " \n " , append = TRUE )
291+ }
292+
255293highlight_string <- function (message , column_number = NULL , ranges = NULL ) {
256294
257295 maximum <- max(column_number , unlist(ranges ))
0 commit comments