jsx-eslint/eslint-plugin-react

jsx-no-leaked-render removes parentheses effecting formatting

Open

#3,357 创建于 2022年8月15日

在 GitHub 查看
 (6 评论) (1 反应) (0 负责人)JavaScript (8,630 star) (2,797 fork)batch import
bughelp wanted

描述

Hello I am trying to get the jsx-no-leaked-render to fix some code in my repo. When it runs its fix it is changing more code than necessary. In this case, it is removing parentheses around the conditionally rendered element. Although, not strictly necessary, the added parentheses are a convention we use in our codebase to keep formatting consistent, resulting in more clearly scoped conditional statements and components.

Although one could argue it doesn't matter for some people or its not a big deal, I think it's best that a rule not have any unintended effect on code structure other than what it is built to fix.

Note: This also happens when fixing strategy is set to coerce.

Before fixing

{item.validateResult && item.validateResult.error && (
  <ErrorWrapper>
    <ErrorIconContainer>
      <ErrorIcon name="info" size={40} />
    </ErrorIconContainer>
    <Text size="medium" $warning>
      {item.validateResult.error.message}
    </Text>
  </ErrorWrapper>
)}

After fixing

{item.validateResult && item.validateResult.error ? <ErrorWrapper>
    <ErrorIconContainer>
      <ErrorIcon name="info" size={40} />
    </ErrorIconContainer>
    <Text size="medium" $warning>
      {item.validateResult.error.message}
    </Text>
  </ErrorWrapper> : null}

贡献者指南