Skip to content

[feat] no-unnecessary-key should catch constant keys outside of map calls #1377

@bschlenk

Description

@bschlenk

Problem Description

It's a strange situation and I don't know why someone would write code this way, but I've ran into a few hardcoded string keys that are used outside of a map call. These are not eligible for the "Static keys used to re-mount components" exception the rule docs mention, since these keys are constant they would never trigger a re-mount.

It would be cool if this rule flagged constant keys like this since they meet the criteria for being unnecessary.

Alternative Solutions

I don't see any other rules in this project that would apply, although in my case the no-duplicate-keys rule did catch some that just happened to be duplicates but also strings.

Feature Details

This would just be an extension on top of the existing no-unnecessary-key rule and enabled by default.

Examples

<Menu.Root>
  <Menu.Option key="one">
    One
  </Menu.Option>
  <Menu.Option key="two">
    Two
  </Menu.Option>
</Menu.Root>

Both of these keys are unnecessary:

  • they are not used in a map call
  • they are constants so would never trigger a re-mount

Evaluation Checklist

  • I have had problems that this feature would solve
  • I could not find a way to solve the problem with existing features or workarounds
  • I have thought very hard about potential edge cases and downsides, and they are acceptable
  • I think the feature is well-defined and would provide clear value to users

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions