Skip to content

Commit

Permalink
fix: add "no-prototype-builtins" eslint-rule and fix all occurences
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Nov 18, 2019
1 parent 1988878 commit f7f05d7
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -57,6 +57,7 @@ module.exports = {
"no-with": "error",
"radix": "error",
"wrap-iife": "error",
"no-prototype-builtins": "error",


// Variables //
Expand Down Expand Up @@ -114,4 +115,4 @@ module.exports = {
"ecmaVersion": 6,
"ecmaFeatures": {}

This comment has been minimized.

Copy link
@anshuman35
}
}
};
11 changes: 5 additions & 6 deletions bench/util/benchwarmer.js
Expand Up @@ -29,7 +29,7 @@ BenchWarmer.prototype = {
});
},
push: function(name, fn) {
if (this.names.indexOf(name) == -1) {
if (this.names.indexOf(name) === -1) {
this.names.push(name);
}

Expand Down Expand Up @@ -77,7 +77,7 @@ BenchWarmer.prototype = {

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

if (errors) {
print('\n\nErrors:\n');
for (prop in self.errors) {
if (self.errors.hasOwnProperty(prop)
&& self.errors[prop].error.message !== 'EWOT') {
Object.keys(self.errors).forEach(function(prop) {
if (self.errors[prop].error.message !== 'EWOT') {
bench = self.errors[prop];
print('\n' + bench.name + ':\n');
print(bench.error.message);
Expand All @@ -97,7 +96,7 @@ BenchWarmer.prototype = {
}
print('\n');
}
}
});
}

callback();
Expand Down
12 changes: 5 additions & 7 deletions lib/handlebars/compiler/code-gen.js
Expand Up @@ -125,14 +125,12 @@ CodeGen.prototype = {
objectLiteral: function(obj) {
let pairs = [];

for (let key in obj) {
if (obj.hasOwnProperty(key)) {
let value = castChunk(obj[key], this);
if (value !== 'undefined') {
pairs.push([this.quotedString(key), ':', value]);
}
Object.keys(obj).forEach(key => {
let value = castChunk(obj[key], this);
if (value !== 'undefined') {
pairs.push([this.quotedString(key), ':', value]);
}
}
});

let ret = this.generateList(pairs);
ret.prepend('{');
Expand Down
6 changes: 3 additions & 3 deletions lib/handlebars/compiler/javascript-compiler.js
Expand Up @@ -218,13 +218,13 @@ JavaScriptCompiler.prototype = {
// 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.
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];
if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) {
if (node.children && node.referenceCount > 1) {
varDeclarations += ', alias' + (++aliasCount) + '=' + alias;
node.children[0] = 'alias' + aliasCount;
}
}
});

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

Expand Down
20 changes: 9 additions & 11 deletions lib/handlebars/helpers/each.js
Expand Up @@ -62,18 +62,16 @@ export default function(instance) {
} else {
let priorKey;

for (let key in context) {
if (context.hasOwnProperty(key)) {
// 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
// an itermediate keys array.
if (priorKey !== undefined) {
execIteration(priorKey, i - 1);
}
priorKey = key;
i++;
Object.keys(context).forEach(key => {
// 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
// an itermediate keys array.
if (priorKey !== undefined) {
execIteration(priorKey, i - 1);
}
}
priorKey = key;
i++;
});
if (priorKey !== undefined) {
execIteration(priorKey, i - 1, true);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/handlebars/helpers/lookup.js
Expand Up @@ -5,7 +5,7 @@ export default function(instance) {
if (!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 obj[field];
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler.js
Expand Up @@ -59,7 +59,7 @@ describe('compiler', function() {
Handlebars.compile(' \n {{#if}}\n{{/def}}')();
equal(true, false, 'Statement must throw exception. This line should not be executed.');
} catch (err) {
equal(err.propertyIsEnumerable('column'), true, 'Checking error column');
equal(Object.prototype.propertyIsEnumerable.call(err, 'column'), true, 'Checking error column');
}
});

Expand Down
4 changes: 2 additions & 2 deletions spec/regressions.js
Expand Up @@ -211,12 +211,12 @@ describe('Regressions', function() {
// 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;
for (var name in this) {
if (this.hasOwnProperty(name)) {
if (Object.prototype.hasOwnProperty.call(this, name)) {
return 'found';
}
}
// 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');
}
};

Expand Down

0 comments on commit f7f05d7

Please sign in to comment.