Skip to content

Commit 0f79aa3

Browse files
committed
[Fix] Never call Object prototype builtins directly.
See #955.
1 parent 5efd392 commit 0f79aa3

23 files changed

+59
-34
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
"max-len": [2, 120],
153153
"max-params": 0,
154154
"max-statements": 0,
155-
"no-plusplus": 0
155+
"no-plusplus": 0,
156+
"no-prototype-builtins": 2
156157
}
157158
}

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var has = require('has');
4+
35
var allRules = {
46
'jsx-uses-react': require('./lib/rules/jsx-uses-react'),
57
'no-multi-comp': require('./lib/rules/no-multi-comp'),
@@ -64,7 +66,7 @@ var allRules = {
6466
function filterRules(rules, predicate) {
6567
var result = {};
6668
for (var key in rules) {
67-
if (rules.hasOwnProperty(key) && predicate(rules[key])) {
69+
if (has(rules, key) && predicate(rules[key])) {
6870
result[key] = rules[key];
6971
}
7072
}
@@ -74,7 +76,7 @@ function filterRules(rules, predicate) {
7476
function configureAsError(rules) {
7577
var result = {};
7678
for (var key in rules) {
77-
if (!rules.hasOwnProperty(key)) {
79+
if (!has(rules, key)) {
7880
continue;
7981
}
8082
result['react/' + key] = 2;

lib/rules/display-name.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var Components = require('../util/Components');
89

910
// ------------------------------------------------------------------------------
@@ -223,7 +224,7 @@ module.exports = {
223224
var list = components.list();
224225
// Report missing display name for all components
225226
for (var component in list) {
226-
if (!list.hasOwnProperty(component) || list[component].hasDisplayName) {
227+
if (!has(list, component) || list[component].hasDisplayName) {
227228
continue;
228229
}
229230
reportMissingDisplayName(list[component]);

lib/rules/jsx-closing-bracket-location.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
8+
79
// ------------------------------------------------------------------------------
810
// Rule Definition
911
// ------------------------------------------------------------------------------
@@ -70,16 +72,16 @@ module.exports = {
7072
options.selfClosing = config;
7173
} else if (typeof config === 'object') {
7274
// [1, {location: 'something'}] (back-compat)
73-
if (config.hasOwnProperty('location')) {
75+
if (has(config, 'location')) {
7476
options.nonEmpty = config.location;
7577
options.selfClosing = config.location;
7678
}
7779
// [1, {nonEmpty: 'something'}]
78-
if (config.hasOwnProperty('nonEmpty')) {
80+
if (has(config, 'nonEmpty')) {
7981
options.nonEmpty = config.nonEmpty;
8082
}
8183
// [1, {selfClosing: 'something'}]
82-
if (config.hasOwnProperty('selfClosing')) {
84+
if (has(config, 'selfClosing')) {
8385
options.selfClosing = config.selfClosing;
8486
}
8587
}

lib/rules/jsx-max-props-per-line.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
'use strict';
77

8+
var has = require('has');
9+
810
// ------------------------------------------------------------------------------
911
// Rule Definition
1012
// ------------------------------------------------------------------------------
@@ -55,7 +57,7 @@ module.exports = {
5557
});
5658

5759
for (var line in props) {
58-
if (!props.hasOwnProperty(line)) {
60+
if (!has(props, line)) {
5961
continue;
6062
}
6163
if (props[line].length > maximum) {

lib/rules/jsx-no-duplicate-props.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
'use strict';
77

8+
var has = require('has');
9+
810
// ------------------------------------------------------------------------------
911
// Rule Definition
1012
// ------------------------------------------------------------------------------
@@ -48,7 +50,7 @@ module.exports = {
4850
name = name.toLowerCase();
4951
}
5052

51-
if (props.hasOwnProperty(name)) {
53+
if (has(props, name)) {
5254
context.report({
5355
node: decl,
5456
message: 'No duplicate props allowed'

lib/rules/jsx-tag-spacing.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');
89

910
// ------------------------------------------------------------------------------
@@ -204,11 +205,9 @@ module.exports = {
204205
beforeSelfClosing: 'always',
205206
afterOpening: 'never'
206207
};
207-
if (context.options[0]) {
208-
for (var key in options) {
209-
if (options.hasOwnProperty(key) && context.options[0].hasOwnProperty(key)) {
210-
options[key] = context.options[0][key];
211-
}
208+
for (var key in options) {
209+
if (has(options, key) && has(context.options[0] || {}, key)) {
210+
options[key] = context.options[0][key];
212211
}
213212
}
214213

lib/rules/jsx-wrap-multilines.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
8+
79
// ------------------------------------------------------------------------------
810
// Constants
911
// ------------------------------------------------------------------------------
@@ -79,7 +81,7 @@ module.exports = {
7981

8082
function isEnabled(type) {
8183
var userOptions = context.options[0] || {};
82-
if (({}).hasOwnProperty.call(userOptions, type)) {
84+
if (has(userOptions, type)) {
8385
return userOptions[type];
8486
}
8587
return DEFAULTS[type];

lib/rules/no-array-index-key.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
8+
79
// ------------------------------------------------------------------------------
810
// Rule Definition
911
// ------------------------------------------------------------------------------
@@ -50,7 +52,7 @@ module.exports = {
5052
if (callee.property.type !== 'Identifier') {
5153
return null;
5254
}
53-
if (!iteratorFunctionsToIndexParamPosition.hasOwnProperty(callee.property.name)) {
55+
if (!has(iteratorFunctionsToIndexParamPosition, callee.property.name)) {
5456
return null;
5557
}
5658

lib/rules/no-direct-mutation-state.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var Components = require('../util/Components');
89

910
// ------------------------------------------------------------------------------
@@ -76,7 +77,7 @@ module.exports = {
7677
'Program:exit': function() {
7778
var list = components.list();
7879
for (var component in list) {
79-
if (!list.hasOwnProperty(component) || isValid(list[component])) {
80+
if (!has(list, component) || isValid(list[component])) {
8081
continue;
8182
}
8283
reportMutations(list[component]);

lib/rules/no-multi-comp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var Components = require('../util/Components');
89

910
// ------------------------------------------------------------------------------
@@ -60,7 +61,7 @@ module.exports = {
6061
var i = 0;
6162

6263
for (var component in list) {
63-
if (!list.hasOwnProperty(component) || isIgnored(list[component]) || ++i === 1) {
64+
if (!has(list, component) || isIgnored(list[component]) || ++i === 1) {
6465
continue;
6566
}
6667
context.report({

lib/rules/no-set-state.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var Components = require('../util/Components');
89

910
// ------------------------------------------------------------------------------
@@ -73,7 +74,7 @@ module.exports = {
7374
'Program:exit': function() {
7475
var list = components.list();
7576
for (var component in list) {
76-
if (!list.hasOwnProperty(component) || isValid(list[component])) {
77+
if (!has(list, component) || isValid(list[component])) {
7778
continue;
7879
}
7980
reportSetStateUsages(list[component]);

lib/rules/no-unused-prop-types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// As for exceptions for props.children or props.className (and alike) look at
88
// https://github.com/yannickcr/eslint-plugin-react/issues/7
99

10+
var has = require('has');
1011
var Components = require('../util/Components');
1112
var variable = require('../util/variable');
1213
var annotations = require('../util/annotations');
@@ -916,7 +917,7 @@ module.exports = {
916917
var list = components.list();
917918
// Report undeclared proptypes for all classes
918919
for (var component in list) {
919-
if (!list.hasOwnProperty(component) || !mustBeValidated(list[component])) {
920+
if (!has(list, component) || !mustBeValidated(list[component])) {
920921
continue;
921922
}
922923
reportUnusedPropTypes(list[component]);

lib/rules/prefer-stateless-function.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
'use strict';
88

9+
var has = require('has');
910
var Components = require('../util/Components');
1011
var versionUtil = require('../util/version');
1112

@@ -371,7 +372,7 @@ module.exports = {
371372
var list = components.list();
372373
for (var component in list) {
373374
if (
374-
!list.hasOwnProperty(component) ||
375+
!has(list, component) ||
375376
hasOtherProperties(list[component].node) ||
376377
list[component].useThis ||
377378
list[component].useRef ||

lib/rules/prop-types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// As for exceptions for props.children or props.className (and alike) look at
88
// https://github.com/yannickcr/eslint-plugin-react/issues/7
99

10+
var has = require('has');
1011
var Components = require('../util/Components');
1112
var variable = require('../util/variable');
1213
var annotations = require('../util/annotations');
@@ -925,7 +926,7 @@ module.exports = {
925926
var list = components.list();
926927
// Report undeclared proptypes for all classes
927928
for (var component in list) {
928-
if (!list.hasOwnProperty(component) || !mustBeValidated(list[component])) {
929+
if (!has(list, component) || !mustBeValidated(list[component])) {
929930
continue;
930931
}
931932
reportUndeclaredPropTypes(list[component]);

lib/rules/require-default-props.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var find = require('array.prototype.find');
89
var Components = require('../util/Components');
910
var variableUtil = require('../util/variable');
@@ -551,7 +552,7 @@ module.exports = {
551552
var list = components.list();
552553

553554
for (var component in list) {
554-
if (!list.hasOwnProperty(component)) {
555+
if (!has(list, component)) {
555556
continue;
556557
}
557558

lib/rules/require-optimization.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var Components = require('../util/Components');
89

910
module.exports = {
@@ -219,7 +220,7 @@ module.exports = {
219220

220221
// Report missing shouldComponentUpdate for all components
221222
for (var component in list) {
222-
if (!list.hasOwnProperty(component) || list[component].hasSCU) {
223+
if (!has(list, component) || list[component].hasSCU) {
223224
continue;
224225
}
225226
reportMissingOptimization(list[component]);

lib/rules/require-render-return.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var Components = require('../util/Components');
89

910
// ------------------------------------------------------------------------------
@@ -111,7 +112,7 @@ module.exports = {
111112
var list = components.list();
112113
for (var component in list) {
113114
if (
114-
!list.hasOwnProperty(component) ||
115+
!has(list, component) ||
115116
!hasRenderMethod(list[component].node) ||
116117
list[component].hasReturnStatement ||
117118
(!utils.isES5Component(list[component].node) && !utils.isES6Component(list[component].node))

lib/rules/sort-comp.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var has = require('has');
78
var util = require('util');
89

910
var Components = require('../util/Components');
@@ -24,7 +25,7 @@ function getMethodsOrder(defaultConfig, userConfig) {
2425
var entry;
2526
for (var i = 0, j = order.length; i < j; i++) {
2627
entry = order[i];
27-
if (groups.hasOwnProperty(entry)) {
28+
if (has(groups, entry)) {
2829
config = config.concat(groups[entry]);
2930
} else {
3031
config.push(entry);
@@ -236,7 +237,7 @@ module.exports = {
236237
*/
237238
function dedupeErrors() {
238239
for (var i in errors) {
239-
if (!errors.hasOwnProperty(i)) {
240+
if (!has(errors, i)) {
240241
continue;
241242
}
242243
var index = errors[i].closest.ref.index;
@@ -262,7 +263,7 @@ module.exports = {
262263
var indexA;
263264
var indexB;
264265
for (var i in errors) {
265-
if (!errors.hasOwnProperty(i)) {
266+
if (!has(errors, i)) {
266267
continue;
267268
}
268269

@@ -412,7 +413,7 @@ module.exports = {
412413
'Program:exit': function() {
413414
var list = components.list();
414415
for (var component in list) {
415-
if (!list.hasOwnProperty(component)) {
416+
if (!has(list, component)) {
416417
continue;
417418
}
418419
var properties = getComponentProperties(list[component].node);

0 commit comments

Comments
 (0)