Skip to content

Commit 872277d

Browse files
[code-quality] Use all_linters(), apply
1 parent 0dc5292 commit 872277d

15 files changed

Lines changed: 84 additions & 79 deletions

.lintr

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
linters: linters_with_defaults(
1+
linters: all_linters(
22
fixed_regex_linter(),
33
function_argument_linter(),
4+
implicit_assignment_linter(allow_lazy = TRUE, allow_scoped = TRUE),
45
implicit_integer_linter(allow_colon = TRUE),
56
infix_spaces_linter(exclude_operators = c("=", "*", "/")),
6-
# TODO(michaelchirico): Enable once quotes used for parallelism are supported
7-
# keyword_quote_linter(),
87
line_length_linter(120L),
98
string_boundary_linter(),
10-
undesirable_function_linter(c(
11-
sapply = NA
12-
)),
9+
# undesirable_function_linter(modify_defaults(
10+
# default_undesirable_functions,
11+
# sapply = NA
12+
# )),
1313
# TODO(michaelchirico): Enable after #2245
1414
# unnecessary_nested_if_linter(),
1515
assignment_linter = NULL,
1616
# TODO(michaelchirico): reactivate this and spaces_inside_linter()
1717
# once they support 'empty' i argument DT[ , j]
1818
commas_linter = NULL,
1919
commented_code_linter = NULL,
20-
cyclocomp_linter = NULL,
20+
cyclocomp_linter = NULL, # TODO(michaelchirico): fix translate_package().
2121
# TODO(michaelchirico): reactivate this. far too many
2222
# false positives for now.
2323
indentation_linter = NULL,
24+
# TODO(michaelchirico): Enable once quotes used for parallelism are supported
25+
keyword_quote_linter = NULL,
26+
nonportable_path_linter = NULL,
2427
object_name_linter = NULL,
2528
quotes_linter = NULL, # TODO(michaelchirico): switch to "'",
26-
spaces_inside_linter = NULL
29+
spaces_inside_linter = NULL,
30+
todo_comment_linter = NULL # TODO(michaelchirico): [hehe] activate this & assign TODOs bugs
2731
)
2832
exclusions: list(
2933
"inst/pkg",
34+
"tests/testthat.R" = list(undesirable_function_linter = Inf),
3035
"tests/testthat" = list(object_usage_linter = Inf),
3136
"tests/testthat/test_packages",
3237
"vignettes" = list(

R/check_cracked_messages.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ attr(check_cracked_messages, "diagnostic_tag") =
7373
# take a call like stop("a", i, "b", j) and suggest
7474
# stop(domain=NA, gettextf("a%sb%s", i, j))
7575
build_gettextf_call = function(e) {
76-
call <- as.character(e[[1L]])
76+
call_str <- as.character(e[[1L]])
7777
rest <- e[-1L]
7878
arg_names <- names(rest)
7979
if (is.null(arg_names) || all(keep_args <- arg_names %chin% c("", "domain"))) {
80-
as.character(glue('{call}(domain=NA, {gettextify(rest)})'))
80+
as.character(glue('{call_str}(domain=NA, {gettextify(rest)})'))
8181
} else {
8282
# if other arguments, e.g. call., appendLF, immediate. are present, keep them with the right call (#227)
8383
kwargs = toString(paste(names(rest[!keep_args]), "=", vapply(rest[!keep_args], deparse1, character(1L))))
84-
as.character(glue('{call}(domain=NA, {gettextify(rest[keep_args])}, {kwargs})'))
84+
as.character(glue('{call_str}(domain=NA, {gettextify(rest[keep_args])}, {kwargs})'))
8585
}
8686
}
8787

R/find_fuzzy_messages.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ find_fuzzy_messages <- function(message_data, lang_file) {
66
message('Typically, this means the corresponding error messages have been refactored.')
77
message('Reproducing these messages here for your reference since they might still provide some utility.')
88

9-
dashes = strrep('-', .9*getOption('width'))
9+
dashes = strrep('-', 0.9*getOption('width'))
1010
old_message_data[idx & type == 'singular', {
1111
if (.N > 0L) {
1212
message(' ** SINGULAR MESSAGES **')

R/get_message_data.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ get_message_data = function(
9595
if (verbose && dir.exists(file.path(dir, "R"))) message('Getting R-level messages...')
9696
r_message_data = get_r_messages(
9797
dir,
98+
# nolint next: backport_linter. False positive on 'R'.
9899
custom_translation_functions = custom_translation_functions$R,
99100
style = style,
100101
is_base = is_base

R/get_po_messages.R

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,38 +84,38 @@ get_po_messages <- function(po_file) {
8484

8585
msg_j = 1L
8686
while (msg_j <= length(msgid_start)) {
87-
start = msgid_start[msg_j]
88-
end = find_msg_end(start)
89-
set(po_data, msg_j, 'msgid', build_msg(start, end, 'msgid'))
87+
start_j = msgid_start[msg_j]
88+
end_j = find_msg_end(start_j)
89+
set(po_data, msg_j, 'msgid', build_msg(start_j, end_j, 'msgid'))
9090

91-
set(po_data, msg_j, 'fuzzy', as.integer(start != 1L && startsWith(po_lines[start - 1L], "#, fuzzy")))
91+
set(po_data, msg_j, 'fuzzy', as.integer(start_j != 1L && startsWith(po_lines[start_j - 1L], "#, fuzzy")))
9292

93-
start = end + 1L
94-
end = find_msg_end(start)
95-
set(po_data, msg_j, 'msgstr', build_msg(start, end, 'msgstr'))
93+
start_j = end_j + 1L
94+
end_j = find_msg_end(start_j)
95+
set(po_data, msg_j, 'msgstr', build_msg(start_j, end_j, 'msgstr'))
9696
msg_j = msg_j + 1L
9797
}
9898

9999
plural_i = 1L
100100
while (plural_i <= length(msgid_plural_start)) {
101-
start = msgid_plural_start[plural_i]
102-
end = find_msg_end(start)
103-
msg1 = build_msg(start, end, 'msgid')
101+
start_j = msgid_plural_start[plural_i]
102+
end_j = find_msg_end(start_j)
103+
msg1 = build_msg(start_j, end_j, 'msgid')
104104

105-
set(po_data, msg_j, 'fuzzy', as.integer(start != 1L && startsWith(po_lines[start - 1L], "#, fuzzy")))
105+
set(po_data, msg_j, 'fuzzy', as.integer(start_j != 1L && startsWith(po_lines[start_j - 1L], "#, fuzzy")))
106106

107-
start = end + 1L
108-
end = find_msg_end(start)
109-
msg2 = build_msg(start, end, 'msgid_plural')
107+
start_j = end_j + 1L
108+
end_j = find_msg_end(start_j)
109+
msg2 = build_msg(start_j, end_j, 'msgid_plural')
110110

111111
set(po_data, msg_j, 'msgid_plural', list(c(msg1, msg2)))
112112

113-
start = end + 1L
113+
start_j = end_j + 1L
114114
msgstr_plural = character()
115-
while (start <= po_length && startsWith(po_lines[start], 'msgstr[')) {
116-
end = find_msg_end(start)
117-
msgstr_plural = c(msgstr_plural, build_msg(start, end, 'msgstr\\[\\d+\\]'))
118-
start = end + 1L
115+
while (start_j <= po_length && startsWith(po_lines[start_j], 'msgstr[')) {
116+
end_j = find_msg_end(start_j)
117+
msgstr_plural = c(msgstr_plural, build_msg(start_j, end_j, 'msgstr\\[\\d+\\]'))
118+
start_j = end_j + 1L
119119
}
120120
set(po_data, msg_j, 'msgstr_plural', list(msgstr_plural))
121121

@@ -125,11 +125,9 @@ get_po_messages <- function(po_file) {
125125

126126
# somewhat hacky approach -- strip the comment markers & recurse;
127127
# retain the same file pattern to ensure 'message_source' is correct
128-
writeLines(
129-
gsub("^#~ ", "", grep("^#~ ", po_lines, value = TRUE)),
130-
tmp <- tempfile(pattern = basename(po_file))
131-
)
128+
tmp <- tempfile(pattern = basename(po_file))
132129
on.exit(unlink(tmp))
130+
writeLines(gsub("^#~ ", "", grep("^#~ ", po_lines, value = TRUE)), tmp)
133131
deprecated = get_po_messages(tmp)
134132
if (nrow(deprecated) > 0L) {
135133
set(deprecated, NULL, 'fuzzy', 2L)

R/get_r_messages.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ parse_r_keywords = function(spec) {
219219
named_idx = grepl("^[a-zA-Z0-9._]+\\|[0-9]+$", keyval$V2)
220220
plural_idx = grepl("^[a-zA-Z0-9._]+\\|[0-9]+,[a-zA-Z0-9._]+\\|[0-9]+$", keyval$V2)
221221
dots_idx = grepl("^[.]{3}[\\](?:[a-zA-Z0-9._]+,)*[a-zA-Z0-9._]+$", keyval$V2)
222-
if (any(idx <- !named_idx & !dots_idx & !plural_idx)) {
222+
if (any(bad_idx <- !named_idx & !dots_idx & !plural_idx)) {
223223
stopf(
224224
# nolint next: line_length_linter.
225225
"Invalid custom translator specification(s): %s.\nAll inputs for R must be key-value pairs like fn:arg1|n1[,arg2|n2] or fn:...\\arg1,...,argn.",
226-
toString(spec[idx])
226+
toString(spec[bad_idx])
227227
)
228228
}
229229

R/get_src_messages.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ get_file_src_messages = function(file, custom_params = NULL) {
265265
parse_src_keywords = function(spec) {
266266
if (!length(spec)) return(data.table(NULL))
267267

268-
if (!all(idx <- grepl("[a-zA-Z0-9_]+:[0-9]+", spec))) {
268+
if (!all(kwd_idx <- grepl("[a-zA-Z0-9_]+:[0-9]+", spec))) {
269269
stopf(
270270
# nolint next: line_length_linter.
271271
"Invalid custom translator specification(s): %s.\nAll inputs for src must be key-value pairs like fn:arg1. Custom plural messagers are not yet supported.",
272-
toString(spec[!idx])
272+
toString(spec[!kwd_idx])
273273
)
274274
}
275275

R/msgmerge.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
# https://docs.oracle.com/cd/E36784_01/html/E36870/msgmerge-1.html#scrolltoc
55
run_msgmerge <- function(po_file, pot_file, previous = FALSE, verbose = TRUE) {
66
check_potools_sys_reqs("msgmerge")
7-
args <- c(
7+
msgmerge_args <- c(
88
"--update", shQuote(path.expand(po_file)),
99
"--backup=off",
1010
if (previous) "--previous", #show previous match for fuzzy matches
1111
shQuote(path.expand(pot_file))
1212
)
1313

1414
if (verbose) {
15-
message("Running system command msgmerge ", paste(args, collapse = " "), "...")
15+
message("Running system command msgmerge ", paste(msgmerge_args, collapse = " "), "...")
1616
}
17-
val <- system2("msgmerge", args, stdout = TRUE, stderr = TRUE)
17+
val <- system2("msgmerge", msgmerge_args, stdout = TRUE, stderr = TRUE)
1818
if (!identical(attr(val, "status", exact = TRUE), NULL)) {
1919
# nocov these warnings? i don't know how to trigger them as of this writing.
2020
warningf("Running msgmerge on './po/%s' failed:\n %s", basename(po_file), paste(val, collapse = "\n"))
@@ -27,7 +27,7 @@ run_msgmerge <- function(po_file, pot_file, previous = FALSE, verbose = TRUE) {
2727
warningf("tools::checkPoFile() found some issues in %s", po_file)
2828
print(res)
2929
}
30-
return(invisible())
30+
invisible()
3131
}
3232

3333
run_msgfmt = function(po_file, mo_file, verbose) {
@@ -80,21 +80,21 @@ update_en_quot_mo_files <- function(dir, verbose) {
8080
# https://docs.oracle.com/cd/E36784_01/html/E36870/msginit-1.html#scrolltoc
8181
run_msginit <- function(po_path, pot_path, locale, width = 80L, verbose = TRUE) {
8282
check_potools_sys_reqs("msginit")
83-
args <- c(
83+
msginit_args <- c(
8484
"-i", shQuote(path.expand(pot_path)),
8585
"-o", shQuote(path.expand(po_path)),
8686
"-l", shQuote(locale),
8787
"-w", width,
8888
"--no-translator" # don't consult user-email etc
8989
)
9090
if (verbose) {
91-
message("Running system command msginit ", paste(args, collapse = " "), "...")
91+
message("Running system command msginit ", paste(msginit_args, collapse = " "), "...")
9292
}
93-
val <- system2("msginit", args, stdout = TRUE, stderr = TRUE)
93+
val <- system2("msginit", msginit_args, stdout = TRUE, stderr = TRUE)
9494
if (!identical(attr(val, "status", exact = TRUE), NULL)) {
9595
stopf("Running msginit on '%s' failed", pot_path)
9696
} else if (verbose) {
9797
messagef(paste(val, collapse = "\n"))
9898
}
99-
return(invisible())
99+
invisible()
100100
}

R/po_compile.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ po_compile = function(dir = ".", package = NULL, lazy = TRUE, verbose = TRUE) {
3333
}
3434

3535
for (ii in seq_len(nrow(po_metadata))) {
36-
row <- po_metadata[ii]
37-
if (verbose) messagef("Recompiling '%s' %s translation", row$language, row$type)
38-
run_msgfmt(row$po, row$mo, verbose = verbose)
36+
row_ii <- po_metadata[ii]
37+
if (verbose) messagef("Recompiling '%s' %s translation", row_ii$language, row_ii$type)
38+
run_msgfmt(row_ii$po, row_ii$mo, verbose = verbose)
3939
}
4040

41-
return(invisible())
41+
invisible()
4242
}
4343

4444

R/po_create.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ po_create <- function(languages, dir = ".", verbose = !is_testing()) {
2020
po_files <- po_language_files(languages, dir)
2121

2222
for (ii in seq_len(nrow(po_files))) {
23-
row <- po_files[ii]
24-
if (file.exists(row$po_path)) {
25-
if (verbose) messagef("Updating '%s' %s translation", row$language, row$type)
26-
run_msgmerge(row$po_path, row$pot_path, previous = TRUE, verbose = verbose)
23+
row_ii <- po_files[ii]
24+
if (file.exists(row_ii$po_path)) {
25+
if (verbose) messagef("Updating '%s' %s translation", row_ii$language, row_ii$type)
26+
run_msgmerge(row_ii$po_path, row_ii$pot_path, previous = TRUE, verbose = verbose)
2727
} else {
28-
if (verbose) messagef("Creating '%s' %s translation", row$language, row$type)
29-
run_msginit(row$po_path, row$pot_path, locale = row$language, verbose = verbose)
28+
if (verbose) messagef("Creating '%s' %s translation", row_ii$language, row_ii$type)
29+
run_msginit(row_ii$po_path, row_ii$pot_path, locale = row_ii$language, verbose = verbose)
3030
}
3131
}
3232

0 commit comments

Comments
 (0)