Skip to content

Commit f7f05d7

Browse files
committed
fix: add "no-prototype-builtins" eslint-rule and fix all occurences
1 parent 1988878 commit f7f05d7

File tree

8 files changed

+28
-32
lines changed

8 files changed

+28
-32
lines changed

Diff for: .eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module.exports = {
5757
"no-with": "error",
5858
"radix": "error",
5959
"wrap-iife": "error",
60+
"no-prototype-builtins": "error",
6061

6162

6263
// Variables //
@@ -114,4 +115,4 @@ module.exports = {
114115
"ecmaVersion": 6,
115116
"ecmaFeatures": {}
116117
}
117-
}
118+
};

Diff for: bench/util/benchwarmer.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ BenchWarmer.prototype = {
2929
});
3030
},
3131
push: function(name, fn) {
32-
if (this.names.indexOf(name) == -1) {
32+
if (this.names.indexOf(name) === -1) {
3333
this.names.push(name);
3434
}
3535

@@ -77,7 +77,7 @@ BenchWarmer.prototype = {
7777

7878
var errors = false, prop, bench;
7979
for (prop in self.errors) {
80-
if (self.errors.hasOwnProperty(prop)
80+
if (Object.prototype.hasOwnProperty.call(self, prop)
8181
&& self.errors[prop].error.message !== 'EWOT') {
8282
errors = true;
8383
break;
@@ -86,9 +86,8 @@ BenchWarmer.prototype = {
8686

8787
if (errors) {
8888
print('\n\nErrors:\n');
89-
for (prop in self.errors) {
90-
if (self.errors.hasOwnProperty(prop)
91-
&& self.errors[prop].error.message !== 'EWOT') {
89+
Object.keys(self.errors).forEach(function(prop) {
90+
if (self.errors[prop].error.message !== 'EWOT') {
9291
bench = self.errors[prop];
9392
print('\n' + bench.name + ':\n');
9493
print(bench.error.message);
@@ -97,7 +96,7 @@ BenchWarmer.prototype = {
9796
}
9897
print('\n');
9998
}
100-
}
99+
});
101100
}
102101

103102
callback();

Diff for: lib/handlebars/compiler/code-gen.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ CodeGen.prototype = {
125125
objectLiteral: function(obj) {
126126
let pairs = [];
127127

128-
for (let key in obj) {
129-
if (obj.hasOwnProperty(key)) {
130-
let value = castChunk(obj[key], this);
131-
if (value !== 'undefined') {
132-
pairs.push([this.quotedString(key), ':', value]);
133-
}
128+
Object.keys(obj).forEach(key => {
129+
let value = castChunk(obj[key], this);
130+
if (value !== 'undefined') {
131+
pairs.push([this.quotedString(key), ':', value]);
134132
}
135-
}
133+
});
136134

137135
let ret = this.generateList(pairs);
138136
ret.prepend('{');

Diff for: lib/handlebars/compiler/javascript-compiler.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ JavaScriptCompiler.prototype = {
218218
// aliases will not be used, but this case is already being run on the client and
219219
// we aren't concern about minimizing the template size.
220220
let aliasCount = 0;
221-
for (let alias in this.aliases) { // eslint-disable-line guard-for-in
221+
Object.keys(this.aliases).forEach(alias => {
222222
let node = this.aliases[alias];
223-
if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) {
223+
if (node.children && node.referenceCount > 1) {
224224
varDeclarations += ', alias' + (++aliasCount) + '=' + alias;
225225
node.children[0] = 'alias' + aliasCount;
226226
}
227-
}
227+
});
228228

229229
let params = ['container', 'depth0', 'helpers', 'partials', 'data'];
230230

Diff for: lib/handlebars/helpers/each.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,16 @@ export default function(instance) {
6262
} else {
6363
let priorKey;
6464

65-
for (let key in context) {
66-
if (context.hasOwnProperty(key)) {
67-
// We're running the iterations one step out of sync so we can detect
68-
// the last iteration without have to scan the object twice and create
69-
// an itermediate keys array.
70-
if (priorKey !== undefined) {
71-
execIteration(priorKey, i - 1);
72-
}
73-
priorKey = key;
74-
i++;
65+
Object.keys(context).forEach(key => {
66+
// We're running the iterations one step out of sync so we can detect
67+
// the last iteration without have to scan the object twice and create
68+
// an itermediate keys array.
69+
if (priorKey !== undefined) {
70+
execIteration(priorKey, i - 1);
7571
}
76-
}
72+
priorKey = key;
73+
i++;
74+
});
7775
if (priorKey !== undefined) {
7876
execIteration(priorKey, i - 1, true);
7977
}

Diff for: lib/handlebars/helpers/lookup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function(instance) {
55
if (!obj) {
66
return obj;
77
}
8-
if (dangerousPropertyRegex.test(String(field)) && !obj.propertyIsEnumerable(field)) {
8+
if (dangerousPropertyRegex.test(String(field)) && !Object.prototype.propertyIsEnumerable.call(obj, field)) {
99
return undefined;
1010
}
1111
return obj[field];

Diff for: spec/compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('compiler', function() {
5959
Handlebars.compile(' \n {{#if}}\n{{/def}}')();
6060
equal(true, false, 'Statement must throw exception. This line should not be executed.');
6161
} catch (err) {
62-
equal(err.propertyIsEnumerable('column'), true, 'Checking error column');
62+
equal(Object.prototype.propertyIsEnumerable.call(err, 'column'), true, 'Checking error column');
6363
}
6464
});
6565

Diff for: spec/regressions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ describe('Regressions', function() {
211211
// It's valid to execute a block against an undefined context, but
212212
// helpers can not do so, so we expect to have an empty object here;
213213
for (var name in this) {
214-
if (this.hasOwnProperty(name)) {
214+
if (Object.prototype.hasOwnProperty.call(this, name)) {
215215
return 'found';
216216
}
217217
}
218218
// And to make IE happy, check for the known string as length is not enumerated.
219-
return (this == 'bat' ? 'found' : 'not');
219+
return (this === 'bat' ? 'found' : 'not');
220220
}
221221
};
222222

0 commit comments

Comments
 (0)