R/trailing_whitespace_style.R

Defines functions trailing_whitespace_style

Documented in trailing_whitespace_style

### roger: Automated grading of R scripts
###
### Validation of unnecessary trailing whitespace.
###
### AUTHORS: Jean-Christophe Langlois, Vincent Goulet <vincent.goulet@act.ulaval.ca>
### LICENSE: GPL 2 or later

trailing_whitespace_style <- function(srcData)
{
    ## Get source code from argument.
    Lines <- srcData$Lines

    ## Guard against null parse data.
    if (is.null(Lines))
        stop("no source code; ",
             "use 'getSourceData' with 'keep.source = TRUE'")

    ## Check that lines do not contain trailing whitespace.
    valid <- !grepl(r"([[:blank:]]$)", Lines)
    res <- all(valid)

    ## Return an error message for lines that are not valid.
    if (!res)
    {
        lines <- which(!valid)
        msg <- sapply(lines, function(l)
            .makeMessage(gettext("Line"), " ", l, ": ",
                         gettext("tidy up and delete unnecessary trailing whitespace"),
                         appendLF = TRUE))
        attributes(res) <- list(lines = lines, message = msg)
        message(msg, appendLF = FALSE)
    }

    res
}

Try the roger package in your browser

Any scripts or data that you put into this service are public.

roger documentation built on Oct. 24, 2023, 9:07 a.m.