Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a bug where new max* options were not recognized.

So while publishing r11 I noticed that new max* options (maxparams,
etc.) were not recognized when set using JSHint comments. That was
because we forgot to update the code that checks for numeric values.
This patch fixes that and adds a regression test (just in case).

Will have to move r11 pointer to this commit instead of previous one.
  • Loading branch information...
commit 9cfae063437b90496334907306fb8d98e93e49f3 1 parent aa95558
@valueof valueof authored
Showing with 28 additions and 23 deletions.
  1. +19 −23 jshint.js
  2. +9 −0 tests/unit/core.js
View
42 jshint.js
@@ -1939,31 +1939,27 @@ loop: for (;;) {
checkOption(t.value, t);
}
- if (t.value === "indent" && (o === "/*jshint" || o === "/*jslint")) {
+ var numericVals = [
+ "maxstatements",
+ "maxparams",
+ "maxdepth",
+ "maxcomplexity",
+ "maxerr",
+ "maxlen",
+ "indent"
+ ];
+
+ if (numericVals.indexOf(t.value) > -1 && (o === "/*jshint" || o === "/*jslint")) {
b = +v.value;
- if (typeof b !== "number" || !isFinite(b) || b <= 0 ||
- Math.floor(b) !== b) {
- error("Expected a small integer and instead saw '{a}'.",
- v, v.value);
- }
- obj.white = true;
- obj.indent = b;
- } else if (t.value === "maxerr" && (o === "/*jshint" || o === "/*jslint")) {
- b = +v.value;
- if (typeof b !== "number" || !isFinite(b) || b <= 0 ||
- Math.floor(b) !== b) {
- error("Expected a small integer and instead saw '{a}'.",
- v, v.value);
- }
- obj.maxerr = b;
- } else if (t.value === "maxlen" && (o === "/*jshint" || o === "/*jslint")) {
- b = +v.value;
- if (typeof b !== "number" || !isFinite(b) || b <= 0 ||
- Math.floor(b) !== b) {
- error("Expected a small integer and instead saw '{a}'.",
- v, v.value);
+
+ if (typeof b !== "number" || !isFinite(b) || b <= 0 || Math.floor(b) !== b) {
+ error("Expected a small integer and instead saw '{a}'.", v, v.value);
}
- obj.maxlen = b;
+
+ if (t.value === "indent")
+ obj.white = true;
+
+ obj[t.value] = b;
} else if (t.value === "validthis") {
if (funct["(global)"]) {
error("Option 'validthis' can't be used in a global scope.");
View
9 tests/unit/core.js
@@ -517,3 +517,12 @@ exports.testCatchBlocks = function () {
TestRun()
.test(src, { undef: true, devel: true, node: true });
};
+
+exports.testNumericParams = function () {
+ TestRun()
+ .test("/*jshint maxparams:4, indent:3 */");
+
+ TestRun()
+ .addError(1, "Expected a small integer and instead saw 'face'.")
+ .test("/*jshint maxparams:face */");
+};
Please sign in to comment.
Something went wrong with that request. Please try again.