Skip to content

Commit 6dd25a5

Browse files
Merge pull request #1026 from IndrajeetPatil/index_integer_literals
2 parents f74502f + ca71391 commit 6dd25a5

30 files changed

+158
-147
lines changed

R/addins.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ style_active_file <- function() {
7878
if (save_after_styling_is_active() == TRUE && context$path != "") {
7979
rstudioapi::documentSave(context$id)
8080
}
81-
rstudioapi::setCursorPosition(context$selection[[1]]$range)
81+
rstudioapi::setCursorPosition(context$selection[[1L]]$range)
8282
}
8383

8484
#' Wrapper around [style_pkg()] for access via Addin.
@@ -123,18 +123,18 @@ save_after_styling_is_active <- function() {
123123
style_selection <- function() {
124124
communicate_addins_style_transformers()
125125
context <- get_rstudio_context()
126-
text <- context$selection[[1]]$text
126+
text <- context$selection[[1L]]$text
127127
if (all(nchar(text) == 0L)) abort("No code selected")
128128
out <- style_text(
129129
text,
130130
transformers = get_addins_style_transformer(),
131131
base_indention = nchar(gsub("^( *).*", "\\1", text))
132132
)
133133
rstudioapi::modifyRange(
134-
context$selection[[1]]$range,
134+
context$selection[[1L]]$range,
135135
paste0(c(
136136
out,
137-
if (context$selection[[1]]$range$end[2] == 1L) ""
137+
if (context$selection[[1L]]$range$end[2L] == 1L) ""
138138
), collapse = "\n"),
139139
id = context$id
140140
)

R/detect-alignment-utils.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ alignment_ensure_trailing_comma <- function(pd_by_line) {
9393
lag_newlines = 0L,
9494
spaces = 0L,
9595
pos_ids = NA,
96-
stylerignore = last_pd$stylerignore[1],
97-
indents = last_pd$indent[1]
96+
stylerignore = last_pd$stylerignore[1L],
97+
indents = last_pd$indent[1L]
9898
)
9999
tokens$.lag_spaces <- 0
100100

@@ -114,9 +114,9 @@ alignment_col1_all_named <- function(relevant_pd_by_line) {
114114
if (nrow(x) < 3L) {
115115
return(FALSE)
116116
}
117-
x$token[3] == "expr" &&
118-
any(c("SYMBOL_SUB", "STR_CONST", "SYMBOL_FORMALS") == x$token[1]) &&
119-
any(c("EQ_SUB", "EQ_FORMALS", "SPECIAL-IN", "LT", "GT", "EQ", "NE") == x$token[2])
117+
x$token[3L] == "expr" &&
118+
any(c("SYMBOL_SUB", "STR_CONST", "SYMBOL_FORMALS") == x$token[1L]) &&
119+
any(c("EQ_SUB", "EQ_FORMALS", "SPECIAL-IN", "LT", "GT", "EQ", "NE") == x$token[2L])
120120
}) %>%
121121
all()
122122
}

R/detect-alignment.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#' ")"
3939
#' )) %>%
4040
#' styler:::post_visit(transformers$initialize)
41-
#' nest <- pd_nested$child[[1]]
41+
#' nest <- pd_nested$child[[1L]]
4242
#' styler:::token_is_on_aligned_line(nest)
4343
#' }
4444
#' )
@@ -62,7 +62,7 @@ token_is_on_aligned_line <- function(pd_flat) {
6262
relevant_idx <- seq2(2L, last_idx)
6363
pd_by_line <- pd_by_line[relevant_idx]
6464

65-
relevant_lag_spaces_col_1 <- map_int(pd_by_line, ~ .x$.lag_spaces[1])
65+
relevant_lag_spaces_col_1 <- map_int(pd_by_line, ~ .x$.lag_spaces[1L])
6666

6767
col1_is_aligned <- length(unique(relevant_lag_spaces_col_1)) == 1L
6868
if (!col1_is_aligned) {
@@ -82,7 +82,7 @@ token_is_on_aligned_line <- function(pd_flat) {
8282
if (!all(has_correct_spacing_around_eq_sub)) {
8383
return(FALSE)
8484
}
85-
starting_with_comma <- map_lgl(pd_by_line, ~ .x$token[1] == "','")
85+
starting_with_comma <- map_lgl(pd_by_line, ~ .x$token[1L] == "','")
8686
if (any(starting_with_comma)) {
8787
return(FALSE)
8888
}

R/expr-is.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ is_curly_expr <- function(pd) {
1212
if (is.null(pd)) {
1313
return(FALSE)
1414
}
15-
pd$token[1] == "'{'"
15+
pd$token[1L] == "'{'"
1616
}
1717

1818
is_for_expr <- function(pd) {
19-
pd$token[1] == "FOR"
19+
pd$token[1L] == "FOR"
2020
}
2121

2222
#' @describeIn pd_is Checks whether `pd` contains is a conditional expression.
2323
#' @keywords internal
2424
is_cond_expr <- function(pd) {
25-
pd$token[1] == "IF"
25+
pd$token[1L] == "IF"
2626
}
2727

2828
#' @describeIn pd_is Checks whether `pd` contains is a while loop.
2929
#' @keywords internal
3030
is_while_expr <- function(pd) {
31-
pd$token[1] == "WHILE"
31+
pd$token[1L] == "WHILE"
3232
}
3333

3434
#' @describeIn pd_is Checks whether `pd` is a function call.
@@ -37,10 +37,10 @@ is_function_call <- function(pd) {
3737
if (is.null(pd)) {
3838
return(FALSE)
3939
}
40-
if (is.na(pd$token_before[2])) {
40+
if (is.na(pd$token_before[2L])) {
4141
return(FALSE)
4242
}
43-
pd$token_before[2] == "SYMBOL_FUNCTION_CALL"
43+
pd$token_before[2L] == "SYMBOL_FUNCTION_CALL"
4444
}
4545

4646
#' @describeIn pd_is Checks whether `pd` is a function declaration.
@@ -49,7 +49,7 @@ is_function_dec <- function(pd) {
4949
if (is.null(pd)) {
5050
return(FALSE)
5151
}
52-
pd$token[1] == "FUNCTION"
52+
pd$token[1L] == "FUNCTION"
5353
}
5454

5555
#' @describeIn pd_is Checks for every token whether or not it is a comment.
@@ -96,7 +96,7 @@ is_subset_expr <- function(pd) {
9696
if (is.null(pd) || nrow(pd) == 1) {
9797
return(FALSE)
9898
}
99-
pd$token[2] == "'['"
99+
pd$token[2L] == "'['"
100100
}
101101

102102

R/indent.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ NULL
1414
indent_without_paren_for_while_fun <- function(pd, indent_by) {
1515
tokens <- c("FOR", "WHILE", "FUNCTION")
1616
nrow <- nrow(pd)
17-
if (!(pd$token[1] %in% tokens)) {
17+
if (!(pd$token[1L] %in% tokens)) {
1818
return(pd)
1919
}
2020
if (is_curly_expr(pd$child[[nrow]])) {
@@ -32,8 +32,8 @@ indent_without_paren_for_while_fun <- function(pd, indent_by) {
3232
#' @importFrom rlang seq2
3333
#' @keywords internal
3434
indent_without_paren_if_else <- function(pd, indent_by) {
35-
expr_after_if <- next_non_comment(pd, which(pd$token == "')'")[1])
36-
is_if <- pd$token[1] == "IF"
35+
expr_after_if <- next_non_comment(pd, which(pd$token == "')'")[1L])
36+
is_if <- pd$token[1L] == "IF"
3737
if (!is_if) {
3838
return(pd)
3939
}
@@ -52,8 +52,8 @@ indent_without_paren_if_else <- function(pd, indent_by) {
5252
expr_after_else_idx <- next_non_comment(pd, else_idx)
5353
has_else_without_curly_or_else_chid <-
5454
any(pd$token == "ELSE") &&
55-
pd$child[[expr_after_else_idx]]$token[1] != "'{'" &&
56-
pd$child[[expr_after_else_idx]]$token[1] != "IF"
55+
pd$child[[expr_after_else_idx]]$token[1L] != "'{'" &&
56+
pd$child[[expr_after_else_idx]]$token[1L] != "IF"
5757

5858
needs_indention_now <- pd$lag_newlines[
5959
next_non_comment(pd, which(pd$token == "ELSE"))
@@ -97,7 +97,7 @@ compute_indent_indices <- function(pd,
9797
needs_indention <- needs_indention(pd, potential_triggers,
9898
other_trigger_tokens = c("EQ_SUB", "EQ_FORMALS")
9999
)
100-
trigger <- potential_triggers[needs_indention][1]
100+
trigger <- potential_triggers[needs_indention][1L]
101101
if (is.na(trigger)) {
102102
return(numeric(0))
103103
}
@@ -163,7 +163,7 @@ needs_indention <- function(pd,
163163
needs_indention_one <- function(pd,
164164
potential_trigger_pos,
165165
other_trigger_tokens) {
166-
before_first_break <- which(pd$lag_newlines > 0L)[1] - 1L
166+
before_first_break <- which(pd$lag_newlines > 0L)[1L] - 1L
167167
if (is.na(before_first_break)) {
168168
return(FALSE)
169169
}

R/nest.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ drop_cached_children <- function(pd) {
145145
#' styler:::get_parse_data(c("", "c(#", "1)", "#"))
146146
#' @keywords internal
147147
find_pos_id_to_keep <- function(pd) {
148-
if (pd$is_cached[1]) {
148+
if (pd$is_cached[1L]) {
149149
pd$pos_id[pd$parent <= 0]
150150
} else {
151151
pd$pos_id
@@ -292,9 +292,9 @@ add_attributes_caching <- function(pd_flat, transformers, more_specs) {
292292
pd_flat$block <- rep(NA, nrow(pd_flat))
293293
pd_flat$is_cached <- rep(FALSE, nrow(pd_flat))
294294
if (cache_is_activated()) {
295-
is_parent <- pd_flat$parent == 0
295+
is_parent <- pd_flat$parent == 0L
296296
pd_flat$is_cached[is_parent] <- map_lgl(
297-
pd_flat$text[pd_flat$parent == 0],
297+
pd_flat$text[pd_flat$parent == 0L],
298298
is_cached, transformers,
299299
more_specs = more_specs
300300
)

R/parse.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ parse_safely <- function(text, ...) {
4545
#' @param initial_text The initial text to style.
4646
#' @keywords internal
4747
has_crlf_as_first_line_sep <- function(message, initial_text) {
48-
split <- strsplit(message, ":", fixed = TRUE)[[1]]
49-
if (length(split) > 1L && split[1] == "<text>") {
50-
start_char <- as.numeric(split[3])
51-
offending_line <- initial_text[as.integer(split[2])]
48+
split <- strsplit(message, ":", fixed = TRUE)[[1L]]
49+
if (length(split) > 1L && split[1L] == "<text>") {
50+
start_char <- as.numeric(split[3L])
51+
offending_line <- initial_text[as.integer(split[2L])]
5252
if (!is.na(offending_line)) {
5353
if (substr(offending_line, start_char, start_char + 1) == "\r\n") {
5454
return(TRUE)

R/relevel.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ flatten_operators_one <- function(pd_nested) {
5252
#' from left or from right.
5353
#' @keywords internal
5454
flatten_pd <- function(pd_nested, token, child_token = token, left = TRUE) {
55-
token_pos_candidates <- which(pd_nested$token[-1] %in% token) + 1L
55+
token_pos_candidates <- which(pd_nested$token[-1L] %in% token) + 1L
5656
if (length(token_pos_candidates) == 0L) {
5757
return(pd_nested)
5858
}
@@ -70,7 +70,7 @@ flatten_pd <- function(pd_nested, token, child_token = token, left = TRUE) {
7070
if (pos < 1L) {
7171
return(pd_nested)
7272
}
73-
if (!any(pd_nested$child[[pos]]$token[-1] %in% child_token)) {
73+
if (!any(pd_nested$child[[pos]]$token[-1L] %in% child_token)) {
7474
return(pd_nested)
7575
}
7676
bind_with_child(pd_nested, pos)
@@ -102,8 +102,8 @@ wrap_expr_in_expr <- function(pd) {
102102
pos_ids = create_pos_ids(pd, 1, after = FALSE),
103103
child = pd,
104104
terminal = FALSE,
105-
stylerignore = pd$stylerignore[1],
106-
indents = pd$indent[1]
105+
stylerignore = pd$stylerignore[1L],
106+
indents = pd$indent[1L]
107107
)
108108
}
109109

@@ -214,7 +214,7 @@ find_block_id <- function(pd) {
214214
#' @keywords internal
215215
relocate_eq_assign_one <- function(pd) {
216216
idx_eq_assign <- which(pd$token == "EQ_ASSIGN")
217-
eq_ind <- seq2(idx_eq_assign[1] - 1L, last(idx_eq_assign) + 1L)
217+
eq_ind <- seq2(idx_eq_assign[1L] - 1L, last(idx_eq_assign) + 1L)
218218
# initialize because wrap_expr_in_expr -> create_tokens -> requires it
219219
pd$indent <- 0
220220
eq_expr <- pd[eq_ind, ] %>%
@@ -240,9 +240,9 @@ relocate_eq_assign_one <- function(pd) {
240240
#' @keywords internal
241241
add_line_col_to_wrapped_expr <- function(pd) {
242242
if (nrow(pd) > 1) abort("pd must be a wrapped expression that has one row.")
243-
pd$line1 <- pd$child[[1]]$line1[1]
244-
pd$line2 <- last(pd$child[[1]]$line2)
245-
pd$col1 <- pd$child[[1]]$col1[1]
246-
pd$col2 <- last(pd$child[[1]]$col2)
243+
pd$line1 <- pd$child[[1L]]$line1[1L]
244+
pd$line2 <- last(pd$child[[1L]]$line2)
245+
pd$col1 <- pd$child[[1L]]$col1[1L]
246+
pd$col2 <- last(pd$child[[1L]]$col2)
247247
pd
248248
}

R/roxygen-examples-add-remove.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @importFrom rlang seq2
66
remove_dont_mask <- function(roxygen) {
77
mask <- c(
8-
1L, 2L, if (roxygen[3] == "\n") 3L, last(which(roxygen == "}"))
8+
1L, 2L, if (roxygen[3L] == "\n") 3L, last(which(roxygen == "}"))
99
) %>% sort()
1010
list(
1111
code = roxygen[-mask], mask = paste(roxygen[seq2(1, 2)], collapse = "")
@@ -45,8 +45,8 @@ remove_roxygen_header <- function(text) {
4545
add_roxygen_mask <- function(text, initial_text, example_type) {
4646
space <- ifelse(text == "", "", " ")
4747
out <- c(
48-
paste0("#' @", example_type, space[1], text[1]),
49-
map2_chr(space[-1], text[-1], ~ paste0("#'", .x, .y))
48+
paste0("#' @", example_type, space[1L], text[1L]),
49+
map2_chr(space[-1L], text[-1L], ~ paste0("#'", .x, .y))
5050
)
5151

5252
ordinary_comment <- grep("^#[^']", initial_text, value = TRUE)
@@ -55,7 +55,7 @@ add_roxygen_mask <- function(text, initial_text, example_type) {
5555
}
5656
without_mask <- remove_roxygen_mask(out)
5757
for (idx in seq_along(ordinary_comment)) {
58-
to_replace <- which(ordinary_comment[idx] == without_mask)[1]
58+
to_replace <- which(ordinary_comment[idx] == without_mask)[1L]
5959
out[to_replace] <- ordinary_comment[idx]
6060
without_mask[to_replace] <- NA
6161
}

R/roxygen-examples-find.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ find_dont_closings <- function(bare, dont_openings) {
6666
match_closing <- intersect(
6767
seq2(dont_openings + 1L, length(bare)),
6868
which(diff == level_dont - 1L)
69-
)[1]
69+
)[1L]
7070
match_closing + 1L
7171
}

0 commit comments

Comments
 (0)