Permalink
Browse files

[[FIX]] Allow ignoring W020 and W021

Fixes gh-2761
  • Loading branch information...
nicolo-ribaudo authored and jugglinmike committed Nov 13, 2015
1 parent 56527c7 commit 46db9238da535a2d82d7565deac887de6e602ad4
Showing with 42 additions and 2 deletions.
  1. +8 −2 src/scope-manager.js
  2. +34 −0 tests/unit/core.js
@@ -305,7 +305,9 @@ var scopeManager = function(state, predefined, exported, declared) {
if ((usedLabelType === "function" || usedLabelType === "class") &&
usage["(reassigned)"]) {
for (j = 0; j < usage["(reassigned)"].length; j++) {
error("W021", usage["(reassigned)"][j], usedLabelName, usedLabelType);
if (!usage["(reassigned)"][j].ignoreW021) {
warning("W021", usage["(reassigned)"][j], usedLabelName, usedLabelType);
}
}
}
continue;
@@ -343,7 +345,9 @@ var scopeManager = function(state, predefined, exported, declared) {
// check for re-assigning a read-only (set to false) predefined
if (_current["(predefined)"][usedLabelName] === false && usage["(reassigned)"]) {
for (j = 0; j < usage["(reassigned)"].length; j++) {
warning("W020", usage["(reassigned)"][j]);
if (!usage["(reassigned)"][j].ignoreW020) {
warning("W020", usage["(reassigned)"][j]);
}
}
}
}
@@ -784,6 +788,8 @@ var scopeManager = function(state, predefined, exported, declared) {
},

reassign: function(labelName, token) {
token.ignoreW020 = state.ignored.W020;
token.ignoreW021 = state.ignored.W021;

this.modify(labelName, token);

@@ -1997,3 +1997,37 @@ exports.duplicateProto = function (test) {

test.done();
};

exports["gh-2761"] = function (test) {
var code = [
"/* global foo: false */",
"foo = 2;",
"// jshint -W020",
"foo = 3;",
"// jshint +W020",
"foo = 4;"
];

TestRun(test, "W020")
.addError(2, "Read only.")
.addError(6, "Read only.")
.test(code);

code = [
"function a() {}",
"a = 2;",
"// jshint -W021",
"a = 3;",
"// jshint +W021",
"a = 4;"
];

TestRun(test, "W021")
.addError(2, "Reassignment of 'a', which is is a function. " +
"Use 'var' or 'let' to declare bindings that may change.")
.addError(6, "Reassignment of 'a', which is is a function. " +
"Use 'var' or 'let' to declare bindings that may change.")
.test(code);

test.done();
};

0 comments on commit 46db923

Please sign in to comment.