Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R] [ci] move linting code out of package #8545

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/r_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ jobs:

- name: Run lintr
run: |
cd R-package
MAKEFLAGS="-j$(nproc)" R CMD INSTALL .
MAKEFLAGS="-j$(nproc)" R CMD INSTALL R-package/
# Disable lintr errors for now: https://github.com/dmlc/xgboost/issues/8012
Rscript tests/helper_scripts/run_lint.R || true
Rscript tests/ci_build/lint_r.R $(pwd) || true

test-R-on-Windows:
runs-on: ${{ matrix.config.os }}
Expand Down
2 changes: 0 additions & 2 deletions R-package/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ Suggests:
Ckmeans.1d.dp (>= 3.3.1),
vcd (>= 1.3),
testthat,
lintr,
igraph (>= 1.0.1),
float,
crayon,
titanic
Depends:
R (>= 3.3.0)
Expand Down
2 changes: 0 additions & 2 deletions R-package/tests/helper_scripts/install_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ pkgs <- c(
"Ckmeans.1d.dp",
"vcd",
"testthat",
"lintr",
trivialfis marked this conversation as resolved.
Show resolved Hide resolved
"igraph",
"float",
"crayon",
"titanic",
## imports
"Matrix",
Expand Down
71 changes: 0 additions & 71 deletions R-package/tests/helper_scripts/run_lint.R

This file was deleted.

72 changes: 72 additions & 0 deletions tests/ci_build/lint_r.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
library(lintr)

args <- commandArgs(
trailingOnly = TRUE
)
SOURCE_DIR <- args[[1L]]

FILES_TO_LINT <- list.files(
path = SOURCE_DIR
, pattern = "\\.r$|\\.rmd$"
, all.files = TRUE
, ignore.case = TRUE
, full.names = TRUE
, recursive = TRUE
, include.dirs = FALSE
)

my_linters <- list(
absolute_path_linter = lintr::absolute_path_linter(),
assignment_linter = lintr::assignment_linter(),
brace_linter = lintr::brace_linter(),
commas_linter = lintr::commas_linter(),
equals_na = lintr::equals_na_linter(),
infix_spaces_linter = lintr::infix_spaces_linter(),
line_length_linter = lintr::line_length_linter(),
no_tab_linter = lintr::no_tab_linter(),
object_usage_linter = lintr::object_usage_linter(),
object_length_linter = lintr::object_length_linter(),
semicolon = lintr::semicolon_linter(),
seq = lintr::seq_linter(),
spaces_inside_linter = lintr::spaces_inside_linter(),
spaces_left_parentheses_linter = lintr::spaces_left_parentheses_linter(),
trailing_blank_lines_linter = lintr::trailing_blank_lines_linter(),
trailing_whitespace_linter = lintr::trailing_whitespace_linter(),
true_false = lintr::T_and_F_symbol_linter(),
unneeded_concatenation = lintr::unneeded_concatenation_linter()
)

noquote(paste0(length(FILES_TO_LINT), " R files need linting"))

results <- NULL

for (r_file in FILES_TO_LINT) {

this_result <- lintr::lint(
filename = r_file
, linters = my_linters
, cache = FALSE
)

print(
sprintf(
"Found %i linting errors in %s"
, length(this_result)
, r_file
)
, quote = FALSE
)

results <- c(results, this_result)

}

issues_found <- length(results)

noquote(paste0("Total linting issues found: ", issues_found))

if (issues_found > 0L) {
print(results)
}

quit(save = "no", status = 1L)