Skip to content

Commit

Permalink
Allow .onLoad and other special functions regardless of name style
Browse files Browse the repository at this point in the history
Also remove relevant # nolint in lintrs own .onLoad.

fixes #500
  • Loading branch information
AshesITR committed Nov 28, 2020
1 parent 92c2a9c commit 0b7c3a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* New `sprintf_linter()` (#544, #578, @renkun-ken)
* Exclusions specified in the `.lintr` file are now relative to the location of that file
and support excluding entire directories (#158, #438, @AshesITR)
* `object_name_linter()` now excludes special R functions such as `.onLoad` (#500, #614, @AshesITR)

# lintr 2.0.1

Expand Down
17 changes: 16 additions & 1 deletion R/object_name_linters.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ make_object_linter <- function(fun) {
keep_indices <- which(
!is_operator(names) &
!is_known_generic(names) &
!is_base_function(names)
!is_base_function(names) &
!is_special_function(names)
)

lapply(
Expand Down Expand Up @@ -239,6 +240,20 @@ is_base_function <- function(x) {
x %in% base_funs
}

special_funs <- c(
".onLoad",
".onAttach",
".onUnload",
".onDetach",
".Last.lib",
".First",
".Last"
)

is_special_function <- function(x) {
x %in% special_funs
}

object_lint <- function(source_file, token, message, type) {
Lint(
filename = source_file$filename,
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ default_settings <- NULL

settings <- NULL

.onLoad <- function(libname, pkgname) { # nolint
.onLoad <- function(libname, pkgname) {
op <- options()
op.lintr <- list(
lintr.linter_file = ".lintr"
Expand Down

0 comments on commit 0b7c3a8

Please sign in to comment.