Skip to content

Commit f41b4df

Browse files
committed
[eslint config] [base] [breaking] enable no-prototype-builtins rule.
1 parent 4700d99 commit f41b4df

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ Other Style Guides
288288
};
289289
```
290290
291-
<a name="objects-quoted-props"></a><a name="3.8"></a>
292-
- [3.8](#objects-quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects)
291+
<a name="objects--quoted-props"></a><a name="3.8"></a>
292+
- [3.8](#objects--quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects)
293293
294294
> Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.
295295
@@ -309,6 +309,26 @@ Other Style Guides
309309
};
310310
```
311311
312+
<a name="objects--prototype-builtins"></a>
313+
- [3.9](#objects--prototype-builtins) Do not call `Object.prototype` methods directly, such as `hasOwnProperty`, `propertyIsEnumerable`, and `isPrototypeOf`.
314+
315+
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`).
316+
317+
```javascript
318+
// bad
319+
console.log(object.hasOwnProperty(key));
320+
321+
// good
322+
console.log(Object.prototype.hasOwnProperty.call(object, key));
323+
324+
// best
325+
const has = Object.prototype.hasOwnProperty; // cache the lookup once, in module scope.
326+
/* or */
327+
const has = require('has');
328+
329+
console.log(has.call(object, key));
330+
```
331+
312332
**[⬆ back to top](#table-of-contents)**
313333
314334
## Arrays
@@ -2506,18 +2526,18 @@ Other Style Guides
25062526
get age() {
25072527
// ...
25082528
}
2509-
2529+
25102530
set age(value) {
25112531
// ...
25122532
}
25132533
}
2514-
2534+
25152535
// good
25162536
class Dragon {
25172537
getAge() {
25182538
// ...
25192539
}
2520-
2540+
25212541
setAge(value) {
25222542
// ...
25232543
}

packages/eslint-config-airbnb-base/rules/errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ module.exports = {
6868
// disallow the use of object properties of the global object (Math and JSON) as functions
6969
'no-obj-calls': 2,
7070

71+
// disallow use of Object.prototypes builtins directly
72+
// http://eslint.org/docs/rules/no-prototype-builtins
73+
'no-prototype-builtins': 2,
74+
7175
// disallow multiple spaces in a regular expression literal
7276
'no-regex-spaces': 2,
7377

0 commit comments

Comments
 (0)