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

Extend conjunct_expectation_linter to include stopifnot(), rename to conjunct_test_linter #1011

Merged
merged 7 commits into from
Mar 28, 2022

Conversation

MichaelChirico
Copy link
Collaborator

Part of #962

Similar naming issue to our TrueFalseAndConditionLinter which became conjunct_expectation_linter. We might consider merging them into just one linter.

@AshesITR
Copy link
Collaborator

Let's merge the linters right away. I think the old name still fits.

@MichaelChirico
Copy link
Collaborator Author

I think the old name still fits.

To me expectation is pretty related to testthat though, conjunct_assertion would be more appropriate here for stopifnot()...

conjunct_test_linter maybe?


xml <- source_file$full_xml_parsed_content

xpath <- "
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 also need to add a TODO for R>=4.0 not to lint in this case:

stopifnot(`Descriptive reason` = A && B)

possibly optionally

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. Could still be written as

stopifnot(
  `Descriptive reason, A failed` = A,
  `Descriptive reason, B failed` = B
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, but it can be tedious... consider

stopifnot(
  `x is a logical scalar` = length(x) == 1 && is.logical(x) && !is.na(x),
  `y is a logical scalar` = length(y) == 1 && is.logical(y) && !is.na(y), 
)

So I think it should be optional.

note that this is equivalent to allowing

assertthat::assert_that(length(x) == 1, is.logical(x), !is.na(x), msg="x is a logical scalar")

instead of requiring several assert_that() calls with a unique msg

@AshesITR
Copy link
Collaborator

Fine with that as well.

I think the old name still fits.

To me expectation is pretty related to testthat though, conjunct_assertion would be more appropriate here for stopifnot()...

conjunct_test_linter maybe?

Fine by me. assertthat::assert_that could be added to the list of linted functions.

@MichaelChirico
Copy link
Collaborator Author

Fine by me. assertthat::assert_that could be added to the list of linted functions.

Let's add a TODO... I'm not as familiar with assertthat... we'd have to make sure msg is unused too right?

@AshesITR
Copy link
Collaborator

Nope, assertthat::assert_that(A && B, msg = x) is equivalent to assertthat::assert_that(A, B, msg = x), very similar to testthat.

@MichaelChirico MichaelChirico changed the title New conjunct_stopifnot_linter Extend conjunct_expectation_linter to include stopifnot(), rename to conjunct_test_linter Mar 28, 2022
@@ -17,9 +17,11 @@ conjunct_expectation_linter <- function() {

xml <- source_file$full_xml_parsed_content

# TODO(#1016): include assert_that() for consideration here too
Copy link
Collaborator

Choose a reason for hiding this comment

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

That would be just or text() = 'assert_that' in the XPath

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right... plus tests. better not to clutter this PR with that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants