Duplicate Function/Class Declaration
ID |
javascript.duplicate_name |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
JavaScript |
Tags |
code-style, dead-code |
Description
Reports the second and subsequent declarations of a function or class with the same name in the same function (or module) scope. JavaScript silently overrides the earlier declaration with the later one, so the earlier body becomes unreachable.
v1 covers function (regular, async, generator, async-generator) and class declarations. Methods and class fields are out of scope — duplicate methods are caught by the dedicated no_dupe_class_members rule.
Rationale
// Bad — the first `helper` is dead.
function helper(x) { return x + 1; }
function helper(x) { return x * 2; }
Remediation
Drop the duplicate, or rename one to reflect its actual purpose. When the duplication is the result of a refactor that merged two files, a search for the name often reveals the source of the conflict.