Skip to content

eslint-factory: require-json-parse-try-catch misses indirect/computed JSON.parse access #41962

Description

@github-actions

Summary

The require-json-parse-try-catch rule (actions/setup/js/eslint-factory/src/rules/require-json-parse-try-catch.ts) only matches a CallExpression whose callee is a direct MemberExpression with object.name === "JSON" and a non-computed property.name === "parse". Any indirect reference to JSON.parse bypasses the rule entirely, so an unguarded parse can ship without a warning.

Missed patterns (false negatives)

  • Computed access: JSON["parse"](raw)property is a string Literal, not an Identifier, so the property.type !== "Identifier" guard returns early.
  • Aliased binding: const p = JSON.parse; p(raw).
  • Destructured binding: const { parse } = JSON; parse(raw).

A grep of actions/setup/js/*.cjs shows 0 current indirect usages, so this is preventive hardening rather than a live regression — but the gap means the rule silently under-reports the moment such code is introduced.

Acceptance criteria

  • Rule reports JSON["parse"](x) (computed member with a "parse" string-literal key) when not inside a protecting try block.
  • Decide and document handling of aliased/destructured bindings: implement scope-based tracking of JSON.parse aliases, OR explicitly document them as out of scope with a code comment and a follow-up note.
  • Add fixture/unit tests covering: computed access flagged; computed access inside try not flagged; (if implemented) aliased and destructured bindings.
  • No new false positives on the existing 107 JSON.parse call sites in actions/setup/js.

Notes

Keep the matcher precise: only treat a "parse" member of an object resolving to the global JSON as in scope; do not flag unrelated .parse members (e.g. path.parse, Number.parse*).

Generated by 🤖 ESLint Refiner · 142.2 AIC · ⌖ 11.9 AIC · ⊞ 4.7K ·

  • expires on Jul 4, 2026, 2:56 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions