Skip to content

Commit

Permalink
[[FIX]] Make the 'freeze' option less strict
Browse files Browse the repository at this point in the history
Don't warn when the prototype of a local variable
named as a native object is modified.

Fixes gh-1600
  • Loading branch information
nicolo-ribaudo authored and jugglinmike committed Jan 30, 2016
1 parent 480252a commit b76447c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,8 +1301,10 @@ var JSHINT = (function() {
while (!obj.identifier && typeof obj.left === "object")
obj = obj.left;

if (obj.identifier && natives.indexOf(obj.value) >= 0)
if (obj.identifier && natives.indexOf(obj.value) >= 0 &&
state.funct["(scope)"].isPredefined(obj.value)) {
return obj.value;
}
}

var prototype = walkPrototype(left);
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/fixtures/nativeobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ Boolean.prototype = {

NonArray.prototype.random = function () {
return 4;
};
};

{
let Array = {};
Array.prototype.method = function() {};
}

(function() {
var Array = 2;
Array.prototype.method = function() {};
}());
4 changes: 2 additions & 2 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2519,10 +2519,10 @@ exports.freeze = function (test) {
TestRun(test)
.addError(3, "Extending prototype of native object: 'Array'.")
.addError(13, "Extending prototype of native object: 'Boolean'.")
.test(src, { freeze: true });
.test(src, { freeze: true, esversion: 6 });

TestRun(test)
.test(src);
.test(src, { esversion: 6 });

test.done();
};
Expand Down

0 comments on commit b76447c

Please sign in to comment.