Skip to content

Fix box_usage_linter working dir resolution; add R6 inheritance support#189

Open
dereckmezquita wants to merge 1 commit into
Appsilon:mainfrom
dereckmezquita:main
Open

Fix box_usage_linter working dir resolution; add R6 inheritance support#189
dereckmezquita wants to merge 1 commit into
Appsilon:mainfrom
dereckmezquita:main

Conversation

@dereckmezquita

@dereckmezquita dereckmezquita commented Mar 30, 2026

Copy link
Copy Markdown

Fixes #150, #157, and #188.

box_usage_linter — working dir fix

box_usage_linter() didn't set the working directory before resolving module exports, so lint_dir() from a parent directory produced false positives on module$function() calls.

Applied the same withr::with_dir(get_module_working_dir(...)) pattern that the other module linters already use. 3 lines changed.

r6_usage_linter — inheritance

r6_usage_linter() ignored the inherit paramater entirely, flagging all inherited method calls as invalid.

Added get_r6_inherited_components() which resolves parent class components from:

  • Same file (including multi-level chains)
  • Other modules via box::use() (alias$Class and [Class] patterns)
  • Installed packages (via R6ClassGenerator introspection)

Includes cycle protection. Switched to file-level linting and scoped XPaths with .// to handle mutliple R6 classes per file.

Tests

  • 12 new tests, 8 fixture files
  • 444 pass, 0 fail
  • R CMD check: 0 errors, 0 warnings, 0 notes

…nce support (#1)

* Fix dir resolution when getting modules from outside dir.

* First draft to support R6 inheritance linting.

* Added support for R6 inheritence linting across files and to packages too.

* Docs updates and build.

* Docs updates and build.
@dereckmezquita dereckmezquita changed the title Fix box_usage_linter working directory resolution and add R6 inherita… Fix box_usage_linter working dir resolution; add R6 inheritance support Mar 30, 2026
@dereckmezquita

dereckmezquita commented Mar 30, 2026

Copy link
Copy Markdown
Author

box_usage_linter fixes

I wrapped the 3 module resolution calls in with::with_dir I saw this somewhere else in the code base and this resolves the issue - the box_usage_linter module was the only one not using this pattern.

r6_usage_linter new features

I use R6 classes in my codebase extensively and chained inheritance as such this is a feature I needed, I included it in this same PR.

To add support for this I switched from expression level to file level linting this is so that the full XML tree can be available for look ups across classes. I changed XPaths from // to .// to scope searches to the current R6 class node; in order to avoid cross class contamination when multiple classes are in a single module. I then iterate on all R6 classes inn the file with lapply.

I added get_r6_inherited_components to parse the inherit argument. It will:

  1. Look in the current file first.
  2. Look in box::use
  3. Allow for $ accessor.
  4. Allow for package classes.
  5. Support resolving classes across modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LINT_BUG]: box_usage_linter false positive when mixing packages with scripts in box::use

1 participant