Skip to content

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Jun 4, 2025

Summary by CodeRabbit

  • Chores
    • Enabled React-specific linting rules to improve code quality and consistency.
    • Added ESLint directive comments to suppress select lint warnings in multiple components.
    • Updated formatting and spacing in some UI components for improved readability.
    • Improved React list rendering by using stable keys where applicable.

@JounQin JounQin self-assigned this Jun 4, 2025
Copilot AI review requested due to automatic review settings June 4, 2025 09:08
@changeset-bot
Copy link

changeset-bot bot commented Jun 4, 2025

🦋 Changeset detected

Latest commit: b8f9e27

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@alauda/doom 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

@coderabbitai
Copy link

coderabbitai bot commented Jun 4, 2025

Walkthrough

This update integrates the @eslint-react/eslint-plugin into the ESLint configuration and addresses its linting rules across the codebase. Changes include adding or updating ESLint directive comments in several React components to suppress specific lint warnings, and adjusting key usage in list rendering for improved React reconciliation.

Changes

Files/Groups Change Summary
.changeset/slow-readers-work.md Added a changeset documenting the ESLint React plugin integration and related fixes.
eslint.config.js Integrated @eslint-react/eslint-plugin and enabled its recommended configs for React and TypeScript files.
src/global/VersionsNav/index.tsx
src/runtime/components/K8sCrd.tsx
Added ESLint disable comments for direct state setting in useEffect hooks.
src/runtime/components/OpenAPIPath.tsx Added ESLint disable comment for array index key usage; adjusted JSX spacing and formatting in parameter list.
src/runtime/components/OpenAPIRef.tsx Changed React list key from array index to property name for stable reconciliation.
src/runtime/components/Tabs.tsx Added ESLint disable comments for Children.map and array index key usage in print mode rendering.
src/runtime/components/TermsTable.tsx Added ESLint disable comment for array index key usage in list rendering.
src/runtime/components/_HeadingTitle.tsx Added ESLint disable comment for Children.toArray usage.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant ESLint Config
    participant React Component
    Developer->>ESLint Config: Add @eslint-react/eslint-plugin
    ESLint Config->>React Component: Enforce React-specific lint rules
    React Component->>ESLint Config: Add disable comments/fix keys as needed
Loading

Possibly related PRs

  • alauda/doom#60: Also focuses on enabling @eslint-react/eslint-plugin and fixing related linting issues, including similar configuration and directive changes.

Poem

In fields of code where React does play,
A rabbit hops to lint away—
With plugins new and comments neat,
Each warning now admits defeat.
Keys are set, arrays aligned,
The code is clean, the rules refined!
🐇✨

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables the @eslint-react/eslint-plugin by updating the ESLint configuration and adding inline disable comments in several React component files to work around newly enforced rules.

  • Added inline ESLint disable comments for various React rules in multiple components.
  • Refactored the Tabs component to remove the forwardRef wrapper.
  • Updated eslint.config.js to include recommended React plugin configurations.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/runtime/components/_HeadingTitle.tsx Added disable comment for no-children-to-array rule.
src/runtime/components/TermsTable.tsx Added disable comment for no-array-index-key on list items.
src/runtime/components/Tabs.tsx Changed Tabs component by removing forwardRef and added eslint-disable comments for children mapping and key usage.
src/runtime/components/OpenAPIRef.tsx Updated list key from index to name in mapped items.
src/runtime/components/OpenAPIPath.tsx Added disable comment for no-array-index-key and adjusted required badge rendering.
src/runtime/components/K8sCrd.tsx Added disable comment for no-direct-set-state-in-use-effect in useEffect.
src/global/VersionsNav/index.tsx Added disable comment for no-direct-set-state-in-use-effect when updating navMenu.
eslint.config.js Imported and applied recommended configurations for the React ESLint plugin.
Comments suppressed due to low confidence (2)

src/runtime/components/Tabs.tsx:9

  • Removing forwardRef changes the component's ref forwarding behavior. If the component is expected to support ref forwarding, consider using React.forwardRef to maintain that contract.
export const Tabs = ({ ref, children, ...props }: TabsProps) => {

src/runtime/components/OpenAPIPath.tsx:57

  • [nitpick] Using an array index as a key in list items may cause rendering issues when the list is dynamic. Consider using a unique identifier if one is available.
<X.li key={index}>

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@alauda/doom@62

commit: b8f9e27

@JounQin
Copy link
Member Author

JounQin commented Jun 4, 2025

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jun 4, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/runtime/components/K8sCrd.tsx (1)

44-44: Consider refactoring instead of suppressing the ESLint rule.

This is similar to a previous concern raised about directly setting state in useEffect. While the current implementation may work, the pattern can lead to synchronization issues and performance problems.

Consider these alternatives:

  1. Remove local state and use expandAll prop directly
  2. Use a different pattern like useMemo or derived state
-const [open, setOpen] = useState(expandAll)
-
-const onToggle = useCallback((open: boolean) => {
-  setOpen(open)
-}, [])
-
-useEffect(() => {
-  // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
-  setOpen(expandAll)
-}, [expandAll])
+const [manualOverride, setManualOverride] = useState<boolean | null>(null)
+const open = manualOverride ?? expandAll
+
+const onToggle = useCallback((open: boolean) => {
+  setManualOverride(open)
+}, [])
🧹 Nitpick comments (3)
src/runtime/components/TermsTable.tsx (1)

23-24: Consider using string content as key instead of array index.

While the ESLint disable is acceptable for this static list, using the string content itself as the key would be more robust and align with React best practices.

-          // eslint-disable-next-line @eslint-react/no-array-index-key
-          <X.li key={index}>{item}</X.li>
+          <X.li key={item}>{item}</X.li>

This approach eliminates the need for the ESLint disable comment and provides better React reconciliation if the list order ever changes.

src/runtime/components/Tabs.tsx (1)

18-24: Consider improving the implementation rather than suppressing ESLint rules.

While these suppressions may work for print mode, they represent patterns that could be improved:

For the array index key issue, consider using a more stable identifier:

-        // eslint-disable-next-line @eslint-react/no-children-map
         Children.map(children, (child, index) => (
-          // eslint-disable-next-line @eslint-react/no-array-index-key
-          <Tabs_ key={index} {...props}>
+          <Tabs_ key={`print-tab-${index}`} {...props}>
             {child}
           </Tabs_>
         ))

Alternatively, if the children have stable identifiers, use those instead of array indices.

src/runtime/components/OpenAPIPath.tsx (1)

61-67: Replace explicit space fragments with CSS or non-breaking spaces
Inserting {' '} inside fragments for spacing is brittle. Consider using CSS margin/padding, non-breaking spaces (\u00A0), or template strings (" ") to handle inline spacing more cleanly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fc26c4 and b8f9e27.

📒 Files selected for processing (9)
  • .changeset/slow-readers-work.md (1 hunks)
  • eslint.config.js (2 hunks)
  • src/global/VersionsNav/index.tsx (1 hunks)
  • src/runtime/components/K8sCrd.tsx (1 hunks)
  • src/runtime/components/OpenAPIPath.tsx (1 hunks)
  • src/runtime/components/OpenAPIRef.tsx (1 hunks)
  • src/runtime/components/Tabs.tsx (1 hunks)
  • src/runtime/components/TermsTable.tsx (1 hunks)
  • src/runtime/components/_HeadingTitle.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/runtime/components/OpenAPIPath.tsx (1)
src/runtime/components/_Markdown.tsx (1)
  • Markdown (6-21)
🔇 Additional comments (5)
eslint.config.js (1)

4-4: LGTM! Proper React ESLint plugin integration.

The React ESLint plugin is correctly integrated following ESLint flat config best practices:

  • Clean import statement
  • Base configuration added to the main config array
  • Type-checked React rules appropriately scoped to TypeScript files

Also applies to: 17-17, 21-25

src/runtime/components/_HeadingTitle.tsx (1)

28-29: ESLint disable comment is appropriately justified.

The @eslint-react/no-children-to-array rule is correctly disabled here since Children.toArray() is being used for slug generation from heading content, not for rendering. This is a legitimate use case where converting children to an array is necessary for text extraction.

src/global/VersionsNav/index.tsx (1)

123-124:

Details

✅ Verification successful

Verify the useEffect logic to prevent potential infinite re-renders.

The ESLint disable comment is understandable given the DOM integration requirements, but the direct state setting in useEffect could be risky.

Please verify that this useEffect implementation doesn't cause infinite re-renders or performance issues:

The current implementation appears to have guards in place, but consider if a useCallback or useRef approach might be safer for DOM integration.


🏁 Script executed:

#!/bin/bash
# Description: Search for similar patterns and potential useEffect issues in the codebase
echo "Searching for other direct setState calls in useEffect..."
rg -A 3 -B 3 "useState.*setNavMenu|setNavMenu.*useState" 

echo -e "\nSearching for other mutation observer patterns..."
rg -A 5 -B 5 "MutationObserver.*useEffect|useEffect.*MutationObserver"

echo -e "\nSearching for similar DOM integration patterns..."
rg -A 3 -B 3 "getNavMenu|querySelector.*nav.*menu"

Length of output: 3362


Direct state update in useEffect is safe and won’t loop

I’ve verified that:

  • The useEffect only runs when siteData.base changes.
  • You compare newNavMenu against navMenu before calling setNavMenu, so it only updates once per actual DOM change.
  • The MutationObserver callback lives inside the same effect but only fires on DOM removals, not React updates.

Given these guards, the disable comment for @eslint-react/hooks-extra/no-direct-set-state-in-use-effect is justified here.

.changeset/slow-readers-work.md (1)

1-6: LGTM!

The changeset correctly documents the patch-level update for enabling the React ESLint plugin and fixing related linting issues.

src/runtime/components/OpenAPIRef.tsx (1)

109-110: Excellent improvement!

Great choice to use the property name as the key instead of the array index. This provides stable, unique keys that improve React's reconciliation performance and avoid potential rendering issues.

@JounQin JounQin merged commit 2d0357a into 0.x Jun 4, 2025
16 checks passed
@JounQin JounQin deleted the chore/eslint branch June 4, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants