Skip to content

fix(eslint): deactivate react/no-leaked-conditional-rendering rule #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025

Conversation

mheob
Copy link
Owner

@mheob mheob commented May 2, 2025

This fix temporarily resolves the following issue:

Error while loading rule 'react/no-leaked-conditional-rendering': You have used a rule which requires type information, but don't have parserOptions set to generate type information for this file. See https://typescript-eslint.io/getting-started/typed-linting for enabling linting with type information.

Summary by CodeRabbit

  • Bug Fixes
    • Disabled the ESLint rule for conditional rendering in React due to a temporary issue.
  • Refactor
    • Updated logging to use console.info for editor environment messages.
    • Adjusted internal configuration to include all TypeScript-related options in React settings.
  • Style
    • Allowed the use of console.info in addition to warn and error without triggering ESLint warnings.

@mheob mheob added bug Something isn't working eslint Belongs to ESLint config labels May 2, 2025
Copy link

height bot commented May 2, 2025

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

Copy link

changeset-bot bot commented May 2, 2025

🦋 Changeset detected

Latest commit: 59df482

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

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

Copy link

vercel bot commented May 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eslint-config ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 2, 2025 9:16am

Copy link

coderabbitai bot commented May 2, 2025

Walkthrough

This update to the @mheob/eslint-config package makes several targeted changes to ESLint rule configurations. The react/no-leaked-conditional-rendering rule is temporarily disabled due to a parser options issue, with a comment indicating this is a short-term measure. The no-console rule is modified to allow console.info in addition to warn and error. Logging for editor environment detection is changed from console.log to console.info. Additionally, TypeScript-related options are now included when applying the React ESLint configuration.

Changes

Files/Paths Change Summary
packages/eslint-config/src/configs/react.ts, .changeset/...md Disabled react/no-leaked-conditional-rendering rule with explanatory comment; added changeset for this update.
packages/eslint-config/src/configs/javascript.ts Allowed console.info in the no-console ESLint rule.
packages/eslint-config/src/factory.ts Changed editor detection log to console.info; spread TypeScript options into React config invocation.

Sequence Diagram(s)

sequenceDiagram
    participant Editor
    participant Factory
    participant ReactConfig

    Editor->>Factory: Initialize ESLint config
    Factory->>Factory: Detect editor environment
    Factory->>Factory: console.info("Running in editor, disabling some rules")
    Factory->>ReactConfig: Apply React config with ...typescriptOptions
    ReactConfig-->>Factory: Return configured rules
    Factory-->>Editor: Provide full ESLint config
Loading

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 2 workspace projects
Progress: resolved 0, reused 0, downloaded 1, added 0
/tmp/eslint/packages/eslint-config:
 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND  In packages/eslint-config: "@mheob/tsconfig@workspace:*" is in the dependencies but no package named "@mheob/tsconfig" is present in the workspace

This error happened while installing a direct dependency of /tmp/eslint/packages/eslint-config

Packages found in the workspace:

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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

sonarqubecloud bot commented May 2, 2025

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: 0

🧹 Nitpick comments (1)
packages/eslint-config/src/factory.ts (1)

183-185: TypeScript options now included in React configuration

The TypeScript options are now properly spread into the React configuration, which should help provide the necessary type information for type-aware rules. This is a step toward resolving the issue with the currently disabled react/no-leaked-conditional-rendering rule.

Once the parserOptions issue is resolved, consider re-enabling the react/no-leaked-conditional-rendering rule, as this spreading of TypeScript options may help provide the necessary type information.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 770aeff and 59df482.

📒 Files selected for processing (4)
  • .changeset/fluffy-emus-burn.md (1 hunks)
  • packages/eslint-config/src/configs/javascript.ts (1 hunks)
  • packages/eslint-config/src/configs/react.ts (1 hunks)
  • packages/eslint-config/src/factory.ts (2 hunks)
🔇 Additional comments (4)
.changeset/fluffy-emus-burn.md (1)

1-5: LGTM: Changeset captures the intent correctly

The changeset correctly documents that react/no-leaked-conditional-rendering rule is being temporarily disabled due to a parserOptions issue, with the intention to re-enable it once the issue is resolved.

packages/eslint-config/src/configs/react.ts (1)

172-172:

✅ Verification successful

Appropriate temporary solution with clear documentation

The rule react/no-leaked-conditional-rendering has been properly commented out with a clear comment explaining why it's disabled (parserOptions issue). This aligns with the changeset and PR objectives.


🌐 Web query:

What are the requirements for the ESLint rule "react/no-leaked-conditional-rendering" to work properly?

💡 Result:

