diff --git a/README.md b/README.md index 95e24219..1d28ccd9 100644 --- a/README.md +++ b/README.md @@ -288,8 +288,8 @@ Other Style Guides }; ``` - - - [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) + + - [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) > Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines. @@ -309,6 +309,26 @@ Other Style Guides }; ``` + + - [3.9](#objects--prototype-builtins) Do not call `Object.prototype` methods directly, such as `hasOwnProperty`, `propertyIsEnumerable`, and `isPrototypeOf`. + + > 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)`). + + ```javascript + // bad + console.log(object.hasOwnProperty(key)); + + // good + console.log(Object.prototype.hasOwnProperty.call(object, key)); + + // best + const has = Object.prototype.hasOwnProperty; // cache the lookup once, in module scope. + /* or */ + const has = require('has'); + … + console.log(has.call(object, key)); + ``` + **[⬆ back to top](#table-of-contents)** ## Arrays @@ -2506,18 +2526,18 @@ Other Style Guides get age() { // ... } - + set age(value) { // ... } } - + // good class Dragon { getAge() { // ... } - + setAge(value) { // ... } diff --git a/packages/eslint-config-airbnb-base/rules/errors.js b/packages/eslint-config-airbnb-base/rules/errors.js index b8ee543c..9233f9f6 100644 --- a/packages/eslint-config-airbnb-base/rules/errors.js +++ b/packages/eslint-config-airbnb-base/rules/errors.js @@ -68,6 +68,10 @@ module.exports = { // disallow the use of object properties of the global object (Math and JSON) as functions 'no-obj-calls': 2, + // disallow use of Object.prototypes builtins directly + // http://eslint.org/docs/rules/no-prototype-builtins + 'no-prototype-builtins': 2, + // disallow multiple spaces in a regular expression literal 'no-regex-spaces': 2,