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

💅 Incorrect Linting Suggestion for useLiteralKeys with __proto__ as Computed Property #2430

Closed
1 task done
vickaita opened this issue Apr 13, 2024 · 3 comments · Fixed by #2441
Closed
1 task done
Assignees
Labels
A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@vickaita
Copy link

vickaita commented Apr 13, 2024

Environment information

CLI:
  Version:                      1.6.3
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.9.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.1.0"

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

Linter:
  Recommended:                  true
  All:                          false
  Rules:                        correctness/noUnusedImports = "error"
                                correctness/useHookAtTopLevel = "error"
                                style/noInferrableTypes = "off"
                                style/useForOf = "error"
                                style/useImportType = "off"
                                suspicious/noArrayIndexKey = "off"

Workspace:
  Open Documents:               0

Rule name

lint/complexity/useLiteralKeys

Playground link

https://biomejs.dev/playground/?code=YwBvAG4AcwB0ACAAbwBiAGoAIAA9ACAAewBbACIAXwBfAHAAcgBvAHQAbwBfAF8AIgBdADoAIAB0AHIAdQBlAH0AOwA%3D

Expected result

The useLiteralKeys rule suggests that object literals with computed properties such as {["__proto__"]: true} can be simplified to {__proto__: true}. However, this suggestion is incorrect due to the different ways JavaScript handles these syntaxes. In JavaScript, {["__proto__"]: true} does not modify the object's prototype, whereas {__proto__: true} does, potentially leading to unexpected behavior.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico ematipico added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug labels Apr 13, 2024
@ematipico
Copy link
Member

Thank you JavaScript 😞

@Conaclos
Copy link
Member

Conaclos commented Apr 13, 2024

__proto__ is a deprecated feature.
However, I accept that we could ignore this because this has security implications.
We should surely implement a noProtoProperty rule.

By the way, why do you want to use a such name as property?

@vickaita
Copy link
Author

vickaita commented Apr 13, 2024

@Conaclos I was implementing a clone function and this came up as an edge case. I wouldn't normally use __proto__ as a property name, but I needed it in a unit test for the edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants