Skip to content

Commit abf92a4

Browse files
authored
fix delint conflicts (#687)
* de-lint test-absolute_path_linter.R * de-lint test-exclusions.R * de-lint test-extraction_operator_linter.R * de-lint test-get_source_expressions.R * de-lint test-implicit_integer_linter.R * de-lint test-nonportable_path_linter.R * de-lint test-object_name_linter.R * de-lint test-pipe_continuation_linter.R * de-lint test-semicolon_terminator_linter.R * de-lint test-settings.R * de-lint test-T_and_F_symbol_linter.R * de-lint test-todo_comment_linter.R * de-lint test-undesirable_function_linter.R * de-lint test-undesirable_operator_linter.R * de-lint test-unneeded_concatenation_linter.R * bump cyclocomp limit up to 30 for lint() caused by #673 * fix test failure on non-english locale * fix test failure on non-english locale * remove most context() calls in touched files test-exclusions.R was not touched since it contains 3 calls (and will be split by #660)
1 parent 375302a commit abf92a4

17 files changed

+168
-199
lines changed

.lintr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
linters: with_defaults( # The following TODOs are part of an effort to have {lintr} lint-free (#584)
22
line_length_linter = line_length_linter(120),
3-
cyclocomp_linter = cyclocomp_linter(29), # TODO reduce to 15
3+
cyclocomp_linter = cyclocomp_linter(30), # TODO reduce to 15
44
paren_brace_linter = NULL # TODO enable (#603)
55
)
66
exclusions: list(
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
context("T_and_F_symbol_linter")
2-
31
test_that("returns the correct linting", {
42
linter <- T_and_F_symbol_linter
5-
msgT <- "Use TRUE instead of the symbol T."
6-
msgF <- "Use FALSE instead of the symbol F."
3+
msg_true <- "Use TRUE instead of the symbol T."
4+
msg_false <- "Use FALSE instead of the symbol F."
75
expect_lint("FALSE", NULL, linter)
86
expect_lint("TRUE", NULL, linter)
97
expect_lint("x <- \"TRUE master vs FALSE slave\"", NULL, linter)
10-
expect_lint("T", list(message=msgT, line_number=1L, column_number=2L), linter)
11-
expect_lint("F", list(message=msgF, line_number=1L, column_number=2L), linter)
8+
expect_lint("T", list(message = msg_true, line_number = 1L, column_number = 2L), linter)
9+
expect_lint("F", list(message = msg_false, line_number = 1L, column_number = 2L), linter)
1210
expect_lint("for (i in 1:10) {x <- c(T, TRUE, F, FALSE)}",
1311
list(
14-
list(message=msgT, line_number=1L, column_number=26L),
15-
list(message=msgF, line_number=1L, column_number=35L)
12+
list(message = msg_true, line_number = 1L, column_number = 26L),
13+
list(message = msg_false, line_number = 1L, column_number = 35L)
1614
),
1715
linter)
1816
})

tests/testthat/test-absolute_path_linter.R

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
context("absolute_path_linter")
2-
31
test_that("unquote", {
42
f <- lintr:::unquote
53
expect_equal(f(character()), character())
64
expect_equal(f("foo"), "foo")
75
expect_equal(
8-
f(c("'f", "\"f'", "\"f\""), q="\""),
9-
c("'f", "\"f'", "f" ))
6+
f(c("'f", "\"f'", "\"f\""), q = "\""),
7+
c("'f", "\"f'", "f"))
108
expect_equal(
11-
f(c("\"f\"", "'f'", "`f`", "`'f'`"), q="'"),
9+
f(c("\"f\"", "'f'", "`f`", "`'f'`"), q = "'"),
1210
c("\"f\"", "f", "`f`", "`'f'`"))
13-
expect_equal(f("`a\\`b`", q=c("`")), "a`b")
11+
expect_equal(f("`a\\`b`", q = c("`")), "a`b")
1412
x <- c("\"x\"", "\"\\n\"", "\"\\\\\"", "\"\\\\y\"", "\"\\ny\"", "\"\\\\ny\"", "\"\\\\\\ny\"",
1513
"\"\\\\\\\\ny\"", "\"'\"", "\"\\\"\"", "\"`\"")
1614
y <- c("x", "\n", "\\", "\\y", "\ny", "\\ny", "\\\ny", "\\\\ny", "'", "\"", "`")
17-
expect_equal(f(x, q="\""), y)
15+
expect_equal(f(x, q = "\""), y)
1816
})
1917

2018
test_that("unescape", {
@@ -33,24 +31,24 @@ test_that("is_root_path", {
3331
y <- logical()
3432
expect_equal(f(x), y)
3533

36-
x <- c( "", "foo", "http://rseek.org/", "./", " /", "/foo", "'/'")
37-
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
34+
x <- c("", "foo", "http://rseek.org/", "./", " /", "/foo", "'/'")
35+
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
3836
expect_equal(f(x), y)
3937

40-
x <- c( "/", "//")
38+
x <- c("/", "//")
4139
y <- c(TRUE, FALSE)
4240
expect_equal(f(x), y)
4341

44-
x <- c( "~", "~/", "~//", "~bob2", "~foo_bar/")
45-
y <- c(TRUE, TRUE, TRUE, TRUE, TRUE)
42+
x <- c("~", "~/", "~//", "~bob2", "~foo_bar/")
43+
y <- c(TRUE, TRUE, TRUE, TRUE, TRUE)
4644
expect_equal(f(x), y)
4745

4846
x <- c("c:", "C:\\", "D:/", "C:\\\\", "D://")
49-
y <- c(TRUE, TRUE, TRUE, FALSE, FALSE)
47+
y <- c(TRUE, TRUE, TRUE, FALSE, FALSE)
5048
expect_equal(f(x), y)
5149

5250
x <- c("\\\\", "\\\\localhost", "\\\\localhost\\")
53-
y <- c( TRUE, TRUE, TRUE)
51+
y <- c(TRUE, TRUE, TRUE)
5452
expect_equal(f(x), y)
5553
})
5654

@@ -62,20 +60,20 @@ test_that("is_absolute_path", {
6260
y <- logical()
6361
expect_equal(f(x), y)
6462

65-
x <- c( "/", "//", "/foo", "/foo/")
66-
y <- c(TRUE, FALSE, TRUE, TRUE)
63+
x <- c("/", "//", "/foo", "/foo/")
64+
y <- c(TRUE, FALSE, TRUE, TRUE)
6765
expect_equal(f(x), y)
6866

69-
x <- c( "~", "~/foo", "~/foo/", "~'") #nolint
70-
y <- c(TRUE, TRUE, TRUE, FALSE)
67+
x <- c("~", "~/foo", "~/foo/", "~'")
68+
y <- c(TRUE, TRUE, TRUE, FALSE)
7169
expect_equal(f(x), y)
7270

73-
x <- c("c:", "C:\\foo\\", "C:/foo/") #nolint
74-
y <- c(TRUE, TRUE, TRUE)
71+
x <- c("c:", "C:\\foo\\", "C:/foo/")
72+
y <- c(TRUE, TRUE, TRUE)
7573
expect_equal(f(x), y)
7674

77-
x <- c("\\\\", "\\\\localhost", "\\\\localhost\\c$", "\\\\localhost\\c$\\foo") #nolint
78-
y <- c( TRUE, TRUE, TRUE, TRUE)
75+
x <- c("\\\\", "\\\\localhost", "\\\\localhost\\c$", "\\\\localhost\\c$\\foo")
76+
y <- c(TRUE, TRUE, TRUE, TRUE)
7977
expect_equal(f(x), y)
8078
})
8179

@@ -87,16 +85,16 @@ test_that("is_relative_path", {
8785
y <- logical()
8886
expect_equal(f(x), y)
8987

90-
x <- c( "/", "c:\\", "~/", "foo", "http://rseek.org/", "'./'")
91-
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
88+
x <- c("/", "c:\\", "~/", "foo", "http://rseek.org/", "'./'")
89+
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
9290
expect_equal(f(x), y)
9391

94-
x <- c("/foo", "foo/", "foo/bar", "foo//bar", "./foo", "../foo") #nolint
95-
y <- c( FALSE, TRUE, TRUE, TRUE, TRUE, TRUE)
92+
x <- c("/foo", "foo/", "foo/bar", "foo//bar", "./foo", "../foo")
93+
y <- c(FALSE, TRUE, TRUE, TRUE, TRUE, TRUE)
9694
expect_equal(f(x), y)
9795

98-
x <- c("\\\\", "\\foo", "foo\\", "foo\\bar", ".\\foo", "..\\foo", ".", "..", "../") #nolint
99-
y <- c( FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)
96+
x <- c("\\\\", "\\foo", "foo\\", "foo\\bar", ".\\foo", "..\\foo", ".", "..", "../")
97+
y <- c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)
10098
expect_equal(f(x), y)
10199
})
102100

@@ -108,12 +106,12 @@ test_that("is_path", {
108106
y <- logical()
109107
expect_equal(f(x), y)
110108

111-
x <- c( "", "foo", "http://rseek.org/", "foo\nbar", "'foo/bar'", "'/'")
112-
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
109+
x <- c("", "foo", "http://rseek.org/", "foo\nbar", "'foo/bar'", "'/'")
110+
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
113111
expect_equal(f(x), y)
114112

115-
x <- c("c:", "..", "foo/bar", "foo\\bar", "~", "\\\\localhost") #nolint
116-
y <- c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)
113+
x <- c("c:", "..", "foo/bar", "foo\\bar", "~", "\\\\localhost")
114+
y <- c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)
117115
expect_equal(f(x), y)
118116
})
119117

@@ -125,21 +123,21 @@ test_that("is_valid_path", {
125123
y <- logical()
126124
expect_equal(f(x), y)
127125

128-
x <- c("C:/asdf", "C:/asd*f", "a\\s:df", "a\\\nsdf") #nolint
129-
y <- c( TRUE, FALSE, FALSE, FALSE)
126+
x <- c("C:/asdf", "C:/asd*f", "a\\s:df", "a\\\nsdf")
127+
y <- c(TRUE, FALSE, FALSE, FALSE)
130128
expect_equal(f(x), y)
131129

132-
x <- c("C:/asdf", "C:/asd*f", "a\\s:df", "a\\\nsdf") #nolint
133-
y <- c( TRUE, FALSE, FALSE, FALSE)
134-
expect_equal(f(x, lax=TRUE), y)
130+
x <- c("C:/asdf", "C:/asd*f", "a\\s:df", "a\\\nsdf")
131+
y <- c(TRUE, FALSE, FALSE, FALSE)
132+
expect_equal(f(x, lax = TRUE), y)
135133

136134
x <- c("/asdf", "/asd*f", "/as:df", "/a\nsdf")
137-
y <- c( TRUE, TRUE, TRUE, TRUE)
135+
y <- c(TRUE, TRUE, TRUE, TRUE)
138136
expect_equal(f(x), y)
139137

140138
x <- c("/asdf", "/asd*f", "/as:df", "/a\nsdf")
141-
y <- c( TRUE, FALSE, FALSE, FALSE)
142-
expect_equal(f(x, lax=TRUE), y)
139+
y <- c(TRUE, FALSE, FALSE, FALSE)
140+
expect_equal(f(x, lax = TRUE), y)
143141
})
144142

