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

capture specifically generic names #755

Merged
merged 27 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aafe40a
capture specifically generic names
AshesITR Feb 13, 2021
cbc5270
add NEWS bullet
AshesITR Feb 13, 2021
a16b856
add regression test file
AshesITR Feb 13, 2021
6e45d60
add anchors to regex
AshesITR Feb 13, 2021
01e4e6d
add .lintr file to not exclude regression test file
AshesITR Feb 13, 2021
58adea5
Merge branch 'master' into fix/737-generics-names
AshesITR Feb 15, 2021
8de24a4
Merge branch 'master' into fix/737-generics-names
MichaelChirico Feb 16, 2021
1d6ec7d
Merge branch 'master' into fix/737-generics-names
MichaelChirico Feb 17, 2021
e4fa911
improve generic detection
AshesITR Feb 17, 2021
5485228
fix vapply
AshesITR Feb 17, 2021
18ed390
Merge branch 'master' into fix/737-generics-names
AshesITR Feb 17, 2021
caa1bc0
make s3 detection more robust
AshesITR Feb 17, 2021
5009392
backwards compatible base s3 generics
AshesITR Feb 17, 2021
31b7687
try fixing compatibility issues with R 3.3 and 3.4
AshesITR Feb 17, 2021
ae61e37
typo
AshesITR Feb 17, 2021
d9247a8
fix R CMD check warning (by wrapping)
AshesITR Feb 17, 2021
15ce499
remove dead code
AshesITR Feb 17, 2021
aa77625
de-lint
AshesITR Feb 17, 2021
96d20ff
Merge branch 'master' into fix/737-generics-names
AshesITR Feb 18, 2021
8da1f7b
Merge branch 'master' into fix/737-generics-names
AshesITR Feb 18, 2021
9125b61
Merge branch 'master' into fix/737-generics-names
AshesITR Mar 16, 2021
21c69ac
Merge branch 'master' into fix/737-generics-names
AshesITR Jun 5, 2021
28eed9a
Merge branch 'master' into fix/737-generics-names
AshesITR Jul 2, 2021
fced525
Merge branch 'master' into fix/737-generics-names
AshesITR Jul 2, 2021
b6873f5
use nzchar
MichaelChirico Jul 2, 2021
8d0233d
fix typo, improve style, fix compare_branches.R (forgot the fallback …
AshesITR Jul 2, 2021
fb0065e
Merge remote-tracking branch 'origin/fix/737-generics-names' into fix…
AshesITR Jul 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
^bench$
^tests/testthat/dummy_packages/package/[.]Rbuildignore$
^tests/testthat/dummy_packages/package/[.]lintr$
^tests/testthat/dummy_packages/clean/[.]lintr$
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* `lint_dir()` excludes the `renv` and `packrat` directories by default (#697, @AshesITR)
* `object_name_linter()` now excludes special R hook functions such as `.onLoad`
(#500, #614, @AshesITR and @michaelchirico)
* Improved generic detection for `object_name_linter()` (#737, @AshesITR)
* `equals_na_linter()` now lints `x != NA` and `NA == x`, and skips usages in comments (#545, @michaelchirico)
* Malformed Rmd files now cause a lint instead of an error (#571, #575, @AshesITR)
* `object_name_linter()` gains a new default style, `"symbols"`, which won't lint all-symbol object names
Expand Down
6 changes: 4 additions & 2 deletions R/object_name_linters.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ object_name_linter <- function(styles = c("snake_case", "symbols")) {
declared_s3_generics(xml),
namespace_imports(find_package(source_file$filename))$fun,
names(.knownS3Generics),
.S3PrimitiveGenerics, ls(baseenv())))
.S3PrimitiveGenerics, ls(baseenv())
))
generics <- unique(generics[generics != ""])
AshesITR marked this conversation as resolved.
Show resolved Hide resolved

style_matches <- lapply(styles, function(style) {
check_style(nms, style, generics)
Expand All @@ -83,7 +85,7 @@ check_style <- function(nms, style, generics = character()) {
if (any(!conforming)) {
possible_s3 <- re_matches(
nms[!conforming],
rex(capture(name = "generic", something), ".", capture(name = "method", something))
rex(start, capture(name = "generic", or(generics)), ".", capture(name = "method", something), end)
)
if (any(!is.na(possible_s3))) {
has_generic <- possible_s3$generic %in% generics
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/dummy_packages/clean/.lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclusions: "R/default_linter_testcode.R"
27 changes: 27 additions & 0 deletions tests/testthat/dummy_packages/clean/R/clean_generics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Regression test for #737 via expecting clean to be lint-free

#' drink_me
#' @description empty
#'
#' @export
drink_me <- function(x, ...) {
UseMethod("drink_me")
}

#' drink_me for most things
#' @export
drink_me.default <- function(x, ...) {
1
}

#' drink_me for lists
#' @export
drink_me.list <- function(x, ...) {
NULL
}

#' drink_me for data.frames
#' @export
drink_me.data.frame <- function(x, ...) {
NULL
}