Skip to content

Commit 83f8e85

Browse files
committed
fix lint-order in the knitr-format tests
Each of the knitr-format tests had code blocks that look like this: ~~~~ a = 1 ~~~~ ~~~~ b <- function(x) { d = 1 } ~~~~ The tests for the lints found in these blocks were misordered (revealed once the object-usage-linter line-numbers had been fixed). The lints should be ordered: - assignment (`=` for a) - local variable ‘d’ assigned but may not be used - assignment (`=` for d) - trailing blank line I updated the tests and added the explicit line-numbers where the lints should throw to test-knitr_formats.R
1 parent 84c89fc commit 83f8e85

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

tests/testthat/test-knitr_formats.R

+24-24
Original file line numberDiff line numberDiff line change
@@ -12,65 +12,65 @@ test_that("it handles dir", {
1212
test_that("it handles markdown", {
1313
expect_lint(file = "knitr_formats/test.Rmd",
1414
checks = list(
15-
rex("local variable"),
16-
rex("Use <-, not =, for assignment."),
17-
rex("Use <-, not =, for assignment."),
18-
rex("Trailing blank lines are superfluous.")
15+
list(rex("Use <-, not =, for assignment."), line_number = 9),
16+
list(rex("local variable"), line_number = 22),
17+
list(rex("Use <-, not =, for assignment."), line_number = 22),
18+
list(rex("Trailing blank lines are superfluous."), line_number = 24)
1919
),
2020
default_linters
2121
)
2222
})
2323
test_that("it handles Sweave", {
2424
expect_lint(file = "knitr_formats/test.Rnw",
2525
checks = list(
26-
rex("local variable"),
27-
rex("Use <-, not =, for assignment."),
28-
rex("Use <-, not =, for assignment."),
29-
rex("Trailing blank lines are superfluous.")
26+
list(rex("Use <-, not =, for assignment."), line_number = 12),
27+
list(rex("local variable"), line_number = 24),
28+
list(rex("Use <-, not =, for assignment."), line_number = 24),
29+
list(rex("Trailing blank lines are superfluous."), line_number = 26)
3030
),
3131
default_linters
3232
)
3333
})
3434
test_that("it handles reStructuredText", {
3535
expect_lint(file = "knitr_formats/test.Rrst",
3636
checks = list(
37-
rex("local variable"),
38-
rex("Use <-, not =, for assignment."),
39-
rex("Use <-, not =, for assignment."),
40-
rex("Trailing blank lines are superfluous.")
37+
list(rex("Use <-, not =, for assignment."), line_number = 10),
38+
list(rex("local variable"), line_number = 23),
39+
list(rex("Use <-, not =, for assignment."), line_number = 23),
40+
list(rex("Trailing blank lines are superfluous."), line_number = 25)
4141
),
4242
default_linters
4343
)
4444
})
4545
test_that("it handles HTML", {
4646
expect_lint(file = "knitr_formats/test.Rhtml",
4747
checks = list(
48-
rex("local variable"),
49-
rex("Use <-, not =, for assignment."),
50-
rex("Use <-, not =, for assignment."),
51-
rex("Trailing blank lines are superfluous.")
48+
list(rex("Use <-, not =, for assignment."), line_number = 15),
49+
list(rex("local variable"), line_number = 27),
50+
list(rex("Use <-, not =, for assignment."), line_number = 27),
51+
list(rex("Trailing blank lines are superfluous."), line_number = 29)
5252
),
5353
default_linters
5454
)
5555
})
5656
test_that("it handles tex", {
5757
expect_lint(file = "knitr_formats/test.Rtex",
5858
checks = list(
59-
rex("local variable"),
60-
rex("Use <-, not =, for assignment."),
61-
rex("Use <-, not =, for assignment."),
62-
rex("Trailing blank lines are superfluous.")
59+
list(rex("Use <-, not =, for assignment."), line_number = 11),
60+
list(rex("local variable"), line_number = 23),
61+
list(rex("Use <-, not =, for assignment."), line_number = 23),
62+
list(rex("Trailing blank lines are superfluous."), line_number = 25)
6363
),
6464
default_linters
6565
)
6666
})
6767
test_that("it handles asciidoc", {
6868
expect_lint(file = "knitr_formats/test.Rtxt",
6969
checks = list(
70-
rex("local variable"),
71-
rex("Use <-, not =, for assignment."),
72-
rex("Use <-, not =, for assignment."),
73-
rex("Trailing blank lines are superfluous.")
70+
list(rex("Use <-, not =, for assignment."), line_number = 9),
71+
list(rex("local variable"), line_number = 22),
72+
list(rex("Use <-, not =, for assignment."), line_number = 22),
73+
list(rex("Trailing blank lines are superfluous."), line_number = 24)
7474
),
7575
default_linters
7676
)

0 commit comments

Comments
 (0)