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

Allow assignment generics on custom classes object name lintr #843

Merged
merged 5 commits into from
Mar 28, 2022

Conversation

jonkeane
Copy link
Contributor

For assignment methods like names<-.class_name I'm seeing linting errors:

> lintr::lint(text = "`names<-.my_custom_class` <- function() 2", linters = lintr::object_name_linter())
<text>:1:1: style: Variable and function name style should be snake_case or symbols.
`names<-.my_custom_class` <- function() 2

This PR resolves this (by looking for <-. and replacing it with ., in strip_names() since the <- are stripped from the generics before they are used in the matching regex in the object name lintr.

Alternatively, I could try keeping <- in both the generic list and the function names that are being linted if we think that's a better approach.

@AshesITR
Copy link
Collaborator

AshesITR commented Aug 19, 2021

Thanks for reporting this bug.
The actual problem here seems to be that the generic detection messes up.

`names<-`

is in .S3PrimitiveGenerics and thus should be considered to be a generic in and of itself. I'd prefer to fix the detection rather than automatically assume all <--functions are generic if and only if their non-setter versions are.

cc @MichaelChirico: lintr:::strip_names(.S3PrimitiveGenerics) removes "names<-" from the list of known generics. Do you remember why we needed strip_names() there and have an idea for a fix?

@jonkeane
Copy link
Contributor Author

I'm happy to try removing strip_names() from the generics detection and seeing if the tests pass / using the compare_branches.R script to check if there are any regressions.

@AshesITR
Copy link
Collaborator

Hi @jonkeane, sorry for the late reply.
I've just locally tested removing strip_names() from the generics call and didn't notice any adverse side-effects.
So this really seems like the best way to fix the issue.

@jonkeane
Copy link
Contributor Author

Is there anything you need from me to get this finished?

@AshesITR
Copy link
Collaborator

Just a few tiny things still need to be done:

  1. revert the change to strip_names()
  2. remove the strip_names() call from
    generics <- strip_names(c(
  3. Add a bullet the NEWS, crediting yourself and citing this PR number (since there is no associated issue IINM)

@jonkeane
Copy link
Contributor Author

Thanks for the follow up — I've done all three of those. I put the news at the end of the current list, but happy to move it elsewhere if that's perferable.

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, almost ready to merge.

NEWS.md Outdated
@@ -130,6 +130,7 @@ function calls. (#850, #851, @renkun-ken)
* * `object_length_linter()` correctly detects generics and only counts the implementation class towards the length.
This prevents false positive lints in the case of long generic names, e.g.
`very_very_very_long_generic_name.short_class` no longer produces a lint (#871, @AshesITR)
* Assignment generics on custom classes (#843, @jonkeane)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe *object_name_linter() now correctly detects assignment generics (#843, @jonkeane)?

NEWS.md Outdated Show resolved Hide resolved
@jonkeane
Copy link
Contributor Author

Done, and thank you, again!

@AshesITR AshesITR merged commit b225fda into r-lib:master Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants