lintr icon indicating copy to clipboard operation
lintr copied to clipboard

New `return_linter` to enforce consistent return style

Open AshesITR opened this issue 2 years ago • 2 comments

Tidyverse expects implicit returns, so those should be the default.

Basically check that the last expr in all function definitions is a) never a return() or b) always a return().

Signature could maybe be return_linter(use_implicit_returns = TRUE)?

The google linters introduced a bunch of these (grep return\(lapply\( R/*.R)

AshesITR avatar Apr 25 '22 20:04 AshesITR

these are coming from Google having the opposite policy which is always to have explicit returns.

in fact ExplicitReturnLinter is part of the extended suite (explicitly tabled because of this conflicting issue), so we can work the new option into the implementation there.

MichaelChirico avatar Apr 25 '22 21:04 MichaelChirico

This would be a great addition. Happy to help beta test.

mjsteinbaugh avatar Jun 07 '22 13:06 mjsteinbaugh

Seconding the ask here, would definitely find this linter useful!

givison avatar Feb 23 '23 16:02 givison

FYI @mjsteinbaugh and @givison there's a pending version in #2271

MichaelChirico avatar Nov 21 '23 01:11 MichaelChirico

Thanks @MichaelChirico I'll check it out!

mjsteinbaugh avatar Nov 21 '23 13:11 mjsteinbaugh