Skip to content

Commit

Permalink
use normalizePath() in find_package() (#1765)
Browse files Browse the repository at this point in the history
* use normalizePath() in find_package()

fixes #1759

* allow undesirable_operator ::: in test-settings.R

* d'oh

* remove unnecessary testthat.R

* add back testthat.R without comments

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>
  • Loading branch information
AshesITR and IndrajeetPatil authored Nov 9, 2022
1 parent f486464 commit 7a4fcee
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

* `namespace_linter()` correctly recognizes backticked operators to be exported from respectives namespaces (like `` rlang::`%||%` ``) (#1752, @IndrajeetPatil)

* `lint_package()` correctly finds a package from within a subdir if the `path` points to anywhere within the package (#1759, @AshesITR)

## Changes to defaults

* Set the default for the `except` argument in `duplicate_argument_linter()` to `c("mutate", "transmute")`.
Expand Down
1 change: 1 addition & 0 deletions R/settings_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ has_description <- function(path) {
}

find_package <- function(path) {
path <- normalizePath(path)
depth <- 2L
while (!has_description(path)) {
path <- dirname(path)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/dummy_packages/assignmentLinter/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Author: Who wrote it
Maintainer: Who to complain to <yourfault@somewhere.net>
Description: More about what it does (maybe more than one line)
License: What license is it under?
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(assignmentLinter)

test_check("assignmentLinter")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("test abc", {
expect_equal(2 * 2, 4)
})
14 changes: 13 additions & 1 deletion tests/testthat/test-lint_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ test_that(
)
lints_from_a_subdir <- withr::with_dir(
file.path(pkg_path, "R"),
lint_package("..", linters = list(assignment_linter()))
lint_package(".", linters = list(assignment_linter()))
)
lints_from_a_subsubdir <- withr::with_dir(
file.path(pkg_path, "tests", "testthat"),
lint_package(".", linters = list(assignment_linter()))
)

expect_identical(
Expand All @@ -114,6 +118,14 @@ test_that(
"(.lintr config present)"
)
)
expect_identical(
as.data.frame(lints_from_outside),
as.data.frame(lints_from_a_subsubdir),
info = paste(
"lint_package() finds the same lints from a sub-subdir as from outside a pkg",
"(.lintr config present)"
)
)
}
)

Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-settings.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# nolint start: undesirable_operator.
# This test file tests multiple internal lintr functions, so we need to allow lintr:::*
test_that("it uses default settings if none provided", {
lintr:::read_settings(NULL)

Expand Down Expand Up @@ -98,8 +100,8 @@ test_that("it has a smart default for encodings", {
lintr:::read_settings(NULL)
expect_identical(settings$encoding, "UTF-8")

proj_file <- test_path("dummy_projects", "project", "metropolis-hastings-rho.R")
pkg_file <- test_path("dummy_packages", "cp1252", "R", "metropolis-hastings-rho.R")
proj_file <- test_path("dummy_projects", "project", "cp1252.R")
pkg_file <- test_path("dummy_packages", "cp1252", "R", "cp1252.R")

expect_identical(
normalizePath(find_rproj_at(find_rproj_or_package(proj_file)), winslash = "/"),
Expand All @@ -119,3 +121,4 @@ test_that("it has a smart default for encodings", {
lintr:::read_settings(pkg_file)
expect_identical(settings$encoding, "ISO8859-1")
})
# nolint end

0 comments on commit 7a4fcee

Please sign in to comment.