feat: add assertArrayEmpty - #118
Merged
Merged
Conversation
assertArrayNotEmpty shipped without a positive counterpart, the only negated assertion in the set whose twin was missing. A test asserting an array is empty had to fall back to assertArrayLength(value, 0), which reads as a count where the test means emptiness. assertArrayEmpty narrows to [] (or readonly [] where the calling scope already knows the array is readonly), and emptyArray() does the same through assertObjectMatches. The failure message names the elements that are present, which is usually the diagnostic the assertion exists to produce. prefer-specific-assertions now steers assertArrayLength(value, 0) at it. That is the first selector in the table starting from a specific assertion. Both linters run without type information, but assertArrayLength has already committed to an array in its callee name, so the string/array ambiguity that keeps the .length selectors out of the table does not arise here. Resolves #117
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
assertArrayEmptyand theemptyArray()matcher, the positive counterpart toassertArrayNotEmptyandnonEmptyArray(). Before this,assertArrayNotEmptywas the only negated assertion in the set whose twin was missing.Resolves #117
What changes
assertArrayEmpty(value, message?)narrows to[], or toreadonly []where the calling scope already knows the array is readonly.emptyArray()does the same throughassertObjectMatches. Both follow the pair insrc/assert/array-not-empty/.The failure message names the elements that are present, which is usually the diagnostic the assertion exists to produce.
A non-array value mirrors the branch
assertArrayNotEmptyalready has (Expected string "abc" to be an empty array.).The lint selector
prefer-specific-assertionsnow steersassertArrayLength(value, 0)at the new assertion. This is the first selector in the table that starts from a specific assertion rather than fromassertIdentical,assertTrueorassertFalse.That is safe here for a reason worth recording. The file comment explains that neither linter has type information, which is what keeps
assertTrue(value.length === 0)andassertFalse(value.length === 0)out of the table (a selector cannot tell a string receiver from an array one, and the array assertions throw on strings).assertArrayLengthhas already committed to an array in its callee name, so that ambiguity does not arise. A literal0in the length position is the only shape that matches, leavingassertArrayLength(values, 2),assertArrayLength(values, expected)andassertStringLength(text, 0)alone.Notes
assertArrayLength(value, 0)already narrowed correctly, sinceArrayOfLength<T, 0>resolves to[]. The gap this closes is in how the call reads and how it fails, not in the type.src/index.tsand the README lists are generated, so both are regenerated output rather than hand edits.