fix: add "no-prototype-builtins" eslint-rule and fix all occurences

This commit is contained in:
Nils Knappmeier
2019-11-18 04:14:54 +01:00
committed by Nils Knappmeier
parent 1988878087
commit f7f05d7558
8 changed files with 28 additions and 32 deletions
+2 -1
View File
@@ -57,6 +57,7 @@ module.exports = {
"no-with": "error", "no-with": "error",
"radix": "error", "radix": "error",
"wrap-iife": "error", "wrap-iife": "error",
"no-prototype-builtins": "error",
// Variables // // Variables //
@@ -114,4 +115,4 @@ module.exports = {
"ecmaVersion": 6, "ecmaVersion": 6,
"ecmaFeatures": {} "ecmaFeatures": {}
} }
} };
+5 -6
View File
@@ -29,7 +29,7 @@ BenchWarmer.prototype = {
}); });
}, },
push: function(name, fn) { push: function(name, fn) {
if (this.names.indexOf(name) == -1) { if (this.names.indexOf(name) === -1) {
this.names.push(name); this.names.push(name);
} }
@@ -77,7 +77,7 @@ BenchWarmer.prototype = {
var errors = false, prop, bench; var errors = false, prop, bench;
for (prop in self.errors) { for (prop in self.errors) {
if (self.errors.hasOwnProperty(prop) if (Object.prototype.hasOwnProperty.call(self, prop)
&& self.errors[prop].error.message !== 'EWOT') { && self.errors[prop].error.message !== 'EWOT') {
errors = true; errors = true;
break; break;
@@ -86,9 +86,8 @@ BenchWarmer.prototype = {
if (errors) { if (errors) {
print('\n\nErrors:\n'); print('\n\nErrors:\n');
for (prop in self.errors) { Object.keys(self.errors).forEach(function(prop) {
if (self.errors.hasOwnProperty(prop) if (self.errors[prop].error.message !== 'EWOT') {
&& self.errors[prop].error.message !== 'EWOT') {
bench = self.errors[prop]; bench = self.errors[prop];
print('\n' + bench.name + ':\n'); print('\n' + bench.name + ':\n');
print(bench.error.message); print(bench.error.message);
@@ -97,7 +96,7 @@ BenchWarmer.prototype = {
} }
print('\n'); print('\n');
} }
} });
} }
callback(); callback();
+5 -7
View File
@@ -125,14 +125,12 @@ CodeGen.prototype = {
objectLiteral: function(obj) { objectLiteral: function(obj) {
let pairs = []; let pairs = [];
for (let key in obj) { Object.keys(obj).forEach(key => {
if (obj.hasOwnProperty(key)) { let value = castChunk(obj[key], this);
let value = castChunk(obj[key], this); if (value !== 'undefined') {
if (value !== 'undefined') { pairs.push([this.quotedString(key), ':', value]);
pairs.push([this.quotedString(key), ':', value]);
}
} }
} });
let ret = this.generateList(pairs); let ret = this.generateList(pairs);
ret.prepend('{'); ret.prepend('{');
@@ -218,13 +218,13 @@ JavaScriptCompiler.prototype = {
// aliases will not be used, but this case is already being run on the client and // aliases will not be used, but this case is already being run on the client and
// we aren't concern about minimizing the template size. // we aren't concern about minimizing the template size.
let aliasCount = 0; let aliasCount = 0;
for (let alias in this.aliases) { // eslint-disable-line guard-for-in Object.keys(this.aliases).forEach(alias => {
let node = this.aliases[alias]; let node = this.aliases[alias];
if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) { if (node.children && node.referenceCount > 1) {
varDeclarations += ', alias' + (++aliasCount) + '=' + alias; varDeclarations += ', alias' + (++aliasCount) + '=' + alias;
node.children[0] = 'alias' + aliasCount; node.children[0] = 'alias' + aliasCount;
} }
} });
let params = ['container', 'depth0', 'helpers', 'partials', 'data']; let params = ['container', 'depth0', 'helpers', 'partials', 'data'];
+9 -11
View File
@@ -62,18 +62,16 @@ export default function(instance) {
} else { } else {
let priorKey; let priorKey;
for (let key in context) { Object.keys(context).forEach(key => {
if (context.hasOwnProperty(key)) { // We're running the iterations one step out of sync so we can detect
// We're running the iterations one step out of sync so we can detect // the last iteration without have to scan the object twice and create
// the last iteration without have to scan the object twice and create // an itermediate keys array.
// an itermediate keys array. if (priorKey !== undefined) {
if (priorKey !== undefined) { execIteration(priorKey, i - 1);
execIteration(priorKey, i - 1);
}
priorKey = key;
i++;
} }
} priorKey = key;
i++;
});
if (priorKey !== undefined) { if (priorKey !== undefined) {
execIteration(priorKey, i - 1, true); execIteration(priorKey, i - 1, true);
} }
+1 -1
View File
@@ -5,7 +5,7 @@ export default function(instance) {
if (!obj) { if (!obj) {
return obj; return obj;
} }
if (dangerousPropertyRegex.test(String(field)) && !obj.propertyIsEnumerable(field)) { if (dangerousPropertyRegex.test(String(field)) && !Object.prototype.propertyIsEnumerable.call(obj, field)) {
return undefined; return undefined;
} }
return obj[field]; return obj[field];
+1 -1
View File
@@ -59,7 +59,7 @@ describe('compiler', function() {
Handlebars.compile(' \n {{#if}}\n{{/def}}')(); Handlebars.compile(' \n {{#if}}\n{{/def}}')();
equal(true, false, 'Statement must throw exception. This line should not be executed.'); equal(true, false, 'Statement must throw exception. This line should not be executed.');
} catch (err) { } catch (err) {
equal(err.propertyIsEnumerable('column'), true, 'Checking error column'); equal(Object.prototype.propertyIsEnumerable.call(err, 'column'), true, 'Checking error column');
} }
}); });
+2 -2
View File
@@ -211,12 +211,12 @@ describe('Regressions', function() {
// It's valid to execute a block against an undefined context, but // It's valid to execute a block against an undefined context, but
// helpers can not do so, so we expect to have an empty object here; // helpers can not do so, so we expect to have an empty object here;
for (var name in this) { for (var name in this) {
if (this.hasOwnProperty(name)) { if (Object.prototype.hasOwnProperty.call(this, name)) {
return 'found'; return 'found';
} }
} }
// And to make IE happy, check for the known string as length is not enumerated. // And to make IE happy, check for the known string as length is not enumerated.
return (this == 'bat' ? 'found' : 'not'); return (this === 'bat' ? 'found' : 'not');
} }
}; };