Appsilon / box.linters

lintr-compatible linters for box modules in R
https://appsilon.github.io/box.linters/
10 stars 0 forks source link

[LINT_BUG]: box_default_linters$box_unused_attached_mod_linter: unexpected input #147

Open SaintRod opened 2 months ago

SaintRod commented 2 months ago

box.linters version

0.10.5

Sample source code to lint

Assume test.R is a file with the below box import statement and 01_example.R is some file that exports stuff.

Sometimes it's useful to add a numeric prefix to indicate the order of operations.

The below box::use call doesn't fail but the box.linters does.

box::use(
  . / `01_example`[...],
)

Lint command used

box::use(
  box.linters[box_default_linters],
  here[here],
  lintr[lint],
)

lint(
  filename = here("test.R"),
  linters = box_default_linters$box_unused_attached_mod_linter
)

Lint result

Error: Linter 'box_unused_attached_mod_linter' failed in ./test.R: <text>:1:5: unexpected input
1: ./01_
        ^

Expected result

If box doesn't return an error, then its linters probably shouldn't either.

If the numeric prefix naming convention isn't recommended, then that's what the lint should say.

SaintRod commented 2 months ago

PS. I'm not using box.linters with rhino

caldwellst commented 1 month ago

I came here to post the same error. This is not because of numeric prefixing, but because of the use of backticks, which are required because starting a variable name with numbers is not valid in R.

Note that this also fails using the {box} recommended testing approach, where __test__ modules are nested in every module and are called in the module __init__.R file like so:

if (is.null(box::name())) {
    box::use(./`__tests__`)
}

For now I am going to simply rename the testing directory to tests, but clearly this isn't desirable behavior as {box} allows backticked module names and in some areas recommends their usage.