diff --git a/.eslintrc.js b/.eslintrc.js index 3ba423055..5c55b10f9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -57,6 +57,7 @@ module.exports = { "no-with": "error", "radix": "error", "wrap-iife": "error", + "no-prototype-builtins": "error", // Variables // @@ -114,4 +115,4 @@ module.exports = { "ecmaVersion": 6, "ecmaFeatures": {} } -} +}; diff --git a/bench/util/benchwarmer.js b/bench/util/benchwarmer.js index 49f66f737..58f138a0e 100644 --- a/bench/util/benchwarmer.js +++ b/bench/util/benchwarmer.js @@ -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); } @@ -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; @@ -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); @@ -97,7 +96,7 @@ BenchWarmer.prototype = { } print('\n'); } - } + }); } callback(); diff --git a/lib/handlebars/compiler/code-gen.js b/lib/handlebars/compiler/code-gen.js index 43c0481bc..30c5af740 100644 --- a/lib/handlebars/compiler/code-gen.js +++ b/lib/handlebars/compiler/code-gen.js @@ -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('{'); diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 4acdb50dd..9a4c02daf 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -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']; diff --git a/lib/handlebars/helpers/each.js b/lib/handlebars/helpers/each.js index ce549b5c7..8e57b7782 100644 --- a/lib/handlebars/helpers/each.js +++ b/lib/handlebars/helpers/each.js @@ -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); } diff --git a/lib/handlebars/helpers/lookup.js b/lib/handlebars/helpers/lookup.js index cba452451..8c1b604be 100644 --- a/lib/handlebars/helpers/lookup.js +++ b/lib/handlebars/helpers/lookup.js @@ -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]; diff --git a/spec/compiler.js b/spec/compiler.js index 02dad6751..3d37b5940 100644 --- a/spec/compiler.js +++ b/spec/compiler.js @@ -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'); } }); diff --git a/spec/regressions.js b/spec/regressions.js index a8879067e..74594de6b 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -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'); } };