chore(eslint): enable @eslint-react/use-state rule#1059
Open
carlosthe19916 wants to merge 3 commits into
Open
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnables the @eslint-react/use-state ESLint rule by removing its override and updating React useState usage patterns to use lazy initializers where computation or object construction occurs, while explicitly suppressing the rule for a deliberate tuple-based useState usage in usePersistentState. Sequence diagram for lazy useState initialization after enabling eslint-react-use-statesequenceDiagram
participant useSelectionState
participant React
participant doSelect
useSelectionState->>React: useState(() => doSelect(isEqual, items, initialSelected)
alt [initial render]
React->>doSelect: doSelect(isEqual, items, initialSelected)
doSelect-->>React: selected
React-->>useSelectionState: selectedSet, setSelectedSet
else [subsequent renders]
React-->>useSelectionState: selectedSet, setSelectedSet
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1059 +/- ##
==========================================
+ Coverage 53.04% 53.06% +0.02%
==========================================
Files 270 270
Lines 5884 5887 +3
Branches 1844 1844
==========================================
+ Hits 3121 3124 +3
Misses 2459 2459
Partials 304 304
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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>
f2e3c60 to
c6e0986
Compare
# Conflicts: # client/src/app/pages/home/watched-sboms-provider.tsx
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
usePersistentState, consider wrapping theReact.useState(defaultValue)tuple in a small helper (e.g.createPersistentState(defaultValue)) or a dedicated type alias so the intentional tuple shape is clearer and the eslint-disable comment is less surprising to future readers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `usePersistentState`, consider wrapping the `React.useState(defaultValue)` tuple in a small helper (e.g. `createPersistentState(defaultValue)`) or a dedicated type alias so the intentional tuple shape is clearer and the eslint-disable comment is less surprising to future readers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@eslint-react/use-stateoverride from ESLint config() => ...) foruseStatecalls that involve function calls or object construction to prevent re-computation on every renderusePersistentStateTest plan
npm run lintpasses 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:
Build: