Skip to content

Create condition_call_linter #2226

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

Merged
merged 14 commits into from
Dec 1, 2023
Merged

Create condition_call_linter #2226

merged 14 commits into from
Dec 1, 2023

Conversation

Bisaloo
Copy link
Collaborator

@Bisaloo Bisaloo commented Oct 3, 2023

Fix #2222

I'm opening this PR so we have something tangible to discuss but I'm happy to take any feedback and do any necessary changes.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Oct 3, 2023

As far as I can tell, tests fail because there are snapshot tests to control the addition of new defaults. It's indeed probably safer to not include this linter as default at least for now. Please let me know what you think.

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 4, 2023

Since it's part of the style guide I am in favor of adding it to the defaults.
The default linter test code would need to be expanded to create a lint for this linter.

Regarding the design, I'm not sure we should lint any call.= calls under the assumption that the author has put thought into the value of call..
Therefor I'd only lint stop() without a call. argument by default. The lint message could still suggest call. = FALSE.
LMK what you think about that.

@MichaelChirico
Copy link
Collaborator

Since it's part of the style guide

Is it? The 'design' book is not the style guide... the latter AFAICT is mum on the topic. Would help to know if we intend to enforce both the style guide and the design guide by default (what does {styler} do here @lorenzwalthert?)

#' )
#'
#' @evalRd rd_tags("condition_call_linter")
#' @seealso [linters] for a complete list of linters available in lintr.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a reference link to design.tidyverse.org?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I missed the location of this comment. The link is now provided here: https://github.com/Bisaloo/lintr/blob/16a9b3f021bf960fca19e91568a0cecc75f2764e/R/condition_call_linter.R#L3-L5. Please let me know if you don't think it's appropriate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We usually put it in @seealso.

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 4, 2023

Since it's part of the style guide

Is it? The 'design' book is not the style guide... the latter AFAICT is mum on the topic. Would help to know if we intend to enforce both the style guide and the design guide by default (what does {styler} do here @lorenzwalthert?)

Good catch.

@lorenzwalthert
Copy link

{styler} only implements the style guide as per the docs.

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (edf8df2) 99.10% compared to head (134ceb0) 99.11%.

❗ Current head 134ceb0 differs from pull request most recent head 7882955. Consider uploading reports for the commit 7882955 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2226   +/-   ##
=======================================
  Coverage   99.10%   99.11%           
=======================================
  Files         124      125    +1     
  Lines        5612     5646   +34     
=======================================
+ Hits         5562     5596   +34     
  Misses         50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Oct 5, 2023

Regarding the design, I'm not sure we should lint any call.= calls under the assumption that the author has put thought into the value of call..
Therefor I'd only lint stop() without a call. argument by default. The lint message could still suggest call. = FALSE.
LMK what you think about that.

That's a good question 🤔

I could still imagine that it's useful to ensure consistency across different contributors (or different projects using the same lintr settings). The code complexity added by linting call. seems low enough that it's worth offering this flexibility.

I don't feel super strongly on this though as I personally prefer call. = FALSE but I have heard diverging opinions on the matter. Happy to follow your recommendation.

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 5, 2023

Yes to offering flexibility.

What do you think about these options?

call. = NA # force providing call.=, ignore its value
call. = TRUE # lint call. = FALSE, ignore missing call.=
call. = FALSE # force call. = FALSE

Default could be FALSE as by the design guide.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Oct 8, 2023

Any thoughts about the argument name? I have used display_call since I wasn't really inspired. I see you used call., should I update it to this?

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 8, 2023

I'm not sure, use_call comes to mind but that implies to me that TRUE does what NA is supposed to do and FALSE requires call. to be missing so that's not ideal, really.

@MichaelChirico, @IndrajeetPatil any thoughts?

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 8, 2023

Other linters tend to have some *style argument. Maybe that's also a valid idea.


Edit:

Maybe
call_style = c("always_hide", "always_show", "specify")

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Oct 10, 2023

BTW, I went back to the style guide history and I confirm this used to be part of the official style guide but is now obsolete since rlang is now recommended instead of base conditions:

tidyverse/style@78bc2e2

I'm not completely sure what makes sense in this case.

@AshesITR
Copy link
Collaborator

Let's leave it as non-default for the moment.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Nov 28, 2023

Hi all, any action required from my end to move forward with this PR?

@AshesITR
Copy link
Collaborator

Hi, you could address my comment (adding a link to the location in tidy design principles which states what this linter checks).
There are also a few lints that need fixing and an entry in NEWS.md giving you credit should be added.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Nov 30, 2023

How should I go about applying this linter to lintr itself? I think you usually do a separate PR. Is that right?

@IndrajeetPatil
Copy link
Collaborator

How should I go about applying this linter to lintr itself? I think you usually do a separate PR. Is that right?

No, we actually fix the lints in lintr in the PR itself. This exercise acts as a good proof of concept 😺

/parent::expr
")

Linter(function(source_expression) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You will also need to update this PR to use this new attribute introduced in #2352

@MichaelChirico
Copy link
Collaborator

How should I go about applying this linter to lintr itself? I think you usually do a separate PR. Is that right?

No, we actually fix the lints in lintr in the PR itself. This exercise acts as a good proof of concept 😺

I would say 'it depends', if there are only a few hits on {lintr}, go ahead and include fixes, but if there are dozens of things to change it will be better in a separate/focused PR.

Anyway, maybe you are asking about whether the new linter will be part of our .lintr config. As of #2328 all linters are applied to {lintr} right away by default.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Nov 30, 2023

How should I go about applying this linter to lintr itself? I think you usually do a separate PR. Is that right?

No, we actually fix the lints in lintr in the PR itself. This exercise acts as a good proof of concept 😺

I would say 'it depends', if there are only a few hits on {lintr}, go ahead and include fixes, but if there are dozens of things to change it will be better in a separate/focused PR.

Anyway, maybe you are asking about whether the new linter will be part of our .lintr config. As of #2328 all linters are applied to {lintr} right away by default.

I've made the change in 0b2e34d and 427b258 but I can easily cherry-pick them in a different branch and remove them from here if you prefer.

@MichaelChirico
Copy link
Collaborator

How should I go about applying this linter to lintr itself? I think you usually do a separate PR. Is that right?

No, we actually fix the lints in lintr in the PR itself. This exercise acts as a good proof of concept 😺

I would say 'it depends', if there are only a few hits on {lintr}, go ahead and include fixes, but if there are dozens of things to change it will be better in a separate/focused PR.
Anyway, maybe you are asking about whether the new linter will be part of our .lintr config. As of #2328 all linters are applied to {lintr} right away by default.

I've made the change in 0b2e34d and 427b258 but I can easily cherry-pick them in a different branch and remove them from here if you prefer.

Yes, please do. The diff is quite large now.

@IndrajeetPatil
Copy link
Collaborator

Sorry, @Bisaloo, for the incorrect advice. Didn't realize there would be so many new lints found in lintr for the current linter.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Dec 1, 2023

Yes, please do. The diff is quite large now.

There is now a separate PR for this: #2377. I'll rebase this PR on main once it's merged.

Sorry, @Bisaloo, for the incorrect advice. Didn't realize there would be so many new lints found in lintr for the current linter.

No worries, I understand there can be some variability depending on the specifics of each case and it wasn't much work to move these commits to a separate branch.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Dec 1, 2023

This PR has now been rebased on main.

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.

LGTM. I'd move the link to @seealso for consistency among the help pages, though.

@AshesITR AshesITR merged commit 38c3f62 into r-lib:main Dec 1, 2023
@Bisaloo Bisaloo deleted the call-condition branch December 2, 2023 08:55
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.

Enforce use of call. = FALSE in stop() and warning()
6 participants