Skip to content

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

Merged
MichaelChirico merged 7 commits into
masterfrom
stopifnot_and_condition
Mar 28, 2022
Merged

MichaelChirico merged 7 commits into
masterfrom
stopifnot_and_condition

Conversation

@MichaelChirico

Copy link
Copy Markdown
Collaborator

Part of #962

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

@MichaelChirico MichaelChirico mentioned this pull request Mar 28, 2022
38 tasks done
@AshesITR

Copy link
Copy Markdown
Collaborator

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

@MichaelChirico

Copy link
Copy Markdown
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?

Comment thread R/conjunct_stopifnot_linter.R Outdated

xml <- source_file$full_xml_parsed_content

xpath <- "

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread R/conjunct_test_linter.R

xml <- source_file$full_xml_parsed_content

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

Copy link
Copy Markdown
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
Copy Markdown
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