Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object_name_linter() complains about ns-hooks (e.g. .onLoad) #500

Closed
salim-b opened this issue Jun 17, 2020 · 2 comments · Fixed by #614 or #633
Closed

object_name_linter() complains about ns-hooks (e.g. .onLoad) #500

salim-b opened this issue Jun 17, 2020 · 2 comments · Fixed by #614 or #633

Comments

@salim-b
Copy link
Contributor

salim-b commented Jun 17, 2020

Reprex:

example_file <- tempfile()

readr::write_file(".onLoad <- function(libname, pkgname) {\n  # some action\n}\n",
                  path = example_file)

lintr::lint(filename = example_file, linters = lintr::object_name_linter())

R's hooks for namespace events are CamelCase and you can't change that AFAIK, so lintr complaining about

Variable and function name style should be snake_case.

is pointless.

@AshesITR
Copy link
Collaborator

AshesITR commented Sep 1, 2020

Thanks for reporting this.

The following function names are special in this regard:

.onLoad(libname, pkgname)
.onAttach(libname, pkgname)
.onUnload(libpath)
.onDetach(libpath)
.Last.lib(libpath)

Additionally, .Rprofile files may also define .First and .Last.

I think a good place to add that would be in a new is_special_function() for use at https://github.com/jimhester/lintr/blob/83a73fc8698bcd2dbc82c9a12d2b4e929a811a73/R/object_name_linters.R#L129-L133

@jimhester What do you think about this?

AshesITR added a commit that referenced this issue Nov 28, 2020
Also remove relevant # nolint in lintrs own .onLoad.

fixes #500
AshesITR added a commit that referenced this issue Nov 29, 2020
)

* 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 <michaelchirico4@gmail.com>
@jimhester
Copy link
Member

Yeah, that sounds like a good plan to special case these names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants