Merge pull request #627 from amplii/no-param-reassign-with-props

[eslint config] [breaking] update best-practices config to prevent parameter object manipulation
This commit is contained in:
Jordan Harband
2015-12-17 11:25:13 -08:00
2 changed files with 36 additions and 1 deletions

View File

@@ -629,6 +629,39 @@ Other Style Guides
const y = function a() {};
```
- [7.12](#7.12) <a name="7.12"></a> Never mutate parameters.
> Why? Overwriting parameters can lead to unexpected behavior, especially when accessing the `arguments` object. Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
eslint rules: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html).
```javascript
// bad
function f1(a) {
a = 1;
}
function f2(a) {
if (!a) { a = 1; }
}
function f3(obj) {
obj.key = 1;
};
// good
function f4(a) {
const b = a || 1;
}
function f5(a = 1) {
}
function f6(obj) {
const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1;
};
```
**[⬆ back to top](#table-of-contents)**
## Arrow Functions

View File

@@ -74,7 +74,9 @@ module.exports = {
// var foo = 'Copyright \251';
'no-octal-escape': 2,
// disallow reassignment of function parameters
'no-param-reassign': 2,
// disallow parameter object manipulation
// rule: http://eslint.org/docs/rules/no-param-reassign.html
'no-param-reassign': [2, { 'props': true }],
// disallow use of process.env
'no-process-env': 0,
// disallow usage of __proto__ property