Skip to content

fix(linter): noUselessUndefinedInitialization false positive in svelte 4.#8776

Merged
dyc3 merged 4 commits intobiomejs:mainfrom
codiini:fix/biome-6003-no-useless-undefined
Jan 19, 2026
Merged

fix(linter): noUselessUndefinedInitialization false positive in svelte 4.#8776
dyc3 merged 4 commits intobiomejs:mainfrom
codiini:fix/biome-6003-no-useless-undefined

Conversation

@codiini
Copy link
Contributor

@codiini codiini commented Jan 16, 2026

I used Claude Code to think through the issue and validate my solution with tests.

Summary

Fixes #6003

The noUselessUndefinedInitialization rule was producing false positives for exported variables. In Svelte 4, exported variables with undefined initialization are used to declare optional component props:

js let className = undefined; export { className as class }; ​

The rule incorrectly flagged this pattern because it only looked at the variable declaration in isolation, without considering that it would be exported later.

Solution

Changed the rule to use Biome's semantic model to check if a variable is exported before flagging it. This handles all export patterns:

  • Direct exports: export let x = undefined;
  • Named exports: let x = undefined; export { x };
  • Renamed exports: let x = undefined; export { x as y };
  • Default exports: let x = undefined; export default x;

Test Plan

  • Added test cases for all export patterns in noUselessUndefinedInitialization/valid.js
  • Ran cargo test -p biome_js_analyze --test spec_tests -- specs::complexity::no_useless_undefined_initialization - all tests pass
  • Manually verified with the exact pattern from the issue:
    • Before fix; undefined is incorrectly removed
    • After fix; undefined is preserved for exported variables

Docs

Documentation is included in the rule's rustdoc comments with examples showing that exported variables are not flagged.

…rted variables

Skip flagging variables initialized to undefined when they are exported,
either directly (export let x = undefined) or through a named export
(let x = undefined; export { x }).

In frameworks like Svelte, exported variables with undefined initialization
are used to declare optional props. The false positive was occurring when
a variable was initialized with undefined and later exported with renaming
(e.g., export { className as class }).

Fixes biomejs#6003
@changeset-bot
Copy link

changeset-bot bot commented Jan 16, 2026

🦋 Changeset detected

Latest commit: 9dd6a3a

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 Jan 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

Walkthrough

Adds a changeset entry and updates the noUselessUndefinedInitialization lint to use semantic analysis (Semantic) and the project's semantic model to detect exported bindings. The rule now skips variables initialized to undefined when they are exported. Tests were added/updated to include direct exports, named/renamed exports, and a default-export pattern where variables are initialised to undefined.

Suggested reviewers

  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing a false positive in the noUselessUndefinedInitialization rule for Svelte 4 exported variables.
Description check ✅ Passed The description is well-structured and directly related to the changeset, explaining the problem, solution, test plan, and documentation updates.
Linked Issues check ✅ Passed The PR fully addresses issue #6003: it detects all export patterns (direct, named, renamed, default) and prevents false positives for exported variables initialised to undefined.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the noUselessUndefinedInitialization rule behaviour and its test suite; no extraneous modifications detected.

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

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Just a nitpick: "Svelte" -> "Svelte 4", because Svelte 5 declares props differently (even though the non-runes version is still supported)

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 16, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing codiini:fix/biome-6003-no-useless-undefined (9dd6a3a) with main (96d09f4)

Summary

✅ 58 untouched benchmarks
⏩ 95 skipped benchmarks1

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.

@codiini codiini changed the title fix(linter): noUselessUndefinedInitialization false positive in svelte files. fix(linter): noUselessUndefinedInitialization false positive in svelte 4. Jan 16, 2026
@ematipico
Copy link
Member

Lol, the output emitted in the PR description is bigger than the code itself

@dyc3
Copy link
Contributor

dyc3 commented Jan 17, 2026

@codiini You'll need to update the snapshots

@codiini
Copy link
Contributor Author

codiini commented Jan 19, 2026

@dyc3 All done.

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.

I think it's safe to land it as a patch, since we're adding a check to an edge case

@dyc3 dyc3 merged commit 395746f into biomejs:main Jan 19, 2026
18 checks passed
@github-actions github-actions bot mentioned this pull request Jan 19, 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.

💅 noUselessUndefinedInitialization false positive in svelte 4 file.

3 participants