Skip to content

eslint-factory: no-core-setoutput-non-string misses negative/unary numeric literals (e.g. -1, +5) #42680

Description

@github-actions

Summary

no-core-setoutput-non-string flags positive numeric literals (core.setOutput("count", 42)) but silently accepts negated/unary numeric literals such as -1 and +5. These carry the exact same implicit-coercion hazard the rule targets, so the omission is an inconsistency rather than an intentional scope boundary.

Evidence

nonStringKind() only inspects bare Literal nodes (no-core-setoutput-non-string.ts:17-22). -1 parses as a UnaryExpression (operator -, argument Literal 1), so nonStringKind returns null and the call is not flagged.

The rule's own test suite codifies this false negative as intended behavior:

// no-core-setoutput-non-string.test.ts:29 (inside the "valid" block)
`core.setOutput("count", -1);`

So core.setOutput("count", 42) is an error but core.setOutput("count", -1) is accepted — both coerce identically ("42", "-1").

Proposed refinement

In nonStringKind, unwrap a UnaryExpression whose operator is - or + (and, optionally, ~) over a numeric Literal argument and report it as a numeric literal. Keep the existing low-false-positive philosophy — only unwrap when the operand is a literal number, not an arbitrary expression.

Acceptance criteria

  • core.setOutput("count", -1) and core.setOutput("count", +5) are flagged as numeric literal.
  • The suggestion wraps correctly: core.setOutput("count", String(-1)).
  • The -1 case is moved from the valid block to an invalid block in no-core-setoutput-non-string.test.ts with the expected suggestion output.
  • Non-literal unary operands (e.g. -someVar) remain unflagged to preserve the low-FP contract.

Filed by ESLint Refiner (2026-07-01). First review of the no-core-setoutput-non-string rule; not a duplicate of open issues 42188-42190 / 42015-42017 / 41962-41963.

Generated by 🤖 ESLint Refiner · 216.1 AIC · ⌖ 12.1 AIC · ⊞ 4.7K ·

  • expires on Jul 7, 2026, 10:53 PM UTC-08:00

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions