Binding Named With A Reserved Word
ID |
javascript.reserved_word_identifier |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
naming, reliability |
Description
Reports a binding whose name is one of the words ECMAScript reserves for future use: enum, implements, interface, package, private, protected, public, static, await and yield.
Sloppy-mode script code may still declare them, so the file parses and runs. Strict mode and every module reject them outright.
Only bindings are reported, never uses of the name. A property is always allowed to carry a reserved word, so an object key, a class member, a method name and a property access are all left alone, and a reference is reported at the declaration that has to be renamed rather than once per mention. In a destructuring pattern only the binding half is judged — { public: p } declares p and merely reads a property called public.
Rationale
// Bad
var package = readPackage();
function interface(spec) {
return spec;
}
const { public: visibility, private } = acl;
-
Nothing warns until the file is turned into a module, or a bundler adds a
"use strict"above it — and then the whole file stops parsing. -
The failure arrives as a build error with no relation to the change that caused it, in a file nobody touched.
-
Renaming the binding costs nothing today, and the names are reserved precisely because a future version of the language may take them.
Remediation
Rename the binding. The property names it reads may stay as they are.
// Good
var pkg = readPackage();
function describe(spec) {
return spec;
}
const { public: visibility, private: restricted } = acl;