The ESLint rule react/no-leaked-conditional-rendering (also known as no-leaked-conditional-rendering in ESLint React or jsx-no-leaked-render in eslint-plugin-react) is designed to prevent problematic leaked values from being rendered in React components. This rule helps developers avoid unexpected rendering behavior that can occur when using the && operator for conditional rendering.

Rule Purpose

The rule targets a common issue in React development where using the && operator for conditional rendering can lead to unwanted values being displayed or even application crashes[1][2]. For example, values like 0, NaN, or empty strings can "leak" into the rendered output when they're on the left side of an && expression[4].

In React Native, this issue is even more severe as rendering these leaked values can crash the application entirely[1][7].

Configuration Requirements

To use this rule effectively, you need to:

  1. Install the appropriate ESLint plugin:

    • Either eslint-plugin-react (where the rule is called jsx-no-leaked-render)
    • Or @eslint-react/eslint-plugin (where it's called no-leaked-conditional-rendering)[1][2]
  2. Configure the rule in your ESLint config:

    {
      "rules": {
        "react/jsx-no-leaked-render": ["error", { "validStrategies": ["ternary", "coerce"] }]
      }
    }

    Or for the ESLint React version:

    {
      "rules": {
        "no-leaked-conditional-rendering": "error"
      }
    }
  3. Understand the rule options:

    • The rule accepts a validStrategies option that can include "coerce", "ternary", or both (default is ["ternary", "coerce"])[2]
    • The order of strategies matters for autofix behavior, with the first one being used when fixing issues[2]

Valid Strategies

The rule supports two main strategies for preventing leaked renders:

  1. Coerce strategy: Transforms expressions by coercing values to booleans

    • Uses !!value or Boolean(value) to ensure boolean conversion
    • Example: {!!count && <Component />}[2][4]
  2. Ternary strategy: Uses ternary expressions instead of &&

    • Example: {count ? <Component /> : null}[2][4]

Examples of Issues Caught by the Rule

The rule will flag code like:

// Problematic code
const Component = ({ count, title }) => {
  return <div>{count && title}</div>
}

This is problematic because if count is 0 or NaN, it would render those values instead of nothing[2][4].

Recommended Fixes

Depending on your configuration, the rule will suggest:

  1. Using boolean coercion:

    const Component = ({ count, title }) => {
      return <div>{!!count && title}</div>
    }
  2. Using ternary operators:

    const Component = ({ count, title }) => {
      return <div>{count ? title : null}</div>
    }

With autofix enabled, the rule can automatically transform your code to follow these patterns[2][4].

Integration with TypeScript ESLint

While this rule isn't part of the TypeScript-ESLint ecosystem directly, there have been proposals to integrate similar functionality with TypeScript's type checking to make the rule even more powerful[7]. Some developers use this rule alongside TypeScript's strict-boolean-expressions rule for more comprehensive protection.

I hope this helps clarify how to use the no-leaked-conditional-rendering rule effectively in your React projects.

Citations:


Approved: Temporary disable of react/no-leaked-conditional-rendering is well-documented
The comment clearly explains that this rule is disabled due to parserOptions limitations. As a reminder, this rule requires:

  • Installing and enabling the correct plugin (eslint-plugin-react or @eslint-react/eslint-plugin)
  • Enabling JSX parsing via parserOptions.ecmaFeatures.jsx = true (or equivalent)
  • Configuring the rule (e.g. "react/jsx-no-leaked-render": ["warn", { validStrategies: ["ternary","coerce"] }])

Once the parserOptions issue is resolved, re-enable the rule with your preferred strategy settings.

packages/eslint-config/src/configs/javascript.ts (1)

57-57: Enhanced console logging configuration

The no-console rule has been updated to allow console.info in addition to the previously allowed warn and error methods. This change aligns with the use of console.info in the factory.ts file.

packages/eslint-config/src/factory.ts (1)

110-110: Logging updated to use console.info

Changed from console.log to console.info, which aligns with the updated ESLint rule configuration that now allows console.info.

@kodiakhq kodiakhq bot merged commit 660dd9d into main May 2, 2025
9 of 10 checks passed
@kodiakhq kodiakhq bot deleted the fix-parser-issue branch May 2, 2025 09:19
kodiakhq bot pushed a commit that referenced this pull request May 2, 2025
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @mheob/[email protected]

### Patch Changes

-   [#263](#263) ([@mheob](https://github.com/mheob)): deactivate `react/no-leaked-conditional-rendering` rule for now; should be added again after the `parserOptions` issue is done



## Summary by CodeRabbit

- **Chores**
  - Updated the changelog and version number for the ESLint configuration package.
  - Removed a changeset related to a temporary ESLint rule deactivation.


Co-authored-by: Alex Böhm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working eslint Belongs to ESLint config
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant