jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.96k stars 510 forks source link

maxErrors error is reported even if --max-errors=-1 option is used #2030

Closed jkryl closed 8 years ago

jkryl commented 8 years ago

and I found the reason why it happens. there is a bug in string-checker.js. _maxErrorsEnabled should check also -1 value and not just null. Following patch solves the problem, however I'm not sure if I did not remove too many lines. In particular I don't have idea for what global.s is used.

diff -ru a/lib/string-checker.js b/lib/string-checker.js
--- a/lib/string-checker.js 2015-12-21 12:51:41.000000000 +0100
+++ b/lib/string-checker.js 2015-12-21 12:51:08.000000000 +0100
@@ -183,14 +183,8 @@
         }

         if (this._maxErrorsEnabled()) {
-            global.s = this._maxErrors === -1 || this._maxErrors === null;
-            if (this._maxErrors === -1 || this._maxErrors === null) {
-                this._maxErrorsExceeded = false;
-
-            } else {
-                this._maxErrorsExceeded = this._errorsFound + errors.getErrorCount() > this._maxErrors;
-                errors.stripErrorList(Math.max(0, this._maxErrors - this._errorsFound));
-            }
+            this._maxErrorsExceeded = this._errorsFound + errors.getErrorCount() > this._maxErrors;
+            errors.stripErrorList(Math.max(0, this._maxErrors - this._errorsFound));
         }

         this._errorsFound += errors.getErrorCount();
@@ -288,7 +282,7 @@
      * @returns {Boolean}
      */
     _maxErrorsEnabled: function() {
-        return this._maxErrors !== null;
+        return (this._maxErrors !== null && this._maxErrors !== -1);
     },

     /**
markelog commented 8 years ago

Yeah, you probably right, do you want to send us a PR?

markelog commented 8 years ago

By looking at the code, it seems there is a commit that shouldn't be there, probably landed by mistake :/

markelog commented 8 years ago

Even though logic is flowed, it actually works correctly from the console, i clean up the code though.

Thank you for noticing.

jkryl commented 8 years ago

@markelog : Thanks for taking care of the issue!