Skip to content

Commit

Permalink
Allow .onLoad and other special functions regardless of name style (#614
Browse files Browse the repository at this point in the history
)

* Allow .onLoad and other special functions regardless of name style

Also remove relevant # nolint in lintrs own .onLoad.

fixes #500

* add a note about source for maintenance

* Clarify NEWS

Co-authored-by: Michael Chirico <[email protected]>
  • Loading branch information
AshesITR and MichaelChirico authored Nov 29, 2020
1 parent f5b4750 commit e48ace4
Show file tree
Hide file tree
Showing 3 changed files with 19 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, #624, #625, @renkun-ken, @AshesITR)
* 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 hook functions such as `.onLoad` (#500, #614, @AshesITR)

# lintr 2.0.1

Expand Down
18 changes: 17 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,21 @@ is_base_function <- function(x) {
x %in% base_funs
}

# see ?".onLoad" and ?"Startup"
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 e48ace4

Please sign in to comment.