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]);

0 commit comments

Comments
 (0)