diff --git a/NEWS.md b/NEWS.md index a91a788a2..7a9e98c28 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/object_name_linters.R b/R/object_name_linters.R index 424605436..6937af24e 100644 --- a/R/object_name_linters.R +++ b/R/object_name_linters.R @@ -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( @@ -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, diff --git a/R/zzz.R b/R/zzz.R index 39d962869..e67844d31 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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"