Literal Called As Function
ID |
javascript.literal_called_as_function |
Severity |
critical |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
reliability, runtime-error |
Description
Reports a call whose callee is a literal — a string, a number, a boolean, null, or a regular expression — optionally wrapped in parentheses. A literal is never callable, so the line throws a TypeError the first time it runs.
const value = "abc"(); // FLAW — TypeError: "abc" is not a function
const value = (42)(); // FLAW
const value = null(); // FLAW
The callee is read through the parentheses that may wrap it, and only a callee that directly holds a literal counts. A property or method of a literal ("abc".repeat(2)) is callable and ordinary, and the comma-sequence idiom (0, obj.fn)() calls its second operand rather than the literal, so neither is reported.
Rationale
-
The shape comes from an editing slip rather than a misunderstanding, which is why it survives to commit: a call’s parentheses left behind after the callee was replaced by a value, a missing operator between a number and a parenthesised group (
const area = 2(w + h)), or a semicolon dropped at the end of a line so a literal and the parenthesised expression under it merged into one call. -
Nothing about the line looks wrong at a glance — it reads as a call — and the error only surfaces when that path is exercised.