Skip to content

refactor(renderer): use function declarations for React components - #3421

Merged
setchy merged 1 commit into
mainfrom
refactor/function-component-declarations
Oct 15, 2026
Merged

setchy merged 1 commit into
mainfrom
refactor/function-component-declarations

Conversation

@setchy

@setchy setchy commented Oct 14, 2026

Copy link
Copy Markdown
Member

Summary

Enable oxlint's react/function-component-definition rule and migrate the renderer's React components to function declarations, so the codebase keeps one enforced component style instead of drifting between React.FC arrows and declarations.

Changes

  • vite.config.mts: enable react/function-component-definition with namedComponents: 'function-declaration' and unnamedComponents: 'arrow-function'. The unnamedComponents option keeps anonymous inline components — e.g. the createWrapper render wrappers in hooks/*.test.tsx — legal, so they are untouched.
  • src/renderer/** (79 files): convert 83 component definitions from export const X: FC<Props> = (props) => ... to function X(props: Props), moving each prop type onto its parameter and pruning the FC imports whose only use was the definition.
  • React.FC is retained where it types a component value rather than a definition — the rule does not govern those:
    • routes/Accounts.tsx (getScopeIcon return type)
    • components/avatars/AvatarWithFallback.tsx, components/filters/TokenSearchInput.tsx, components/metrics/MetricPill.tsx (props)
  • CONTRIBUTING.md: document the convention.

No runtime behavior change: component output, props, and rendering are identical.

Verification

  • pnpm check passes; tsc --noEmit exits 0.
  • pnpm test: 188 files / 1901 tests pass, with the icon snapshots unchanged.
  • rg -U 'return;\s*\n\s*<' src returns nothing — the expression-body rewrites did not leave the unreachable return; <JSX> pattern (the icons/LogoIcon.tsx leading oxlint-disable comment is preserved inside the returned expression).
  • Added a throwaway arrow component and confirmed pnpm lint:check fails on it, then removed it and confirmed the check passes again.
  • That migration used the linter's own fixer for the arrow → declaration conversion (the : FC<Props> annotation was stripped first, since the fixer will not rewrite across an annotation), with tsc as the guard.

Notes

  • Visual regression baselines were not run locally: scripts/visual.sh requires the pinned Playwright Docker image and refuses to run on the host. Relying on the Visual Regression CI job for that.

Enable oxlint's react/function-component-definition rule (named components as
function declarations; anonymous components stay arrow functions) and migrate
the renderer's component definitions from React.FC arrows to function
declarations, moving each prop type onto its parameter and pruning the FC
imports whose only use was the definition.

React.FC is retained where it types a component value (a prop or a return
type), which the rule does not govern.

No runtime behavior change: component output, props, and rendering are
identical. Verified with pnpm check (format, lint, types), pnpm test
(1901 tests, icon snapshots unchanged), and a lint probe confirming an arrow
component now fails the check.
@setchy
setchy requested a review from afonsojramos as a code owner October 14, 2026 12:32
@github-actions github-actions Bot added the refactor Refactoring of existing feature label Oct 14, 2026
@sonarqubecloud

Copy link
Copy Markdown

@setchy
setchy merged commit 26abebd into main Oct 15, 2026
19 checks passed
@setchy
setchy deleted the refactor/function-component-declarations branch October 15, 2026 16:44
@github-actions github-actions Bot added this to the Release 7.10.0 milestone Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring of existing feature

Development

Successfully merging this pull request may close these issues.

2 participants