Skip to content

feat: add assertArrayEmpty - #118

Merged
hughgrigg merged 1 commit into
mainfrom
feat/hg/array-empty-assertion
Aug 28, 2026
Merged

feat: add assertArrayEmpty#118
hughgrigg merged 1 commit into
mainfrom
feat/hg/array-empty-assertion

Conversation

@hughgrigg

Copy link
Copy Markdown
Contributor

Adds assertArrayEmpty and the emptyArray() matcher, the positive counterpart to assertArrayNotEmpty and nonEmptyArray(). Before this, assertArrayNotEmpty was the only negated assertion in the set whose twin was missing.

Resolves #117

What changes

assertArrayEmpty(value, message?) narrows to [], or to readonly [] where the calling scope already knows the array is readonly. emptyArray() does the same through assertObjectMatches. Both follow the pair in src/assert/array-not-empty/.

The failure message names the elements that are present, which is usually the diagnostic the assertion exists to produce.

Expected array ["DenyRegions: unsupported condition key aws:RequestedRegion"] (len 1) to be empty.

A non-array value mirrors the branch assertArrayNotEmpty already has (Expected string "abc" to be an empty array.).

The lint selector

prefer-specific-assertions now steers assertArrayLength(value, 0) at the new assertion. This is the first selector in the table that starts from a specific assertion rather than from assertIdentical, assertTrue or assertFalse.

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) and assertFalse(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). assertArrayLength has already committed to an array in its callee name, so that ambiguity does not arise. A literal 0 in the length position is the only shape that matches, leaving assertArrayLength(values, 2), assertArrayLength(values, expected) and assertStringLength(text, 0) alone.

Notes

assertArrayLength(value, 0) already narrowed correctly, since ArrayOfLength<T, 0> resolves to []. The gap this closes is in how the call reads and how it fails, not in the type.

src/index.ts and the README lists are generated, so both are regenerated output rather than hand edits.

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
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e0653ec-110a-4713-9ea0-a6bfa5fc2fe9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@hughgrigg
hughgrigg merged commit 45ba3f9 into main Aug 28, 2026
3 checks passed
@hughgrigg
hughgrigg deleted the feat/hg/array-empty-assertion branch August 28, 2026 18:08
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.

Add assertArrayEmpty, the positive form of assertArrayNotEmpty

1 participant