-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlint-pretty.R
87 lines (75 loc) · 2.57 KB
/
lint-pretty.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env Rscript
library(argparse)
library(crayon)
library(lintr)
library(spongebob)
.VERSION <- "0.0.1"
parser <- argparse::ArgumentParser(
description = "Lint R code with {lintr}"
)
parser$add_argument(
"--dir-to-lint"
, type = "character"
, help = "Directory to lint"
)
parser$add_argument(
"--version"
, action = "store_true"
, help = "Print the version of this linting tool."
)
# Grab args (store in constants for easier debugging)
args <- parser$parse_args()
DIR_TO_LINT <- args[["dir_to_lint"]]
# print version and exit early if --version was passed
if (isTRUE(args[["version"]])){
cat(paste0(.VERSION, "\n"))
quit(save = "no", status = 0)
}
cat(crayon::yellow(
spongebob::spongebobsay(
what = "linting is important"
, print = FALSE
)
))
cat("\n\n")
LINTERS_TO_USE <- list(
"absolute_path" = lintr::absolute_path_linter
, "assignment" = lintr::assignment_linter
, "closed_curly" = lintr::closed_curly_linter
, "commas" = lintr::commas_linter
, "equals_na" = lintr::equals_na_linter
, "function_left" = lintr::function_left_parentheses_linter
, "implicit_integers" = lintr::implicit_integer_linter
, "infix_spaces" = lintr::infix_spaces_linter
, "long_lines" = lintr::line_length_linter(length = 120L)
, "no_tabs" = lintr::no_tab_linter
, "non_portable_path" = lintr::nonportable_path_linter
, "open_curly" = lintr::open_curly_linter
, "paren_brace_linter" = lintr::paren_brace_linter
, "semicolon" = lintr::semicolon_terminator_linter
, "seq" = lintr::seq_linter
, "single_quotes" = lintr::single_quotes_linter
, "spaces_inside" = lintr::spaces_inside_linter
, "spaces_left_parens" = lintr::spaces_left_parentheses_linter
, "todo_comments" = lintr::todo_comment_linter(c("todo", "fixme", "to-do"))
, "trailing_blank" = lintr::trailing_blank_lines_linter
, "trailing_white" = lintr::trailing_whitespace_linter
, "true_false" = lintr::T_and_F_symbol_linter
, "unneeded_concatenation" = lintr::unneeded_concatenation_linter
)
issues <- lintr::lint_dir(
path = DIR_TO_LINT
, linters = LINTERS_TO_USE
)
num_issues <- length(issues)
print(issues)
header_txt <- sprintf(
"\n---------- %i issues found ----------\n"
, num_issues
)
if (num_issues == 0) {
cat(crayon::green(header_txt))
} else {
cat(crayon::red(header_txt))
}
quit(save = "no", status = num_issues)