Skip to content

Commit e05d994

Browse files
Consistently use lint_msg instead of msg (#1654)
Currently, in some tests we use `msg`, while in others `lint_msg`.
1 parent 71beed9 commit e05d994

29 files changed

+223
-223
lines changed

tests/testthat/test-absolute_path_linter.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test_that("is_long_path", {
129129

130130

131131
test_that("returns the correct linting", {
132-
msg <- rex::escape("Do not use absolute paths.")
132+
lint_msg <- rex::escape("Do not use absolute paths.")
133133

134134
# strict mode
135135
linter <- absolute_path_linter(lax = FALSE)
@@ -158,8 +158,8 @@ test_that("returns the correct linting", {
158158
"/as:df"
159159
)
160160
for (path in absolute_path_strings) {
161-
expect_lint(single_quote(path), msg, linter)
162-
expect_lint(double_quote(path), msg, linter)
161+
expect_lint(single_quote(path), lint_msg, linter)
162+
expect_lint(double_quote(path), lint_msg, linter)
163163
}
164164

165165
# lax mode: no check for strings that are likely not paths (too short or with special characters)

tests/testthat/test-assignment_linter.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
test_that("returns the correct linting", {
22
linter <- assignment_linter()
3-
msg <- rex::rex("Use <-, not =, for assignment.")
3+
lint_msg <- rex::rex("Use <-, not =, for assignment.")
44

55
expect_lint("blah", NULL, linter)
66
expect_lint("blah <- 1", NULL, linter)
77
expect_lint("blah<-1", NULL, linter)
88
expect_lint("fun(blah=1)", NULL, linter)
99

10-
expect_lint("blah=1", msg, linter)
11-
expect_lint("blah = 1", msg, linter)
12-
expect_lint("blah = fun(1)", msg, linter)
13-
expect_lint("fun((blah = fun(1)))", msg, linter)
10+
expect_lint("blah=1", lint_msg, linter)
11+
expect_lint("blah = 1", lint_msg, linter)
12+
expect_lint("blah = fun(1)", lint_msg, linter)
13+
expect_lint("fun((blah = fun(1)))", lint_msg, linter)
1414

1515
expect_lint(
1616
"blah = fun(1) {",
1717
list(
18-
msg,
18+
lint_msg,
1919
c(type = "error", "unexpected")
2020
),
2121
linter

tests/testthat/test-brace_linter.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ test_that("brace_linter lints braces correctly", {
224224

225225
test_that("brace_linter lints spaces before open braces", {
226226
linter <- brace_linter()
227-
msg <- rex::rex("There should be a space before an opening curly brace.")
227+
lint_msg <- rex::rex("There should be a space before an opening curly brace.")
228228

229229
expect_lint(
230230
"blah <- function(){\n}",
231231
list(
232-
message = msg,
232+
message = lint_msg,
233233
column_number = 19L
234234
),
235235
linter
@@ -238,7 +238,7 @@ test_that("brace_linter lints spaces before open braces", {
238238
expect_lint(
239239
"\nblah <- function(){\n\n\n}",
240240
list(
241-
message = msg,
241+
message = lint_msg,
242242
column_number = 19L
243243
),
244244
linter
@@ -248,16 +248,16 @@ test_that("brace_linter lints spaces before open braces", {
248248
expect_lint(
249249
"a <- if (a){\n} else{\n}",
250250
list(
251-
list(message = msg, line_number = 1L, column_number = 12L),
252-
list(message = msg, line_number = 2L, column_number = 7L)
251+
list(message = lint_msg, line_number = 1L, column_number = 12L),
252+
list(message = lint_msg, line_number = 2L, column_number = 7L)
253253
),
254254
linter
255255
)
256256

257257
# should lint repeat{
258258
expect_lint(
259259
"repeat{\nblah\n}",
260-
list(message = msg, line_number = 1L, column_number = 7L),
260+
list(message = lint_msg, line_number = 1L, column_number = 7L),
261261
linter
262262
)
263263

@@ -277,7 +277,7 @@ test_that("brace_linter lints spaces before open braces", {
277277
list(
278278
rex::rex("Opening curly braces should never go on their own line and should always be followed by a new line."),
279279
rex::rex("Closing curly-braces should always be on their own line, unless they are followed by an else.")
280-
), # , but not msg
280+
), # , but not lint_msg
281281
linter
282282
)
283283
})

tests/testthat/test-class_equals_linter.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ test_that("class_equals_linter skips allowed usages", {
1111

1212
test_that("class_equals_linter blocks simple disallowed usages", {
1313
linter <- class_equals_linter()
14-
msg <- rex::rex("Instead of comparing class(x) with ==")
14+
lint_msg <- rex::rex("Instead of comparing class(x) with ==")
1515

16-
expect_lint("if (class(x) == 'character') stop('no')", msg, linter)
17-
expect_lint("is_regression <- class(x) == 'lm'", msg, linter)
18-
expect_lint("is_regression <- 'lm' == class(x)", msg, linter)
16+
expect_lint("if (class(x) == 'character') stop('no')", lint_msg, linter)
17+
expect_lint("is_regression <- class(x) == 'lm'", lint_msg, linter)
18+
expect_lint("is_regression <- 'lm' == class(x)", lint_msg, linter)
1919
})
2020

2121
test_that("class_equals_linter blocks usage of %in% for checking class", {
2222
linter <- class_equals_linter()
23-
msg <- rex::rex("Instead of comparing class(x) with %in%")
23+
lint_msg <- rex::rex("Instead of comparing class(x) with %in%")
2424

25-
expect_lint("if ('character' %in% class(x)) stop('no')", msg, linter)
26-
expect_lint("if (class(x) %in% 'character') stop('no')", msg, linter)
25+
expect_lint("if ('character' %in% class(x)) stop('no')", lint_msg, linter)
26+
expect_lint("if (class(x) %in% 'character') stop('no')", lint_msg, linter)
2727
})
2828

2929
test_that("class_equals_linter blocks class(x) != 'klass'", {

tests/testthat/test-commented_code_linter.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
test_that("returns the correct linting", {
2-
msg <- rex::rex("Commented code should be removed.")
2+
lint_msg <- rex::rex("Commented code should be removed.")
33
linter <- commented_code_linter()
44
expect_s3_class(linter, "linter")
55

66
expect_lint("blah", NULL, linter)
77

8-
expect_lint("# blah <- 1", msg, linter)
8+
expect_lint("# blah <- 1", lint_msg, linter)
99

1010
expect_lint(
1111
"bleurgh <- fun_call(1) # other_call()",
12-
list(message = msg, column_number = 26L),
12+
list(message = lint_msg, column_number = 26L),
1313
linter
1414
)
1515

1616
expect_lint(
1717
" #blah <- 1",
18-
list(message = msg, column_number = 3L),
18+
list(message = lint_msg, column_number = 3L),
1919
linter
2020
)
2121

@@ -26,7 +26,7 @@ test_that("returns the correct linting", {
2626
line_without_comment <- 42L
2727
#blah <- 1
2828
"),
29-
list(message = msg, line_number = 3L, column_number = 3L),
29+
list(message = lint_msg, line_number = 3L, column_number = 3L),
3030
linter
3131
)
3232

@@ -59,7 +59,7 @@ test_that("returns the correct linting", {
5959
mu = 175
6060
)
6161
"),
62-
list(message = msg, line_number = 3L),
62+
list(message = lint_msg, line_number = 3L),
6363
linter
6464
)
6565

@@ -72,15 +72,15 @@ test_that("returns the correct linting", {
7272
, mu = 175
7373
)
7474
"),
75-
list(message = msg, line_number = 3L),
75+
list(message = lint_msg, line_number = 3L),
7676
linter
7777
)
7878

7979
test_ops <- append(lintr:::ops[lintr:::ops != "%[^%]*%"], values = c("%>%", "%anything%"))
8080
for (op in test_ops) {
8181
expect_lint(paste("i", op, "1", collapse = ""), NULL, linter)
8282
expect_lint(paste("# something like i", op, "1", collapse = ""), NULL, linter)
83-
expect_lint(paste("# i", op, "1", collapse = ""), msg, linter)
83+
expect_lint(paste("# i", op, "1", collapse = ""), lint_msg, linter)
8484
}
8585

8686
expect_lint("TRUE", NULL, linter)
@@ -93,8 +93,8 @@ test_that("returns the correct linting", {
9393

9494
expect_lint("1+1 # for example cat(\"123\")", NULL, linter)
9595

96-
expect_lint("1+1 # cat('123')", msg, linter)
97-
expect_lint("#expect_ftype(1e-12 , t)", msg, linter)
96+
expect_lint("1+1 # cat('123')", lint_msg, linter)
97+
expect_lint("#expect_ftype(1e-12 , t)", lint_msg, linter)
9898

9999
# regression test for #451
100100
expect_lint("c('#a#' = 1)", NULL, linter)

tests/testthat/test-cyclocomp_linter.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
test_that("returns the correct linting", {
22
cc_linter_1 <- cyclocomp_linter(1L)
33
cc_linter_2 <- cyclocomp_linter(2L)
4-
msg <- rex::rex("Functions should have cyclomatic complexity")
4+
lint_msg <- rex::rex("Functions should have cyclomatic complexity")
55

66
expect_lint("if (TRUE) 1 else 2", NULL, cc_linter_2)
7-
expect_lint("if (TRUE) 1 else 2", msg, cc_linter_1)
7+
expect_lint("if (TRUE) 1 else 2", lint_msg, cc_linter_1)
88

99
expect_lint(
1010
"function(x) {not parsing}",
@@ -14,7 +14,7 @@ test_that("returns the correct linting", {
1414
complexity <- readLines(
1515
system.file("example/complexity.R", package = "lintr")
1616
)
17-
expect_lint(complexity, msg, cc_linter_2)
17+
expect_lint(complexity, lint_msg, cc_linter_2)
1818
expect_lint(
1919
complexity,
2020
"should have cyclomatic complexity of less than 2, this has 10",

tests/testthat/test-duplicate_argument_linter.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ test_that("duplicate_argument_linter doesn't block allowed usages", {
1111

1212
test_that("duplicate_argument_linter blocks disallowed usages", {
1313
linter <- duplicate_argument_linter()
14-
msg <- rex::rex("Duplicate arguments in function call.")
14+
lint_msg <- rex::rex("Duplicate arguments in function call.")
1515

16-
expect_lint("fun(arg = 1, arg = 2)", msg, linter)
17-
expect_lint("fun(arg = 1, 'arg' = 2)", msg, linter)
18-
expect_lint("fun(arg = 1, `arg` = 2)", msg, linter)
19-
expect_lint("'fun'(arg = 1, arg = 2)", msg, linter)
20-
expect_lint("(function(x, y) x + y)(x = 1, x = 2)", msg, linter)
21-
expect_lint("dt[i = 1, i = 2]", msg, linter)
16+
expect_lint("fun(arg = 1, arg = 2)", lint_msg, linter)
17+
expect_lint("fun(arg = 1, 'arg' = 2)", lint_msg, linter)
18+
expect_lint("fun(arg = 1, `arg` = 2)", lint_msg, linter)
19+
expect_lint("'fun'(arg = 1, arg = 2)", lint_msg, linter)
20+
expect_lint("(function(x, y) x + y)(x = 1, x = 2)", lint_msg, linter)
21+
expect_lint("dt[i = 1, i = 2]", lint_msg, linter)
2222

2323
expect_lint(
2424
"list(
2525
var = 1,
2626
var = 2
2727
)",
28-
msg,
28+
lint_msg,
2929
linter
3030
)
3131
})

tests/testthat/test-equals_na_linter.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that("equals_na_linter skips allowed usages", {
1313

1414
# equals_na_linter should ignore strings and comments
1515
expect_lint("is.na(x) # dont flag x == NA if inside a comment", NULL, linter)
16-
expect_lint("msg <- 'dont flag x == NA if inside a string'", NULL, linter)
16+
expect_lint("lint_msg <- 'dont flag x == NA if inside a string'", NULL, linter)
1717

1818
# nested NAs are okay
1919
expect_lint("x==f(1, ignore = NA)", NULL, linter)
@@ -45,14 +45,14 @@ patrick::with_parameters_test_that(
4545

4646
test_that("equals_na_linter blocks disallowed usages in edge cases", {
4747
linter <- equals_na_linter()
48-
msg <- rex::rex("Use is.na for comparisons to NA (not == or !=)")
48+
lint_msg <- rex::rex("Use is.na for comparisons to NA (not == or !=)")
4949

5050
# missing spaces around operators
51-
expect_lint("x==NA", list(message = msg, line_number = 1L, column_number = 1L), linter)
52-
expect_lint("x!=NA", list(message = msg, line_number = 1L, column_number = 1L), linter)
51+
expect_lint("x==NA", list(message = lint_msg, line_number = 1L, column_number = 1L), linter)
52+
expect_lint("x!=NA", list(message = lint_msg, line_number = 1L, column_number = 1L), linter)
5353

5454
# order doesn't matter
55-
expect_lint("NA == x", list(message = msg, line_number = 1L, column_number = 1L), linter)
55+
expect_lint("NA == x", list(message = lint_msg, line_number = 1L, column_number = 1L), linter)
5656

5757
# correct line number for multiline code
5858
expect_lint("x ==\nNA", list(line_number = 1L, column_number = 1L, ranges = list(c(1L, 4L))), linter)

tests/testthat/test-expect_identical_linter.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ test_that("expect_identical_linter skips allowed usages", {
1717

1818
test_that("expect_identical_linter blocks simple disallowed usages", {
1919
linter <- expect_identical_linter()
20-
msg <- rex::rex("Use expect_identical(x, y) by default; resort to expect_equal() only when needed")
20+
lint_msg <- rex::rex("Use expect_identical(x, y) by default; resort to expect_equal() only when needed")
2121

22-
expect_lint("expect_equal(x, y)", msg, linter)
22+
expect_lint("expect_equal(x, y)", lint_msg, linter)
2323

2424
# different usage to redirect to expect_identical
25-
expect_lint("expect_true(identical(x, y))", msg, linter)
25+
expect_lint("expect_true(identical(x, y))", lint_msg, linter)
2626
})
2727

2828
test_that("expect_identical_linter skips cases likely testing numeric equality", {
2929
linter <- expect_identical_linter()
30-
msg <- rex::rex("Use expect_identical(x, y) by default; resort to expect_equal() only when needed")
30+
lint_msg <- rex::rex("Use expect_identical(x, y) by default; resort to expect_equal() only when needed")
3131

3232
expect_lint("expect_equal(x, 1.034)", NULL, linter)
3333
expect_lint("expect_equal(x, c(1.01, 1.02))", NULL, linter)
3434
# whole numbers with explicit decimals are OK, even in mixed scenarios
3535
expect_lint("expect_equal(x, c(1.0, 2))", NULL, linter)
3636
# plain numbers are still caught, however
37-
expect_lint("expect_equal(x, 1L)", msg, linter)
38-
expect_lint("expect_equal(x, 1)", msg, linter)
37+
expect_lint("expect_equal(x, 1L)", lint_msg, linter)
38+
expect_lint("expect_equal(x, 1)", lint_msg, linter)
3939
# NB: TRUE is a NUM_CONST so we want test matching it, even though this test is
4040
# also a violation of expect_true_false_linter()
41-
expect_lint("expect_equal(x, TRUE)", msg, linter)
41+
expect_lint("expect_equal(x, TRUE)", lint_msg, linter)
4242
})
4343

4444
test_that("expect_identical_linter skips 3e cases needing expect_equal", {

tests/testthat/test-expect_lint.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# for failure, always put the lint check or lint field that must fail first.
44

55
linter <- assignment_linter()
6-
msg <- "Use <-, not ="
6+
lint_msg <- "Use <-, not ="
77

88
test_that("no checks", {
99
expect_success(expect_lint("a", NULL, linter))
@@ -12,36 +12,36 @@ test_that("no checks", {
1212
})
1313

1414
test_that("single check", {
15-
expect_failure(expect_lint(character(), msg, linter))
16-
expect_failure(expect_lint("", msg, linter))
15+
expect_failure(expect_lint(character(), lint_msg, linter))
16+
expect_failure(expect_lint("", lint_msg, linter))
1717

18-
expect_success(expect_lint(content = "a=1", checks = msg, linters = linter))
19-
expect_success(expect_lint("a=1", msg, linter))
18+
expect_success(expect_lint(content = "a=1", checks = lint_msg, linters = linter))
19+
expect_success(expect_lint("a=1", lint_msg, linter))
2020
expect_failure(expect_lint("a=1", "asdf", linter))
21-
expect_success(expect_lint("a=1", c(message = msg), linter))
21+
expect_success(expect_lint("a=1", c(message = lint_msg), linter))
2222
expect_failure(expect_lint("a=1", c(message = NULL), linter))
23-
expect_success(expect_lint("a=1", c(message = msg, line_number = 1L), linter))
24-
expect_failure(expect_lint("a=1", c(line_number = 2L, message = msg), linter))
23+
expect_success(expect_lint("a=1", c(message = lint_msg, line_number = 1L), linter))
24+
expect_failure(expect_lint("a=1", c(line_number = 2L, message = lint_msg), linter))
2525

26-
expect_error(expect_lint("a=1", c(message = msg, lineXXX = 1L), linter), "invalid field")
26+
expect_error(expect_lint("a=1", c(message = lint_msg, lineXXX = 1L), linter), "invalid field")
2727

2828
expect_failure(expect_lint("foo ()", list(ranges = list(c(2L, 2L))), function_left_parentheses_linter()))
2929
expect_success(expect_lint("\t1", list(ranges = list(c(1L, 1L))), no_tab_linter()))
30-
expect_success(expect_lint("a=1", list(message = msg, line_number = 1L), linter))
31-
expect_failure(expect_lint("a=1", list(2L, msg), linter))
30+
expect_success(expect_lint("a=1", list(message = lint_msg, line_number = 1L), linter))
31+
expect_failure(expect_lint("a=1", list(2L, lint_msg), linter))
3232

3333
expect_error(expect_lint("1:nrow(x)", "(group)", seq_linter()), "Invalid regex result", fixed = TRUE)
3434
})
3535

3636
test_that("multiple checks", {
3737
expect_success(
38-
expect_lint(file = "exclusions-test", checks = as.list(rep(msg, 9L)), linters = linter, parse_settings = FALSE)
38+
expect_lint(file = "exclusions-test", checks = as.list(rep(lint_msg, 9L)), linters = linter, parse_settings = FALSE)
3939
)
4040

41-
expect_success(expect_lint("a=1; b=2", list(msg, msg), linter))
42-
expect_success(expect_lint("a=1; b=2", list(c(message = msg), c(message = msg)), linter))
41+
expect_success(expect_lint("a=1; b=2", list(lint_msg, lint_msg), linter))
42+
expect_success(expect_lint("a=1; b=2", list(c(message = lint_msg), c(message = lint_msg)), linter))
4343
expect_success(expect_lint("a=1; b=2", list(c(line_number = 1L), c(linter = "assignment_linter")), linter))
44-
expect_success(expect_lint("a=1; b=2", list(msg, c(line = "a=1; b=2", type = "warning")), linter))
44+
expect_success(expect_lint("a=1; b=2", list(lint_msg, c(line = "a=1; b=2", type = "warning")), linter))
4545
expect_success(expect_lint(c("a=1", "b=2"), list(c(line_number = 1L), c(line_number = 2L)), linter))
4646
expect_failure(expect_lint(c("a=1", "b=2"), list(c(line_number = 2L), c(line_number = 2L)), linter))
4747

tests/testthat/test-get_source_expressions.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ test_that("Warns if encoding is misspecified", {
111111
the_lint <- lint(filename = file, parse_settings = FALSE)[[1L]]
112112
expect_s3_class(the_lint, "lint")
113113

114-
msg <- "Invalid multibyte character in parser. Is the encoding correct?"
114+
lint_msg <- "Invalid multibyte character in parser. Is the encoding correct?"
115115
if (!isTRUE(l10n_info()[["UTF-8"]])) {
116116
# Prior to R 4.2.0, the Windows parser throws a different error message because the source code is converted to
117117
# native encoding.
118118
# This results in line 4 becoming <fc> <- 42 before the parser sees it.
119-
msg <- "unexpected '<'"
119+
lint_msg <- "unexpected '<'"
120120
}
121121

122122
expect_identical(the_lint$linter, "error")
123-
expect_identical(the_lint$message, msg)
123+
expect_identical(the_lint$message, lint_msg)
124124
expect_identical(the_lint$line_number, 4L)
125125

126126
file <- test_path("dummy_projects", "project", "cp1252_parseable.R")

0 commit comments

Comments
 (0)