Skip to content

chore(eslint): enable @eslint-react/use-state rule#1059

Draft
carlosthe19916 wants to merge 4 commits into
guacsec:mainfrom
carlosthe19916:hotfix/enable-use-state
Draft

chore(eslint): enable @eslint-react/use-state rule#1059
carlosthe19916 wants to merge 4 commits into
guacsec:mainfrom
carlosthe19916:hotfix/enable-use-state

Conversation

@carlosthe19916
Copy link
Copy Markdown
Collaborator

@carlosthe19916 carlosthe19916 commented May 27, 2026

Summary

  • Remove the @eslint-react/use-state override from ESLint config
  • Use lazy initial state (() => ...) for useState calls that involve function calls or object construction to prevent re-computation on every render
  • Suppress rule for one intentional non-standard destructuring in usePersistentState

Test plan

  • npm run lint passes with 0 warnings

🤖 Generated with Claude Code

Summary by Sourcery

Enable the @eslint-react/use-state rule and update state initialization patterns to comply with it.

Enhancements:

  • Use lazy initializers for useState calls that perform computation or object construction to avoid unnecessary work on re-renders.
  • Annotate the intentional tuple-based useState usage in usePersistentState to document and suppress the lint rule in that spot.
  • Clean up ESLint configuration by removing the override that disabled @eslint-react/use-state.

Use lazy initial state for useState calls that involve function
calls or object construction to prevent re-computation on every render.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 27, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enables the @eslint-react/use-state rule by removing its override in ESLint config and updating React useState usages to follow the rule, primarily by switching to lazy initializers for expensive or non-primitive initial state and suppressing it once for an intentional tuple usage.

Sequence diagram for lazy React.useState initialization after ESLint rule enablement

sequenceDiagram
  participant React
  participant useSelectionState
  participant doSelect

  React->>useSelectionState: render component
  useSelectionState->>React: React.useState(() => doSelect(isEqual, items, initialSelected))
  React->>doSelect: doSelect(isEqual, items, initialSelected) [initial render]
  doSelect-->>React: selectedSet
  React-->>useSelectionState: [selectedSet, setSelectedSet]

  React->>useSelectionState: re-render component
  useSelectionState->>React: React.useState(() => doSelect(isEqual, items, initialSelected))
  React-->>useSelectionState: [selectedSet, setSelectedSet]  [initializer not re-executed]
Loading

File-Level Changes

Change Details Files
Switch useState initializers that perform work to lazy initial state functions to avoid recomputation on every render and satisfy @eslint-react/use-state.
  • Wrap doSelect(...) call in useSelectionState in a lazy initializer arrow function passed to React.useState.
  • Wrap getValueFromStorage(...) call in useStorage in a lazy initializer arrow function passed to React.useState.
  • Initialize mutatingKeys state in WatchedSbomsProvider with a lazy () => new Set() instead of constructing the Set eagerly.
  • Initialize expandedNodeIds state in SbomGroupsProvider with a lazy () => new Set() instead of constructing the Set eagerly.
client/src/app/hooks/useSelectionState.ts
client/src/app/hooks/useStorage.ts
client/src/app/pages/home/watched-sboms-provider.tsx
client/src/app/pages/sbom-groups/sbom-groups-provider.tsx
Explicitly document and suppress one intentional non-standard useState return value and enable the lint rule globally.
  • Add an inline eslint-disable comment for @eslint-react/use-state on the persistence.state tuple construction in usePersistentState to acknowledge and allow the pattern.
  • Remove the override that turned off @eslint-react/use-state from the ESLint config so the rule runs by default.
client/src/app/hooks/usePersistentState.ts
eslint.config.mjs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 50.69%. Comparing base (16a6bec) to head (f2e3c60).

Files with missing lines Patch % Lines
...ient/src/app/pages/home/watched-sboms-provider.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1059      +/-   ##
==========================================
+ Coverage   50.68%   50.69%   +0.01%     
==========================================
  Files         253      253              
  Lines        5499     5503       +4     
  Branches     1660     1660              
==========================================
+ Hits         2787     2790       +3     
- Misses       2440     2442       +2     
+ Partials      272      271       -1     
Flag Coverage Δ
e2e 68.94% <75.00%> (+<0.01%) ⬆️
unit 2.01% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@carlosthe19916 carlosthe19916 marked this pull request as draft May 27, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant