@@ -4,59 +4,58 @@ local({
4
4
# Note: cases indicated by "*" are whole numbers, but don't lint because the user has
5
5
# effectively declared "this is a double" much as adding '.0' is otherwise accepted.
6
6
cases <- tibble :: tribble(
7
- ~ num_value_str , ~ should_lint ,
8
- " Inf" , FALSE ,
9
- " NaN" , FALSE ,
10
- " TRUE" , FALSE ,
11
- " FALSE" , FALSE ,
12
- " NA" , FALSE ,
13
- " NA_character_" , FALSE ,
14
- " 2.000" , FALSE ,
15
- " 2." , FALSE ,
16
- " 2L" , FALSE ,
17
- " 2.0" , FALSE ,
18
- " 2.1" , FALSE ,
19
- " 2" , TRUE ,
20
- " 1e3" , TRUE ,
21
- " 1e3L" , FALSE ,
22
- " 1.0e3L" , FALSE ,
23
- " 1.2e3" , FALSE , # * ( = 1200)
24
- " 1.2e-3" , FALSE ,
25
- " 1e-3" , FALSE ,
26
- " 1e-33" , FALSE ,
27
- " 1.2e0" , FALSE ,
28
- " 0x1p+0" , FALSE , # * ( = 1)
29
- " 0x1.ecp+6L" , FALSE ,
30
- " 0x1.ecp+6" , FALSE , # * ( = 123)
31
- " 0x1.ec66666666666p+6" , FALSE ,
32
- " 8i" , FALSE ,
33
- " 8.0i" , FALSE
7
+ ~ num_value_str , ~ lint_msg ,
8
+ " Inf" , " " ,
9
+ " NaN" , " " ,
10
+ " TRUE" , " " ,
11
+ " FALSE" , " " ,
12
+ " NA" , " " ,
13
+ " NA_character_" , " " ,
14
+ " 2.000" , " " ,
15
+ " 2." , " " ,
16
+ " 2L" , " " ,
17
+ " 2.0" , " " ,
18
+ " 2.1" , " " ,
19
+ " 2" , " 2L or 2.0 " ,
20
+ " 1e3" , " 1000L or 1000.0 " ,
21
+ " 1e3L" , " " ,
22
+ " 1.0e3L" , " " ,
23
+ " 1.2e3" , " " , # * ( = 1200)
24
+ " 1.2e-3" , " " ,
25
+ " 1e-3" , " " ,
26
+ " 1e-33" , " " ,
27
+ " 1.2e0" , " " ,
28
+ " 0x1p+0" , " " , # * ( = 1)
29
+ " 0x1.ecp+6L" , " " ,
30
+ " 0x1.ecp+6" , " " , # * ( = 123)
31
+ " 0x1.ec66666666666p+6" , " " ,
32
+ " 8i" , " " ,
33
+ " 8.0i" , " "
34
34
)
35
35
# for convenience of coercing these to string (since tribble doesn't support auto-conversion)
36
36
int_max <- .Machine [[" integer.max" ]] # largest number that R can represent as an integer
37
37
cases_int_max <- tibble :: tribble(
38
- ~ num_value_str , ~ should_lint ,
39
- - int_max - 1.0 , FALSE ,
40
- - int_max , TRUE ,
41
- int_max , TRUE ,
42
- int_max + 1.0 , FALSE
38
+ ~ num_value_str , ~ lint_msg ,
39
+ - int_max - 1.0 , " " ,
40
+ - int_max , sprintf( " %1$dL or %1$d.0 " , - int_max ) ,
41
+ int_max , sprintf( " %1$dL or %1$d.0 " , int_max ) ,
42
+ int_max + 1.0 , " "
43
43
)
44
44
cases_int_max $ num_value_str <- as.character(cases_int_max $ num_value_str )
45
45
cases <- rbind(cases , cases_int_max )
46
- cases $ .test_name <- sprintf(" num_value_str=%s, should_lint=%s" , cases $ num_value_str , cases $ should_lint )
47
46
48
47
linter <- implicit_integer_linter()
49
48
patrick :: with_parameters_test_that(
50
49
" single numerical constants are properly identified " ,
51
- expect_lint(num_value_str , if (should_lint ) " Avoid implicit integers " , linter ),
50
+ expect_lint(num_value_str , if (nzchar( lint_msg )) lint_msg , linter ),
52
51
.cases = cases
53
52
)
54
53
})
55
54
# styler: on
56
55
57
56
test_that(" linter returns the correct linting" , {
58
57
linter <- implicit_integer_linter()
59
- lint_msg <- rex :: rex(" Avoid implicit integers. Use e.g. 1L for integers or 1.0 for doubles ." )
58
+ lint_msg <- rex :: rex(" Use 1L or 1.0 to avoid implicit integers ." )
60
59
61
60
expect_lint(" x <<- 1L" , NULL , linter )
62
61
expect_lint(" 1.0/-Inf -> y" , NULL , linter )
@@ -67,7 +66,7 @@ test_that("linter returns the correct linting", {
67
66
)
68
67
expect_lint(
69
68
" z <- 1e5" ,
70
- list (message = lint_msg , line_number = 1L , column_number = 9L ),
69
+ list (message = rex :: rex( " 100000L or 100000.0 " ) , line_number = 1L , column_number = 9L ),
71
70
linter
72
71
)
73
72
expect_lint(
@@ -78,8 +77,8 @@ test_that("linter returns the correct linting", {
78
77
expect_lint(
79
78
" 552^9" ,
80
79
list (
81
- list (message = lint_msg , line_number = 1L , column_number = 4L ),
82
- list (message = lint_msg , line_number = 1L , column_number = 6L )
80
+ list (message = rex :: rex( " 552L or 552.0 " ) , line_number = 1L , column_number = 4L ),
81
+ list (message = rex :: rex( " 9L or 9.0 " ) , line_number = 1L , column_number = 6L )
83
82
),
84
83
linter
85
84
)
@@ -90,7 +89,7 @@ patrick::with_parameters_test_that(
90
89
" numbers in a:b input are optionally not linted" ,
91
90
expect_lint(
92
91
paste0(left , " :" , right ),
93
- if (n_lints > 0L ) rep(list (" Avoid implicit integers " ), n_lints ),
92
+ if (n_lints > 0L ) rep(list (rex :: rex( " Use 1L or 1.0 " ) ), n_lints ),
94
93
implicit_integer_linter(allow_colon = allow_colon )
95
94
),
96
95
.cases = tibble :: tribble(
0 commit comments