no-prototype-builtins
NOTE: this rule is part of the
recommended rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-prototype-builtins"],
"exclude": ["no-prototype-builtins"]
}
}
}Disallows the use of Object.prototype builtins directly.
If objects are created via Object.create(null) they have no prototype
specified. This can lead to runtime errors when you assume objects have
properties from Object.prototype and attempt to call the following methods:
hasOwnPropertyisPrototypeOfpropertyIsEnumerable
Instead, it's always encouraged to call these methods from Object.prototype
explicitly.
Invalid:
const a = foo.hasOwnProperty("bar");
const b = foo.isPrototypeOf("bar");
const c = foo.propertyIsEnumerable("bar");
Valid:
const a = Object.prototype.hasOwnProperty.call(foo, "bar");
const b = Object.prototype.isPrototypeOf.call(foo, "bar");
const c = Object.prototype.propertyIsEnumerable.call(foo, "bar");