lintr
lintr copied to clipboard
Linter for package code that is not within a function
This is usually bad practice.
Could you be more specific about what should be linted exactly?
Well, I am not entirely sure, it depends on how strict you want to be. If very strict, then all package code that is not a function definition. But of course this would also catch (S4, R6, etc.) class definitions, which is not good. So maybe it is not realistic to implement this.
Maybe lint all top level non-assignment expressions except for some whitelisted function calls, string literals (used for roxygen on data) and NULL?
Otherwise, factory patterns (e.g. R6) would be false positives.
Alternatively, another whitelist of factory functions would be necessary.
Top level assignments can be bad as well, actually, e.g.
foo <- anotherpackage::fun()
is not good practice. (Of course sometimes you do need it.)
Yeah, that's exactly the factory pattern I meant.
MyClass <- R6::R6Class(...)
I have yet to see packages with problematic use of that pattern, though.
Happy to support anyone trying to implement this, but it seems there's not much interest.