Skip to content

fix(lint): consider more constructs as valid test assertions#9178

Merged
dyc3 merged 1 commit intobiomejs:mainfrom
Bertie690:expect-type-of
Feb 23, 2026
Merged

fix(lint): consider more constructs as valid test assertions#9178
dyc3 merged 1 commit intobiomejs:mainfrom
Bertie690:expect-type-of

Conversation

@Bertie690
Copy link
Contributor

Summary

Fixes #9172
Fixes #9168

Test Plan

Added new tests for allowed constructs

Docs

More doctests were added as well.

@changeset-bot
Copy link

changeset-bot bot commented Feb 21, 2026

🦋 Changeset detected

Latest commit: c70d97f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Feb 21, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

Caution

Review failed

Failed to post review comments

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR broadens Biome's JS test-assertion recognition by treating assert, expectTypeOf, and assertType (in addition to expect) as valid expect-like assertions in the JS analyzer, updates the lint/nursery/useExpect documentation and examples to list these variants, adds a patch changeset note, and introduces a Vitest-focused TypeScript test exercising the new variants. Several formatter/parser changes across CSS/SCSS and HTML/ASTRO (new SCSS nodes, unary expressions, Astro directive/frontmatter handling, and many formatter wiring files) and multiple new test/bench fixtures were also added.

Possibly related PRs

Suggested reviewers

  • dyc3
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Extensive out-of-scope changes detected: CSS parser/formatter enhancements (SCSS nesting, unary expressions, qualified names), HTML parser/formatter Astro directive support, and numerous test fixtures unrelated to fixing lint rule false positives. Rebase PR to exclude CSS/HTML parser changes. Create separate PRs for CSS formatter SCSS support and HTML parser Astro directive enhancements; keep only the lint rule fixes and their tests.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change: expanding recognition of test assertion constructs in the useExpect lint rule.
Description check ✅ Passed The description accurately references the fixed issues (#9172 and #9168) and mentions the addition of tests and doctests.
Linked Issues check ✅ Passed Code changes fully implement the objectives from both issues: playwright.rs recognises 'assert', 'expectTypeOf', and 'assertType' as valid assertions; documentation and tests validate the new constructs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
crates/biome_js_analyze/src/lint/nursery/use_expect.rs (1)

44-44: Trailing whitespace in doc comment.

Line 44 appears to have trailing whitespace after ///. Running just f should clean this up.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_js_analyze/src/lint/nursery/use_expect.rs` at line 44, Remove
the trailing whitespace in the doc comment that currently contains "/// " in
crates/biome_js_analyze/src/lint/nursery/use_expect.rs (the standalone
doc-comment line shown in the diff); edit that line to be exactly "///" with no
trailing spaces and re-run the formatter (just f) to ensure the file is clean.
.changeset/busy-numbers-reply.md (1)

5-5: Minor grammatical tweak in the changeset title.

The title reads "Fixed consider more constructs..." which is a bit awkward. Consider rephrasing to "Fix: consider more constructs as valid test assertions" or simply "Consider more constructs as valid test assertions".

Suggested fix
-Fixed consider more constructs as valid test assertions
+Fix: consider more constructs as valid test assertions
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.changeset/busy-numbers-reply.md at line 5, Update the changeset title
string "Fixed consider more constructs as valid test assertions" to a clearer
phrasing—either "Fix: consider more constructs as valid test assertions"
(preferred conventional changeset prefix) or "Consider more constructs as valid
test assertions" so the title reads naturally; edit the single-line title in the
changeset content to match one of these suggestions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/busy-numbers-reply.md:
- Around line 14-16: The test uses incorrect TypeScript generic syntax by
calling expectTypeOf<myStr>() where myStr is a const value; change the assertion
to use a value or its type instead — either call
expectTypeOf(myStr).toBeString() or expectTypeOf<typeof myStr>().toBeString(),
updating the test that references myStr and expectTypeOf accordingly.

In `@crates/biome_js_analyze/src/lint/nursery/use_expect.rs`:
- Around line 48-50: The example uses a runtime function name directly; update
the example to query the type of the runtime value by wrapping the function name
with typeof in the expectTypeOf call — replace
expectTypeOf<myFunc>().toBeCallableWith("foo") with expectTypeOf<typeof
myFunc>().toBeCallableWith("foo") so the test explicitly references the runtime
function type (symbols to change: expectTypeOf, myFunc, toBeCallableWith).

---

Nitpick comments:
In @.changeset/busy-numbers-reply.md:
- Line 5: Update the changeset title string "Fixed consider more constructs as
valid test assertions" to a clearer phrasing—either "Fix: consider more
constructs as valid test assertions" (preferred conventional changeset prefix)
or "Consider more constructs as valid test assertions" so the title reads
naturally; edit the single-line title in the changeset content to match one of
these suggestions.

In `@crates/biome_js_analyze/src/lint/nursery/use_expect.rs`:
- Line 44: Remove the trailing whitespace in the doc comment that currently
contains "/// " in crates/biome_js_analyze/src/lint/nursery/use_expect.rs (the
standalone doc-comment line shown in the diff); edit that line to be exactly
"///" with no trailing spaces and re-run the formatter (just f) to ensure the
file is clean.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you. Code looks good, just need to tweak the changeset to follow our requirements

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 21, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 95 skipped benchmarks1


Comparing Bertie690:expect-type-of (1b0e1a9) with next (c166df3)

Open in CodSpeed

Footnotes

  1. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/busy-numbers-reply.md:
- Line 8: The markdown line containing "assert", "expectTypeOf" and "assertType"
has a trailing space causing the linter to fail; open the file, locate the line
with those tokens and remove the trailing whitespace at the end of that line
(ensure no extra spaces after the closing parenthesis), save and re-run the
pipeline to confirm the Markdown linter passes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/use_expect.rs (1)

11-68: Consider aligning the diagnostic wording with the new “allowed variants” docs.

Docs now mention assert/expectTypeOf/assertType; the diagnostic still says only expect(). A small tweak could prevent confusion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_js_analyze/src/lint/nursery/use_expect.rs` around lines 11 - 68,
The diagnostic message in the declare_lint_rule! for the use_expect rule (the
rule defined in this file—referenced by the declare_lint_rule! block / rule name
use_expect) still mentions only `expect()`; update the diagnostic text emitted
by this rule to mention the allowed variants `assert`, `expectTypeOf`, and
`assertType` (or a short phrase like "expect(), assert(), expectTypeOf(),
assertType()") so it matches the documentation and avoid confusion; locate the
diagnostic message string inside the declare_lint_rule! (the message used when
reporting tests without assertions) and edit it to include those variants and/or
a brief pointer to the docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_js_analyze/src/lint/nursery/use_expect.rs`:
- Around line 11-68: The diagnostic message in the declare_lint_rule! for the
use_expect rule (the rule defined in this file—referenced by the
declare_lint_rule! block / rule name use_expect) still mentions only `expect()`;
update the diagnostic text emitted by this rule to mention the allowed variants
`assert`, `expectTypeOf`, and `assertType` (or a short phrase like "expect(),
assert(), expectTypeOf(), assertType()") so it matches the documentation and
avoid confusion; locate the diagnostic message string inside the
declare_lint_rule! (the message used when reporting tests without assertions)
and edit it to include those variants and/or a brief pointer to the docs.

@dyc3
Copy link
Contributor

dyc3 commented Feb 21, 2026

Why is this against next? Should be against main.

@Bertie690
Copy link
Contributor Author

Bertie690 commented Feb 21, 2026

Oops

@ematipico ematipico changed the base branch from next to main February 21, 2026 18:39
@ematipico ematipico changed the base branch from main to next February 21, 2026 18:40
@Bertie690
Copy link
Contributor Author

This needs to be rebased onto main btw

@Bertie690 Bertie690 changed the base branch from next to main February 23, 2026 20:35
@Bertie690
Copy link
Contributor Author

@ematipico @dyc3
Branch has been rebased onto main, so merge at your next convenience.

@dyc3 dyc3 merged commit 101b3bb into biomejs:main Feb 23, 2026
4 checks passed
@Bertie690 Bertie690 deleted the expect-type-of branch February 23, 2026 20:58
@github-actions github-actions bot mentioned this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useExpect false positives on Chai-style assert calls 💅 useExpect false positive with expect-type's type testing expectTypeOf

3 participants