forked from microsoft/LightGBM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added R linting and changed R code to comma-first (fixes microsoft#2373)
- Loading branch information
Showing
39 changed files
with
1,472 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# [description] | ||
# Lint R code in a directory for style | ||
# problems | ||
# [usage] | ||
# ./.ci/lint_r.sh $(pwd) | ||
|
||
SOURCE_DIR=${1} | ||
|
||
# failure is a natural part of life | ||
set -e | ||
|
||
echo "" | ||
echo "Checking code for R style problems..." | ||
echo "" | ||
|
||
Rscript $(pwd)/.ci/lint_r_code.R \ | ||
--source-dir ${SOURCE_DIR} | ||
|
||
echo "" | ||
echo "Done checking code for style problems." | ||
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
library(argparse) | ||
library(lintr) | ||
|
||
parser <- argparse::ArgumentParser() | ||
parser$add_argument( | ||
"--source-dir" | ||
, type = "character" | ||
, help = "Fully-qualified directory to search for R files" | ||
) | ||
args <- parser$parse_args() | ||
|
||
SOURCE_DIR <- args[["source_dir"]] | ||
|
||
FILES_TO_LINT <- list.files( | ||
path = SOURCE_DIR | ||
, pattern = "\\.r$" | ||
, all.files = TRUE | ||
, ignore.case = TRUE | ||
, full.names = TRUE | ||
, recursive = TRUE | ||
, include.dirs = FALSE | ||
) | ||
|
||
LINTERS_TO_USE <- list( | ||
"open_curly" = lintr::open_curly_linter | ||
, "closed_curly" = lintr::closed_curly_linter | ||
, "tabs" = lintr::no_tab_linter | ||
, "spaces" = lintr::infix_spaces_linter | ||
, "trailing_blank" = lintr::trailing_blank_lines_linter | ||
, "trailing_white" = lintr::trailing_whitespace_linter | ||
, "long_lines" = lintr::line_length_linter(length = 120) | ||
) | ||
|
||
cat(sprintf("Found %i R files to lint\n", length(FILES_TO_LINT))) | ||
|
||
results <- c() | ||
|
||
for (r_file in FILES_TO_LINT){ | ||
|
||
this_result <- lintr::lint( | ||
filename = r_file | ||
, linters = LINTERS_TO_USE | ||
, cache = FALSE | ||
) | ||
|
||
cat(sprintf( | ||
"Found %i linting errors in %s\n" | ||
, length(this_result) | ||
, r_file | ||
)) | ||
|
||
results <- c(results, this_result) | ||
|
||
} | ||
|
||
issues_found <- length(results) | ||
|
||
if (issues_found > 0){ | ||
cat("\n") | ||
print(results) | ||
} | ||
|
||
quit(save = "no", status = issues_found) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.