Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LINT_BUG]: Box.linters should be able to load box modules when the working directory is changed #142

Open
osenan opened this issue Sep 3, 2024 · 2 comments
Labels
wontfix This will not be worked on

Comments

@osenan
Copy link

osenan commented Sep 3, 2024

box.linters version

‘0.10.3’

Sample source code to lint

This a reproducible (toy) example that fails (uploaded files with .txt extension, please replace with .R):
create a rhino app with rhino::init()

  1. Add attached file [init.R ](http://init.to/)to logic folder
    init.txt

  2. Add test test-two_numbers.R test-two-numbers.txt to folder tests/testthat

  3. Running rhino::test_r() passes the tests.

  4. But running rhino::lint_r()

fails, because box.linters is not following withr::with_dir.

Lint command used

linters:
linters_with_defaults(
defaults = box.linters::rhino_default_linters,
line_length_linter = line_length_linter(100)
)

rhino::lint_r()

Lint result

Linter 'box_mod_fun_exists_linter' failed in /home/osenan/Documents/Apptests/box_issues/tests/testthat/test-two-numbers.R: unable to load module “logic/init”; not found in “/home/osenan/Documents/Apptests/box_issues”, “/home/osenan/.cache/R/renv/cache/v5/linux-ubuntu-jammy/R-4.4/x86_64-pc-linux-gnu/box/1.2.0/d94049c1d9446b0abb413fde9e82a505/box/mod”, “/home/osenan/Documents/Apptests/box_issues”

There is an error in loading because it does not follows the working directory change

Expected result

lint_r shuold have been executed (could find or not style errors)

@osenan osenan added the bug Something isn't working label Sep 3, 2024
@radbasa
Copy link
Collaborator

radbasa commented Sep 12, 2024

Linters ({box.linters} or {lintr} itself), being static code analysis tools do not execute code. They cannot follow changes made by code like withr::with_*().

Linters operate within the existing current environment.

For the following case:

with_dir("../../app/",
  box::use(
    logic/init[sum_two_numbers],
  )
)

In {rhino}, the with_dir() should be unnecessary because box.path is set in .Rprofile:

options(box.path = getwd())

This would normally be the project root.

The following should work in unit tests:

  box::use(
    app/logic/init[sum_two_numbers],
  )

@osenan

@radbasa
Copy link
Collaborator

radbasa commented Sep 12, 2024

However, dealing with non-existing box module paths should be handled more gracefully. #108

@radbasa radbasa added wontfix This will not be worked on and removed bug Something isn't working labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants