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

Linter for explicit/implicit returns #2271

Merged
merged 47 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bc9f197
feat: Add `return_linter`
MEO265 Nov 8, 2023
2a54612
feat: Dont lint deterministically returning control statements
MEO265 Nov 9, 2023
293e4a2
test: Accept false negatives
MEO265 Nov 9, 2023
842a006
feat: Do not lint stop
MEO265 Nov 9, 2023
cda5823
feat: Refined lint of `switch`
MEO265 Nov 9, 2023
c091d1f
test: Add line tests
MEO265 Nov 10, 2023
067a33d
doc: Mark as configurable
MEO265 Nov 10, 2023
94955ed
mnt: Add terminal new lines
MEO265 Nov 10, 2023
8a27435
Merge branch 'main' into feature/return_linter
MEO265 Nov 10, 2023
ae5304f
incorporate new test cases, improve lint message, begin work to recon…
MichaelChirico Nov 20, 2023
336e9a5
drop in the other XPath
MichaelChirico Nov 20, 2023
a9c8801
catch OP-LAMBDA, typos, fix lint metadata
MichaelChirico Nov 20, 2023
a4a18e3
remove vestigial, clean up repeated var usage
MichaelChirico Nov 20, 2023
23b0fdb
Merge remote-tracking branch 'origin/main' into feature/return_linter
MichaelChirico Nov 20, 2023
63741c3
progress on rectifying disagreements
MichaelChirico Nov 20, 2023
580b935
more progress, simplifying XPath
MichaelChirico Nov 20, 2023
48eaab0
more test+logic adjustments, now passing tests
MichaelChirico Nov 20, 2023
c6b11be
simplify implicit XPath
MichaelChirico Nov 20, 2023
ee5eed3
test code style
MichaelChirico Nov 20, 2023
0826721
Merge branch 'main' into feature/return_linter
MichaelChirico Nov 20, 2023
bafe717
add simple examples
MichaelChirico Nov 20, 2023
f58d408
set as a default linter
MichaelChirico Nov 20, 2023
514927d
test-defaults
MichaelChirico Nov 20, 2023
b3ac25f
style guide ref in doc
MichaelChirico Nov 20, 2023
f8d958d
finish TODOs
MichaelChirico Nov 21, 2023
de3e9ce
NEWS entry
MichaelChirico Nov 21, 2023
95edca4
Merge branch 'main' into feature/return_linter
MichaelChirico Nov 21, 2023
3810968
Merge branch 'main' into feature/return_linter
MichaelChirico Nov 21, 2023
9bb7d3a
fix merge
MichaelChirico Nov 21, 2023
414257b
feat: Add parameters for exceptions
MEO265 Nov 21, 2023
8da36f4
feat: Add parameter for Runit
MEO265 Nov 21, 2023
5d67b25
feat: Lint `warning`, `message`, and `stopifnot`
MEO265 Nov 21, 2023
0b95fc7
mnt: Add terminal newline to tests
MEO265 Nov 21, 2023
4b09754
doc: Fix doc of `additional_side_effect_func`
MEO265 Nov 21, 2023
ca945bc
Merge branch 'main' into feature/return_linter
MichaelChirico Nov 23, 2023
f7afa54
Merge branch 'feature/return_linter' of github.com:MEO265/lintr into …
MichaelChirico Nov 23, 2023
91820bd
drop runit support for now
MichaelChirico Nov 23, 2023
e1961d5
style
MichaelChirico Nov 23, 2023
5248af9
rename parameter to accept "implicit"/"explicit"
MichaelChirico Nov 23, 2023
8612b70
rename other parameters
MichaelChirico Nov 23, 2023
aff7765
corresponding changes to tests
MichaelChirico Nov 23, 2023
28b51f4
dont link R4.0+ tryInvokeRestart, which is in linked page already anyway
MichaelChirico Nov 23, 2023
cb2d9c4
Merge branch 'main' into feature/return_linter
MEO265 Nov 23, 2023
8a0ea77
Merge branch 'main' into MEO265-feature/return_linter
AshesITR Nov 23, 2023
63eba24
review and fixes
AshesITR Nov 23, 2023
f89c8bc
document()
AshesITR Nov 23, 2023
325205c
Merge branch 'main' into feature/return_linter
AshesITR Nov 23, 2023
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* `library_call_linter()` is extended
+ to encourage all packages to be attached with `library(symbol)`, not `library("symbol", character.only = TRUE)` or "vectorized" approaches looping over package names (part of #884, @MichaelChirico).
+ to discourage many consecutive calls to `suppressMessages()` or `suppressPackageStartupMessages()` (part of #884, @MichaelChirico).
* `return_linter()` also has an argument `use_implicit_returns` (`TRUE` by default) which, when `FALSE`, forces all returns to be explicit (part of #884, @MichaelChirico and @MEO265).
* `return_linter()` also has an argument `return_style` (`"implicit"` by default) which checks that all functions confirm to the specified return style of `"implicit"` or `"explicit"` (part of #884, @MichaelChirico, @AshesITR and @MEO265).
* `unnecessary_lambda_linter` is extended to encourage vectorized comparisons where possible, e.g. `sapply(x, sum) > 0` instead of `sapply(x, function(x) sum(x) > 0)` (part of #884, @MichaelChirico). Toggle this behavior with argument `allow_comparison`.

### New linters
Expand Down
5 changes: 2 additions & 3 deletions R/return_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param except Character vector of functions that are not checked when
#' `return_style = "explicit"`. These are in addition to namespace hook functions
#' that are never checked: `.onLoad()`, `.onUnload()`, `.onAttach()`, `.onDetach()`,
#' and `.Last.lib()`.
#' `.Last.lib()`, `.First()` and `.Last()`.
#'
#' @examples
#' # will produce lints
Expand Down Expand Up @@ -74,9 +74,8 @@ return_linter <- function(
} else {
# See `?.onAttach`; these functions are all exclusively used for their
# side-effects, so implicit return is generally acceptable
default_except <- c(".onLoad", ".onUnload", ".onAttach", ".onDetach", ".Last.lib")

except <- union(default_except, except)
except <- union(special_funs, except)

base_return_functions <- c(
# Normal calls
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/default_linter_testcode.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ g <- function(x) {
# object_name
# object_usage
# open_curly
# return
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh! in some commit I added an explicit return here. Must not have survived. I see someone (possibly me?) added a return_linter() test case to this file in another commit.

# T_and_F_symbol
someComplicatedFunctionWithALongCamelCaseName <- function(x)
{
Expand Down
Loading
Loading