Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

@emmanuel-ferdman emmanuel-ferdman commented Nov 2, 2025

PR Summary

This PR fixes package_hooks_linter to properly validate .onUnload() hook signatures. Previously, the linter would silently ignore .onUnload() functions with missing or incorrect arguments, but R CMD check requires .onUnload() to take exactly one argument starting with 'lib' (like libpath). The fix adds .onUnload to the existing argument validation logic that was already checking .onDetach() and .Last.lib().

R source reference for .onUnload(libpath): https://github.com/wch/r-source/blob/97f6c68d5856ecc2257867e89bc870d7e49a8da8/src/library/base/R/namespace.R#L881-L892

Fixes #2940.

Related: #2737

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.24%. Comparing base (ec332f1) to head (91648e9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2964   +/-   ##
=======================================
  Coverage   99.24%   99.24%           
=======================================
  Files         129      129           
  Lines        7282     7282           
=======================================
  Hits         7227     7227           
  Misses         55       55           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

rex::rex(".onUnload() should take one argument starting with 'lib'."),
linter
)
expect_lint(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use expect_no_lint here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed 🙌

@MichaelChirico
Copy link
Collaborator

thanks! basically LGTM. please link the R source of how this is enforced in the PR description for future reference

@MichaelChirico
Copy link
Collaborator

Oh, @emmanuel-ferdman, thanks for the link. Actually, what I had in mind is:

https://github.com/r-devel/r-svn/blob/9b7baa54a5026c23fe69ddbf7b9cc9874e78762a/src/library/tools/R/QC.R#L5498-L5501

But, it turns out that's not currently enforced by R CMD check for .unUnload() hooks. Probably that should become a Bugzilla report, I'm short of time to do so at the moment.

@MichaelChirico MichaelChirico merged commit 81eba81 into r-lib:main Nov 3, 2025
21 checks passed
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.

package_hooks_linter should trigger on .onUnload without arguments

2 participants