Skip to content

feat(linter): add noReactObjectTypeAsDefaultProp rule - #10634

Merged
ematipico merged 26 commits into
biomejs:mainfrom
subaru-hello:feat/no-object-type-as-default-prop
Sep 19, 2026
Merged

ematipico merged 26 commits into
biomejs:mainfrom
subaru-hello:feat/no-object-type-as-default-prop

Conversation

@subaru-hello

@subaru-hello subaru-hello commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Ports no-object-type-as-default-prop from eslint-plugin-react as noObjectTypeAsDefaultProp in the nursery group.

The rule reports reference-type defaults on destructured props of React function components. These create a new instance on every render, which can break memoization and trigger extra re-renders. Primitive defaults are fine.

It flags the following default value types:

  • object literals ({})
  • array literals ([])
  • arrow functions / function expressions
  • class expressions
  • new expressions
  • JSX elements
  • regular expressions
  • Symbol() calls

Closes #7656

Notes

  • Component detection uses Biome's existing ReactComponentInfo (name + param count), not return-value analysis. Two cases differ from upstream:
    • export default function NotReturningJsx({ foo = {} }) {} is reported (PascalCase name).
    • ({ a = {} }, context) => {} is not reported (two params, so not a component here).
  • Handles function declarations, arrow/function expressions in a PascalCase variable, memo/forwardRef wrappers, and default-exported functions.
  • Checks top-level defaults, including aliased properties, like upstream.

Test plan

  • cargo test -p biome_js_analyze -- no_object_type_as_default_prop
  • cargo run -p rules_check
  • just gen-analyzer

The committed snapshots (invalid.jsx.snap / valid.jsx.snap) show the rendered diagnostics for every flagged type.

AI usage disclosure

I used an AI assistant (Claude) heavily while writing this PR — for finding the right syntax-tree APIs, writing a lot of the traversal code, fixing compile errors, and polishing the docs. I made the design decisions (how components are detected, which default types to flag, the differences from upstream), wrote the test cases, and reviewed and verified all the code.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Parser Area: parser A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port no-object-type-as-default-prop from react rules

5 participants