|
lines <- get_lines(filename, text) |
|
|
|
if (needs_tempfile) { |
|
filename <- tempfile() |
|
con <- file(filename, open = "w", encoding = settings$encoding) |
|
on.exit(unlink(filename), add = TRUE) |
|
writeLines(text = lines, con = con, sep = "\n") |
|
close(con) |
|
} |
|
|
|
filename <- normalize_path(filename, mustWork = !inline_data) # to ensure a unique file in cache |
|
source_expressions <- get_source_expressions(filename, lines) |
|
|
|
if (isTRUE(parse_settings)) { |
|
read_settings(filename) |
get_lines() is run before read_settings() but it relies on settings$encoding:
|
get_lines <- function(filename, text) { |
|
if (!is.null(text)) { |
|
strsplit(paste(text, collapse = "\n"), "\n", fixed = TRUE)[[1L]] |
|
} else if (re_matches(filename, rex(newline))) { |
|
strsplit(gsub("\n$", "", filename), "\n", fixed = TRUE)[[1L]] |
|
} else { |
|
read_lines(filename) |
|
read_lines <- function(file, encoding = settings$encoding, ...) { |
I seem to recall running into issues moving read_settings() earlier in lint(), but this situation seems incorrect.
This came up in #2801 -- when trying to move away from manually running lintr:::read_settings() in the test, we fail because get_source_expressions() doesn't know the encoding, and neither does moving to accessing the file by lint() instead help:
|
test_that("Can read non UTF-8 file", { |
|
file <- test_path("dummy_projects", "project", "cp1252.R") |
|
lintr:::read_settings(file) |
|
expect_null(get_source_expressions(file)$error) |
|
}) |
lintr/R/lint.R
Lines 48 to 62 in a1a2cda
get_lines()is run beforeread_settings()but it relies onsettings$encoding:lintr/R/lint.R
Lines 685 to 691 in a1a2cda
lintr/R/utils.R
Line 161 in a1a2cda
I seem to recall running into issues moving
read_settings()earlier inlint(), but this situation seems incorrect.This came up in #2801 -- when trying to move away from manually running
lintr:::read_settings()in the test, we fail becauseget_source_expressions()doesn't know the encoding, and neither does moving to accessing the file bylint()instead help:lintr/tests/testthat/test-get_source_expressions.R
Lines 106 to 110 in a1a2cda