145143

@@ -150,8 +148,8 @@ test_that("is_long_path", {
150148
y <- logical()
151149
expect_equal(f(x), y)
152150

153-
x <- c("foo/", "/foo", "n/a", "Z:\\foo", "foo/bar", "~/foo", "../foo") #nolint
154-
y <- c( FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE)
151+
x <- c("foo/", "/foo", "n/a", "Z:\\foo", "foo/bar", "~/foo", "../foo")
152+
y <- c(FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE)
155153
expect_equal(f(x), y)
156154
})
157155

@@ -160,7 +158,7 @@ test_that("returns the correct linting", {
160158
msg <- rex::escape("Do not use absolute paths.")
161159

162160
# strict mode
163-
linter <- absolute_path_linter(lax=FALSE)
161+
linter <- absolute_path_linter(lax = FALSE)
164162
non_absolute_path_strings <- c(
165163
"..",
166164
"./blah",
@@ -191,7 +189,7 @@ test_that("returns the correct linting", {
191189
}
192190

193191
# lax mode: no check for strings that are likely not paths (too short or with special characters)
194-
linter <- absolute_path_linter(lax=TRUE)
192+
linter <- absolute_path_linter(lax = TRUE)
195193
unlikely_path_strings <- c(
196194
"/",
197195
encodeString("/a\nsdf/bar"),

tests/testthat/test-error.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
context("error")
21
test_that("returns the correct linting", {
32
expect_lint("\"\\R\"",
43
rex("is an unrecognized escape in character string starting")
@@ -60,11 +59,6 @@ test_that("returns the correct linting", {
6059
expected_message <- tryCatch(parse(text = "\\"), error = get_base_message)
6160
expect_lint("\\", rex(expected_message))
6261

63-
# also try when LANGUAGE initially unset
64-
Sys.unsetenv("LANGUAGE")
65-
expected_message <- tryCatch(parse(text = "\\"), error = get_base_message)
66-
expect_lint("\\", rex(expected_message))
67-
6862
expect_lint("``",
6963
rex("attempt to use zero-length variable name")
7064
)

tests/testthat/test-exclusions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ context("normalize_exclusions")
105105

106106
a <- tempfile()
107107
b <- tempfile()
108-
c <- tempfile(tmpdir=".")
108+
c <- tempfile(tmpdir = ".")
109109
file.create(a, b, c)
110110
a <- normalizePath(a)
111111
b <- normalizePath(b)
@@ -178,7 +178,7 @@ test_that("it normalizes file paths, removing non-existing files", {
178178
expect_equal(normalize_exclusions(c(t1, t2, t3)), res)
179179

180180
res <- list(); res[[a]] <- 1:10; res[["notafile"]] <- 5:15; res[[c]] <- 5:15
181-
expect_equal(normalize_exclusions(c(t1, t2, t3), normalize_path=FALSE), res)
181+
expect_equal(normalize_exclusions(c(t1, t2, t3), normalize_path = FALSE), res)
182182
})
183183

184184
unlink(c(a, b, c))
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
context("extraction_operator_linter")
2-
31
test_that("linter returns the correct linting", {
42
linter <- extraction_operator_linter
5-
msgB <- rex::escape("Use `[[` instead of `[` to extract an element.")
6-
msgD <- rex::escape("Use `[[` instead of `$` to extract an element.")
3+
msg_b <- rex::escape("Use `[[` instead of `[` to extract an element.")
4+
msg_d <- rex::escape("Use `[[` instead of `$` to extract an element.")
75

86
expect_lint("x[[1]]", NULL, linter)
97
expect_lint("x[-1]", NULL, linter)
108
expect_lint("x[1, 'a']", NULL, linter)
119
expect_lint("self$a", NULL, linter)
1210
expect_lint(".self $\na", NULL, linter)
13-
expect_lint("x$a", list(message=msgD, line_number=1L, column_number=2L), linter)
14-
expect_lint("x $\na", list(message=msgD, line_number=1L, column_number=3L), linter)
15-
expect_lint("x[NULL]", list(message=msgB, line_number=1L, column_number=2L), linter)
16-
expect_lint("x[++ + 3]", list(message=msgB, line_number=1L, column_number=2L), linter)
11+
expect_lint("x$a", list(message = msg_d, line_number = 1L, column_number = 2L), linter)
12+
expect_lint("x $\na", list(message = msg_d, line_number = 1L, column_number = 3L), linter)
13+
expect_lint("x[NULL]", list(message = msg_b, line_number = 1L, column_number = 2L), linter)
14+
expect_lint("x[++ + 3]", list(message = msg_b, line_number = 1L, column_number = 2L), linter)
1715
expect_lint("c(x['a'], x [ 1 ])",
1816
list(
19-
list(message=msgB, line_number=1L, column_number=4L),
20-
list(message=msgB, line_number=1L, column_number=13L)
17+
list(message = msg_b, line_number = 1L, column_number = 4L),
18+
list(message = msg_b, line_number = 1L, column_number = 13L)
2119
),
2220
linter)
2321
})

tests/testthat/test-get_source_expressions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ test_that("tab positions have been corrected", {
6161

6262
test_that("Terminal newlines are detected correctly", {
6363
writeLines("lm(y ~ x)", tmp <- tempfile())
64-
on.exit(unlink(tmp), add=TRUE)
64+
on.exit(unlink(tmp), add = TRUE)
6565
writeBin(
6666
# strip the last (two) element(s) (\r\n or \n)
6767
head(readBin(tmp, raw(), file.size(tmp)), if (.Platform$OS.type == "windows") -2L else -1L),
6868
tmp2 <- tempfile()
6969
)
70-
on.exit(unlink(tmp2), add=TRUE)
70+
on.exit(unlink(tmp2), add = TRUE)
7171

7272
expect_true(get_source_expressions(tmp)$expressions[[2L]]$terminal_newline)
7373
expect_false(get_source_expressions(tmp2)$expressions[[2L]]$terminal_newline)
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
context("implicit_integer_linter")
2-
31
test_that("single numerical constants are properly identified ", {
42
# Test single numerical constants
53
is_implicit <- lintr:::is_implicit_integer
64

7-
x <- c("Inf", "NaN", "TRUE", "FALSE", "NA", "NA_character")
8-
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
5+
x <- c("Inf", "NaN", "TRUE", "FALSE", "NA", "NA_character")
6+
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
97
expect_equal(is_implicit(x), y)
108

11-
x <- c("2.000", "2.", "2L", "2.0", "2.1", "2")
12-
y <- c( FALSE, FALSE, FALSE, FALSE, FALSE, TRUE)
9+
x <- c("2.000", "2.", "2L", "2.0", "2.1", "2")
10+
y <- c(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE)
1311
expect_equal(is_implicit(x), y)
1412

1513
# 1000 1000L 1000L 1200* 0.0012 0.001 0.0... 1.2
1614
x <- c("1e3", "1e3L", "1.0e3L", "1.2e3", "1.2e-3", "1e-3", "1e-33", "1.2e0")
17-
y <- c( TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
15+
y <- c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
1816
expect_equal(is_implicit(x), y)
1917

2018
# 1* 123L 123* 123.1
2119
x <- c("0x1p+0", "0x1.ecp+6L", "0x1.ecp+6", "0x1.ec66666666666p+6")
22-
y <- c( FALSE, FALSE, FALSE, FALSE)
20+
y <- c(FALSE, FALSE, FALSE, FALSE)
2321
expect_equal(is_implicit(x), y)
2422

25-
x <- c( "8i", "8.0i")
26-
y <- c( FALSE, FALSE)
23+
x <- c("8i", "8.0i")
24+
y <- c(FALSE, FALSE)
2725
expect_equal(is_implicit(x), y)
2826

2927
max <- .Machine[["integer.max"]] # largest number that R can represent as an integer
30-
x <- as.character(c(-max - 1.0, -max, max, max + 1.0))
31-
y <- c( FALSE, TRUE, TRUE, FALSE)
28+
x <- as.character(c(-max - 1.0, -max, max, max + 1.0))
29+
y <- c(FALSE, TRUE, TRUE, FALSE)
3230
expect_equal(is_implicit(x), y)
3331

3432
# Note: cases indicated by "*" should be TRUE but they are complicated to handle, and it is not
@@ -41,13 +39,13 @@ test_that("linter returns the correct linting", {
4139

4240
expect_lint("x <<- 1L", NULL, linter)
4341
expect_lint("1.0/-Inf -> y", NULL, linter)
44-
expect_lint("y <- 1+i", list(message=msg, line_number=1L, column_number=7L), linter)
45-
expect_lint("z <- 1e5", list(message=msg, line_number=1L, column_number=9L), linter)
46-
expect_lint("cat(1:n)", list(message=msg, line_number=1L, column_number=6L), linter)
42+
expect_lint("y <- 1+i", list(message = msg, line_number = 1L, column_number = 7L), linter)
43+
expect_lint("z <- 1e5", list(message = msg, line_number = 1L, column_number = 9L), linter)
44+
expect_lint("cat(1:n)", list(message = msg, line_number = 1L, column_number = 6L), linter)
4745
expect_lint("552^9",
4846
list(
49-
list(message=msg, line_number=1L, column_number=4L),
50-
list(message=msg, line_number=1L, column_number=6L)
47+
list(message = msg, line_number = 1L, column_number = 4L),
48+
list(message = msg, line_number = 1L, column_number = 6L)
5149
),
5250
linter)
5351
})

tests/testthat/test-nonportable_path_linter.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
context("nonportable_path_linter")
2-
3-
41
test_that("Non-portable path linter", {
5-
linter <- nonportable_path_linter(lax=FALSE)
2+
linter <- nonportable_path_linter(lax = FALSE)
63
msg <- rex::escape("Use file.path() to construct portable file paths.")
74

85
# various strings
@@ -44,7 +41,7 @@ test_that("Non-portable path linter", {
4441
}
4542

4643
# lax mode: no check for strings that are likely not paths (too short or with special characters)
47-
linter <- nonportable_path_linter(lax=TRUE)
44+
linter <- nonportable_path_linter(lax = TRUE)
4845

4946
unlikely_path_strings <- c(
5047
"/foo", encodeString("/a\nsdf/bar"), "/as:df/bar"

0 commit comments

Comments
 (0)