.azure-pipelines/scripts/check_code_style.R

#!/usr/bin/env
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
  stop("Please provide the directory path", call.=FALSE)
}

library("lintr")

check_code_style <- function(args) {
  skip_tests = c("package.R")
  if (length(args) > 1) {
    skip_tests <- append(skip_tests, unlist(strsplit(args[2], ";")))
  }

  directory = args[1]
  files <- list.files(directory)

  for (filename in files) {
    if (filename %in% skip_tests) {
      next
    }

    file <- file.path(".", "R", filename)

    style_issues <- lintr::lint(file, linters = with_defaults(
      line_length_linter = line_length_linter(240L),
      object_length_linter = object_length_linter(50L)
      )
    )

    if (length(style_issues) != 0) {
      print(file)
      print(style_issues)
      stop("Code quality failed.")
    }
  }
}

check_code_style(args)
Azure/azureml-sdk-for-r documentation built on Sept. 21, 2022, 5:45 a.m.