Skip to content

Commit ae2870d

Browse files
committed
Fix data.frame.lints issue
1 parent a51c268 commit ae2870d

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

NEWS.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
and do not consider "-" an R operator to avoid too many false positives.
2626
* Fixed object linters to only lint objects declared in the current file
2727
(#76, #108, #136, #191, #194, #201, @fangly).
28-
* Fixed cache not saved in the requested directory (#213, @fangly)
2928
* Fixed expect_lint() issues (#180, #211, @fangly): markers were displayed when
3029
check was NULL, some error messages were malformed.
30+
* Fixed Lint() / as.data.frame() error (#179, @fangly).
3131
* Do not error with inline \\Sexpr (#127).
3232
* Do not error with '<% %>' constructs (#185).
3333
* Allow closing parenthesis or comma after closing curly brace (#167, @Enchufa2)
@@ -37,6 +37,7 @@
3737
https://github.com/MangoTheCat/xmlparsedata package (#154, @gaborcsardi)
3838
* lintr does not need the igraph package any more (#152, @gaborcsardi)
3939
* Fixed lint_package bug where cache was not caching (#146, @schloerke)
40+
* Fixed cache not saved in a directory other than requested (#213, @fangly)
4041
* Commas linter handles missing arguments calls properly (#145)
4142

4243
# lintr 1.0.0 #

R/lint.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ pkg_name <- function(path = find_package()) {
217217
#' @param ranges ranges on the line that should be emphasized.
218218
#' @param linter name of linter that created the Lint object.
219219
#' @export
220-
Lint <- function(filename, line_number = 1L, column_number = NULL,
220+
Lint <- function(filename, line_number = 1L, column_number = 1L,
221221
type = c("style", "warning", "error"),
222-
message = "", line = "", ranges = NULL, linter = NULL) {
222+
message = "", line = "", ranges = NULL, linter = "") {
223223

224224
type <- match.arg(type)
225225

226226
structure(
227227
list(
228228
filename = filename,
229229
line_number = as.integer(line_number),
230-
column_number = as.integer(column_number) %||% 1L,
230+
column_number = as.integer(column_number),
231231
type = type,
232232
message = message,
233233
line = line,

man/Lint.Rd

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
% Generated by roxygen2: do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/lint.R
33
\name{Lint}
44
\alias{Lint}
55
\title{Create a \code{Lint} object}
66
\usage{
7-
Lint(filename, line_number = 1L, column_number = NULL, type = c("style",
7+
Lint(filename, line_number = 1L, column_number = 1L, type = c("style",
88
"warning", "error"), message = "", line = "", ranges = NULL,
9-
linter = NULL)
9+
linter = "")
1010
}
1111
\arguments{
1212
\item{filename}{path to the source file that was linted.}

tests/testthat/test-methods.R

+47
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,50 @@ test_that("it returns the input trimmed to the last full lint if one exists with
1717

1818
expect_equal(trim_output(t1, max = 2000), substr(t1, 1, 1930))
1919
})
20+
21+
test_that("as.data.frame.lints", {
22+
# A minimum lint
23+
expect_is(
24+
l1 <- Lint("dummy.R",
25+
line_number = 1L,
26+
type = "style",
27+
message = "",
28+
line = ""),
29+
"lint"
30+
)
31+
32+
# A larger lint
33+
expect_is(
34+
l2 <- Lint("dummy.R",
35+
line_number = 2L,
36+
column_number = 6L,
37+
type = "error",
38+
message = "Under no circumstances is the use of foobar allowed.",
39+
line = "a <- 1",
40+
ranges = list(c(1, 2), c(10, 20)),
41+
linter = "custom_linter"),
42+
"lint"
43+
)
44+
45+
# Convert lints to data.frame
46+
lints <- structure(list(l1, l2), class = "lints")
47+
expect_is(
48+
df <- as.data.frame.lints(lints),
49+
"data.frame"
50+
)
51+
52+
exp <- data.frame(
53+
filename = rep("dummy.R", 2),
54+
line_number = c(1, 2),
55+
column_number = c(1, 6),
56+
type = c("style", "error"),
57+
message = c("", "Under no circumstances is the use of foobar allowed."),
58+
line = c("", "a <- 1"),
59+
linter = c("", "custom_linter"),
60+
stringsAsFactors = FALSE)
61+
62+
expect_equal(
63+
df,
64+
exp
65+
)
66+
})

0 commit comments

Comments
 (0)