Skip to content
This repository
Browse code

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
Anton Kovalyov authored September 03, 2012
42  jshint.js
@@ -1939,31 +1939,27 @@ loop:   for (;;) {
1939 1939
                     checkOption(t.value, t);
1940 1940
                 }
1941 1941
 
1942  
-                if (t.value === "indent" && (o === "/*jshint" || o === "/*jslint")) {
  1942
+                var numericVals = [
  1943
+                    "maxstatements",
  1944
+                    "maxparams",
  1945
+                    "maxdepth",
  1946
+                    "maxcomplexity",
  1947
+                    "maxerr",
  1948
+                    "maxlen",
  1949
+                    "indent"
  1950
+                ];
  1951
+
  1952
+                if (numericVals.indexOf(t.value) > -1 && (o === "/*jshint" || o === "/*jslint")) {
1943 1953
                     b = +v.value;
1944  
-                    if (typeof b !== "number" || !isFinite(b) || b <= 0 ||
1945  
-                            Math.floor(b) !== b) {
1946  
-                        error("Expected a small integer and instead saw '{a}'.",
1947  
-                                v, v.value);
1948  
-                    }
1949  
-                    obj.white = true;
1950  
-                    obj.indent = b;
1951  
-                } else if (t.value === "maxerr" && (o === "/*jshint" || o === "/*jslint")) {
1952  
-                    b = +v.value;
1953  
-                    if (typeof b !== "number" || !isFinite(b) || b <= 0 ||
1954  
-                            Math.floor(b) !== b) {
1955  
-                        error("Expected a small integer and instead saw '{a}'.",
1956  
-                                v, v.value);
1957  
-                    }
1958  
-                    obj.maxerr = b;
1959  
-                } else if (t.value === "maxlen" && (o === "/*jshint" || o === "/*jslint")) {
1960  
-                    b = +v.value;
1961  
-                    if (typeof b !== "number" || !isFinite(b) || b <= 0 ||
1962  
-                            Math.floor(b) !== b) {
1963  
-                        error("Expected a small integer and instead saw '{a}'.",
1964  
-                                v, v.value);
  1954
+
  1955
+                    if (typeof b !== "number" || !isFinite(b) || b <= 0 || Math.floor(b) !== b) {
  1956
+                        error("Expected a small integer and instead saw '{a}'.", v, v.value);
1965 1957
                     }
1966  
-                    obj.maxlen = b;
  1958
+
  1959
+                    if (t.value === "indent")
  1960
+                        obj.white = true;
  1961
+
  1962
+                    obj[t.value] = b;
1967 1963
                 } else if (t.value === "validthis") {
1968 1964
                     if (funct["(global)"]) {
1969 1965
                         error("Option 'validthis' can't be used in a global scope.");
9  tests/unit/core.js
@@ -517,3 +517,12 @@ exports.testCatchBlocks = function () {
517 517
     TestRun()
518 518
         .test(src, { undef: true, devel: true, node: true });
519 519
 };
  520
+
  521
+exports.testNumericParams = function () {
  522
+    TestRun()
  523
+        .test("/*jshint maxparams:4, indent:3 */");
  524
+
  525
+    TestRun()
  526
+        .addError(1, "Expected a small integer and instead saw 'face'.")
  527
+        .test("/*jshint maxparams:face */");
  528
+};

0 notes on commit 9cfae06

Please sign in to comment.
Something went wrong with that request. Please try again.