Skip to content
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

💅 useJsxKeyInIterable: Not working when component starts on the next line #2011

Closed
1 task done
kevinwolfcr opened this issue Mar 9, 2024 · 14 comments · Fixed by #2016
Closed
1 task done

💅 useJsxKeyInIterable: Not working when component starts on the next line #2011

kevinwolfcr opened this issue Mar 9, 2024 · 14 comments · Fixed by #2016
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@kevinwolfcr
Copy link
Contributor

Environment information

CLI:
  Version:                      1.6.0
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.10.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.0.30"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Linter:
  Recommended:                  false
  All:                          true
  Rules:                        nursery/all = true
                                nursery/useSortedClasses = {"level":"error","options":{"attributes":["class","className","className","classList"],"functions":["clsx","cva","tw","cn"]}}
                                style/all = true
                                style/noImplicitBoolean = "off"
                                style/useBlockStatements = "off"
                                style/useNamingConvention = "off"

Workspace:
  Open Documents:               0

Rule name

useJsxKeyInIterable

Playground link

https://biomejs.dev/playground/?lintRules=all&code=YwBvAG4AcwB0ACAAZgByAHUAaQB0AHMAIAA9ACAAWwAiAEEAcABwAGwAZQAiACwAIAAiAEIAYQBuAGEAbgBhACIALAAgACIATwByAGEAbgBnAGUAIgBdADsACgAKAGUAeABwAG8AcgB0ACAAZgB1AG4AYwB0AGkAbwBuACAARgBvAG8AZAAoACkAIAB7AAoAIAAgAHIAZQB0AHUAcgBuACAAKAAKACAAIAAgACAAPABkAGkAdgA%2BAAoAIAAgACAAIAAgACAAPABoADEAPgBGAG8AbwBkADwALwBoADEAPgAKACAAIAAgACAAIAAgADwAdQBsAD4ACgAgACAAIAAgACAAIAAgACAAewBmAHIAdQBpAHQAcwAuAG0AYQBwACgAKABmAHIAdQBpAHQAKQAgAD0APgAgACgACgAgACAAIAAgACAAIAAgACAAIAAgADwAbABpACAAawBlAHkAPQB7AGYAcgB1AGkAdAB9AD4AewBmAHIAdQBpAHQAfQA8AC8AbABpAD4ACgAgACAAIAAgACAAIAAgACAAKQApAH0ACgAgACAAIAAgACAAIAA8AC8AdQBsAD4ACgAgACAAIAAgADwALwBkAGkAdgA%2BAAoAIAAgACkAOwAKAH0ACgA%3D

Expected result

On the attached playground, the following reports Cannot determine whether this child has the required key prop.. However, if I place the JSX on the same line as the map, it doesn't report.

This reports:

const fruits = ["Apple", "Banana", "Orange"];

export function Food() {
  return (
    <div>
      <h1>Food</h1>
      <ul>
        {fruits.map((fruit) => (
          <li key={fruit}>{fruit}</li>
        ))}
      </ul>
    </div>
  );
}

This doesn't:

const fruits = ["Apple", "Banana", "Orange"];

export function Food() {
  return (
    <div>
      <h1>Food</h1>
      <ul>
        {fruits.map((fruit) => <li key={fruit}>{fruit}</li>)}
      </ul>
    </div>
  );
}

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@hilja
Copy link

hilja commented Mar 9, 2024

Can confirm. v1.6.0.

@Sec-ant
Copy link
Member

Sec-ant commented Mar 9, 2024

I have been learning Rust recently and want to get my feet wet. Can I give this a try? @ematipico

@Conaclos
Copy link
Member

Conaclos commented Mar 9, 2024

@Sec-ant All yours :)

@togami2864 togami2864 added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Mar 9, 2024
@hilja
Copy link

hilja commented Mar 12, 2024

@Sec-ant This seems to be still happening. Is it meant to work when a component spans multiple lines? All the examples are one-liners.

Screenshot 2024-03-12 at 19 46 41

@Sec-ant
Copy link
Member

Sec-ant commented Mar 13, 2024

@Sec-ant This seems to be still happening. Is it meant to work when a component spans multiple lines? All the examples are one-liners.

Would you mind providing the problematic code snippet?

@hilja
Copy link

hilja commented Mar 13, 2024

@Sec-ant Managed to narrow it down. It breaks if you have a return inside the map:

const testArr = [
  { id: 1, name: 'test' },
  { id: 2, name: 'test2' },
  { id: 3, name: 'test3' },
  { id: 4, name: 'test4' },
]

export function TestFoo() {
  return (
    <div>
      <h1>Hello from Foo</h1>
      <ul>
        {testArr.map(item => {
          const { id, name } = item

          // Breaks useJsxKeyInIterable
          return (
            <li key={id}>
              <p>{name}</p>
            </li>
          )
        })}
      </ul>
    </div>
  )
}

@Sec-ant
Copy link
Member

Sec-ant commented Mar 13, 2024

@hilja It should be fixed in #2076.

@kevinwolfcr
Copy link
Contributor Author

@Sec-ant you rock!

@sahithyandev

This comment was marked as outdated.

@Sec-ant

This comment was marked as outdated.

@sahithyandev

This comment was marked as outdated.

@scallaway

This comment was marked as off-topic.

@Sec-ant

This comment was marked as off-topic.

@scallaway

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants