diff --git a/R/check_cracked_messages.R b/R/check_cracked_messages.R index d1c781a..3c7b0e1 100644 --- a/R/check_cracked_messages.R +++ b/R/check_cracked_messages.R @@ -65,7 +65,7 @@ check_cracked_messages = function(message_data) { set(dup_messages, ii, "replacement", build_gettextf_call(dup_messages$call_expr[[ii]])) } - return(dup_messages[ , .(call, file, line_number, replacement)]) + dup_messages[ , .(call, file, line_number, replacement)] } attr(check_cracked_messages, "diagnostic_tag") = "R messaging calls that might be better suited for gettextf for ease of translation" @@ -105,8 +105,8 @@ count_dots = function(call) { call, function(x) { e = match.call(definition, x) - if (is.null(names(e))) return(length(e) - 1L) - return(length(e) - sum(names(e) %chin% c("call.", "immediate.", "noBreaks.", "domain", "appendLF")) - 1L) + n_excluded = sum(names(e) %chin% c("call.", "immediate.", "noBreaks.", "domain", "appendLF")) + length(e) - n_excluded - 1L }, integer(1L) ) diff --git a/R/check_untranslated_cat.R b/R/check_untranslated_cat.R index d3f4960..1a598cb 100644 --- a/R/check_untranslated_cat.R +++ b/R/check_untranslated_cat.R @@ -75,10 +75,10 @@ check_untranslated_cat <- function(message_data) { set(cat_calls, ii, "replacement", build_suggested_cat_call(cat_calls$call_expr[[ii]])) } - return(cat_calls[ + cat_calls[ nzchar(replacement), .(call, file, line_number, replacement) - ]) + ] } attr(check_untranslated_cat, "diagnostic_tag") = "untranslated messaging calls passed through cat()" @@ -124,5 +124,5 @@ build_suggested_cat_call = function(e) { no_translated_subcall <- function(e) { if (!is.call(e)) return(TRUE) if (is.name(e[[1L]]) && e[[1L]] %chin% c("gettext", "gettextf", "ngettext")) return(FALSE) - return(all(vapply(e[-1L], no_translated_subcall, logical(1L)))) + all(vapply(e[-1L], no_translated_subcall, logical(1L))) } diff --git a/R/check_untranslated_src.R b/R/check_untranslated_src.R index 7da9389..ea13f4f 100644 --- a/R/check_untranslated_src.R +++ b/R/check_untranslated_src.R @@ -44,9 +44,9 @@ check_untranslated_src <- function(message_data) { if (!is.data.table(message_data)) message_data = as.data.table(message_data) - return(message_data[ + message_data[ message_source == "src" & !is_marked_for_translation, .(call, file, line_number, replacement = NA_character_) - ]) + ] } attr(check_untranslated_src, "diagnostic_tag") <- "src messaging calls that were not properly marked for translation" diff --git a/R/explain_plurals.R b/R/explain_plurals.R index c6248be..92572ba 100644 --- a/R/explain_plurals.R +++ b/R/explain_plurals.R @@ -47,7 +47,7 @@ po_explain_plurals <- function(language, index) { ) ] } - return(invisible()) + invisible() } # just here to generate translations. comes from the PLURAL_RANGE_STRINGS csv diff --git a/R/get_r_messages.R b/R/get_r_messages.R index 897a4cd..bdfc6ea 100644 --- a/R/get_r_messages.R +++ b/R/get_r_messages.R @@ -197,7 +197,7 @@ parse_r_files = function(dir, is_base) { return(out) } names(out) = r_files - return(out) + out } # inspired by the --keyword argument in gettext, but customized to make sense for R. @@ -463,32 +463,32 @@ drop_suppressed_and_named = function(calls_data, expr_data, target_args) { build_call = function(lines, comments, params) { if (params$line1 == params$line2) { return(substr(adjust_tabs(lines[params$line1]), params$col1, params$col2)) - } else { - lines = lines[params$line1:params$line2] - - # substring not substr here so we can eschew providing - # last=nchar(lines[1L]) because we'd need to recalculate it after adjust_tabs() - lines[1L] = substring(adjust_tabs(lines[1L]), params$col1) - lines[length(lines)] = substring(adjust_tabs(lines[length(lines)]), 1L, params$col2) - - # strip comments, _after_ getting the tab-adjusted column #s - for (ii in seq_len(nrow(comments))) { - # we've already subset lines, so line numbers have to be re-mapped - adj_line_idx = comments$line1[ii] - params$line1 + 1L - # column number has to be re-mapped relative to col1 as well, but only on line1 itself - col_adj = if (adj_line_idx == 1L) params$col1 else 1L - lines[adj_line_idx] = substr( - lines[adj_line_idx], - 1L, - comments$col1[ii] - col_adj - ) - } + } - # strip internal whitespace across lines in the call - # NB: eventually, this will need to be smarter about multi-line STR_CONST... - # for now, just wave hands around those.... - return(paste(trimws(lines), collapse = " ")) + lines = lines[params$line1:params$line2] + + # substring not substr here so we can eschew providing + # last=nchar(lines[1L]) because we'd need to recalculate it after adjust_tabs() + lines[1L] = substring(adjust_tabs(lines[1L]), params$col1) + lines[length(lines)] = substring(adjust_tabs(lines[length(lines)]), 1L, params$col2) + + # strip comments, _after_ getting the tab-adjusted column #s + for (ii in seq_len(nrow(comments))) { + # we've already subset lines, so line numbers have to be re-mapped + adj_line_idx = comments$line1[ii] - params$line1 + 1L + # column number has to be re-mapped relative to col1 as well, but only on line1 itself + col_adj = if (adj_line_idx == 1L) params$col1 else 1L + lines[adj_line_idx] = substr( + lines[adj_line_idx], + 1L, + comments$col1[ii] - col_adj + ) } + + # strip internal whitespace across lines in the call + # NB: eventually, this will need to be smarter about multi-line STR_CONST... + # for now, just wave hands around those.... + paste(trimws(lines), collapse = " ") } adjust_tabs = function(l) { @@ -526,7 +526,7 @@ clean_text = function(x) { # e.g. in 'a string with an \"escaped\" quote', the escapes for " disappear after parsing. See #128 x = gsub("(?:^|(?