Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
00aaf53
lint(text=) finds local settings again
MichaelChirico Jun 21, 2025
a257f09
Add a comment
MichaelChirico Jun 21, 2025
b50e4e2
Annotate issue # too
MichaelChirico Jun 21, 2025
159234d
explicitly disable cyclocomp_linter under "hard mode"
MichaelChirico Jun 21, 2025
af4d66b
also need explicit parse_settings=FALSE in cyclocomp test
MichaelChirico Jun 21, 2025
3043aa1
More explicit parse_settings=FALSE
MichaelChirico Jun 22, 2025
07d31f3
must parse .Rproj settings
MichaelChirico Jun 22, 2025
990e3a3
Merge branch 'main' into lint-text-settings
MichaelChirico Jun 30, 2025
1ba8f42
Merge branch 'main' into lint-text-settings
MichaelChirico Jul 14, 2025
83125b3
revert config edit
MichaelChirico Jul 29, 2025
7deac2b
revert
MichaelChirico Jul 29, 2025
05f8fbc
revert
MichaelChirico Jul 29, 2025
f0f4a70
Revert "revert"
MichaelChirico Jul 29, 2025
e760adb
Merge branch 'main' into lint-text-settings
MichaelChirico Jul 29, 2025
9e5894e
Merge branch 'main' into lint-text-settings
MichaelChirico Jul 29, 2025
9fe5af5
amend .lintr to avoid cyclocomp here only
MichaelChirico Jul 29, 2025
90b9d7b
mention breaking change
MichaelChirico Jul 29, 2025
4511bdb
Merge remote-tracking branch 'origin/lint-text-settings' into lint-te…
MichaelChirico Jul 29, 2025
846079a
Merge branch 'main' into lint-text-settings
MichaelChirico Jul 29, 2025
a0401cc
full revert
MichaelChirico Jul 29, 2025
f3337be
only edit NEWS
MichaelChirico Jul 29, 2025
0f028e6
restore once more :)
MichaelChirico Jul 29, 2025
90f9687
delint
MichaelChirico Jul 29, 2025
aa8e5fd
dont parse when missing parse_settings
MichaelChirico Jul 29, 2025
492da73
Merge remote-tracking branch 'origin/lint-text-settings' into lint-te…
MichaelChirico Jul 29, 2025
fa8e9eb
another test
MichaelChirico Jul 29, 2025
891604a
new helper for cyclocomp
MichaelChirico Jul 29, 2025
a4e29a1
missing _
MichaelChirico Jul 29, 2025
42d628c
more typos
MichaelChirico Jul 29, 2025
61bf105
need to pass filename=
MichaelChirico Jul 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## Bug fixes

* `Lint()`, and thus all linters, ensures that the returned object's `message` attribute is consistently a simple character string (and not, for example, an object of class `"glue"`; #2740, @MichaelChirico).
* Files with encoding inferred from settings read more robustly under `lint(parse_settings = TRUE)` (#2803, @MichaelChirico).
* Files with encoding inferred from settings read more robustly under `lint(parse_settings = TRUE)` (#2803, @MichaelChirico). Thanks also to @bastistician for detecting a regression caused by the initial change for users of Emacs (#2847).
* `assignment_linter()` no longer errors if `"%<>%"` is an allowed operator (#2850, @AshesITR).

## Changes to default linters
Expand Down
3 changes: 1 addition & 2 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings =

needs_tempfile <- missing(filename) || re_matches(filename, rex(newline))
inline_data <- !is.null(text) || needs_tempfile
parse_settings <- !inline_data && isTRUE(parse_settings)

if (parse_settings) {
if (isTRUE(parse_settings)) {
read_settings(filename)
on.exit(reset_settings(), add = TRUE)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-backport_linter.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("backport_linter produces error when R version misspecified", {
expect_error(
lint(text = "numToBits(2)", linters = backport_linter(420L)),
lint(text = "numToBits(2)", linters = backport_linter(420L), parse_settings = FALSE),
"`r_version` must be an R version number"
)
})
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-cyclocomp_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ test_that("a null linter is returned, with warning, if cyclocomp is unavailable"
linter <- cyclocomp_linter(1L)
})

expect_error(lint(text = "if (TRUE) 1 else 2", linters = linter), "disabled", fixed = TRUE)
expect_error(
lint(text = "if (TRUE) 1 else 2", linters = linter, parse_settings = FALSE),
"disabled",
fixed = TRUE
)
})
19 changes: 13 additions & 6 deletions tests/testthat/test-lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ test_that("lint() results from file or text should be consistent", {
file <- normalize_path(file)

lint_from_file <- lint(file, linters = linters)
lint_from_lines <- lint(linters = linters, text = lines)
lint_from_text <- lint(linters = linters, text = text)
lint_from_lines <- lint(linters = linters, text = lines, parse_settings = FALSE)
lint_from_text <- lint(linters = linters, text = text, parse_settings = FALSE)

# Remove file before linting to ensure that lint works and do not
# assume that file exists when both filename and text are supplied.
expect_identical(unlink(file), 0L)
lint_from_text2 <- lint(file, linters = linters, text = text)
lint_from_text2 <- lint(file, linters = linters, text = text, parse_settings = FALSE)

expect_length(lint_from_file, 2L)
expect_length(lint_from_lines, 2L)
Expand Down Expand Up @@ -205,12 +205,12 @@ test_that("old compatibility usage errors", {
)

expect_error(
lint("a <- 1\n", linters = function(two, arguments) NULL),
lint("a <- 1\n", linters = function(two, arguments) NULL, parse_settings = FALSE),
error_msg
)

expect_error(
lint("a <- 1\n", linters = "equals_na_linter"),
lint("a <- 1\n", linters = "equals_na_linter", parse_settings = FALSE),
error_msg
)
})
Expand All @@ -234,7 +234,6 @@ test_that("typo in argument name gives helpful error", {
expect_error(lint("xxx", litners = identity), "Found unknown arguments in `...`: `litners`")
})


test_that("gitlab_output() writes expected report", {
skip_if_not_installed("jsonlite")

Expand Down Expand Up @@ -279,3 +278,11 @@ test_that("gitlab_output() writes expected report", {
))
)
})

test_that("settings are picked up under lint(text=)", {
.lintr <- withr::local_tempfile(lines = "linters: list(assignment_linter())")
withr::local_options(lintr.linter_file = .lintr)

# lint '=', but not the operator spacing
expect_length(lint(text = "a=1"), 1L)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ test_that("as.data.frame.lints", {
})

test_that("summary.lints() works (no lints)", {
no_lints <- lint("x <- 1\n", linters = assignment_linter())
no_lints <- lint("x <- 1\n", linters = assignment_linter(), parse_settings = FALSE)
no_lint_summary <- summary(no_lints)
expect_s3_class(no_lint_summary, "data.frame")
expect_identical(nrow(no_lint_summary), 0L)
})

test_that("summary.lints() works (lints found)", {
has_lints <- lint("x = 1\n", linters = assignment_linter())
has_lints <- lint("x = 1\n", linters = assignment_linter(), parse_settings = FALSE)
has_lint_summary <- summary(has_lints)

expect_s3_class(has_lint_summary, "data.frame")
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-spaces_left_parentheses_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ test_that("doesn't produce a warning", {
}
")

expect_no_warning(lint(text = complex_lines, linters = spaces_left_parentheses_linter()))
expect_no_warning(lint(
text = complex_lines,
linters = spaces_left_parentheses_linter(),
parse_settings = FALSE
))
})

test_that("lints vectorize", {
Expand Down
Loading