jshint/fixmyjs

Error fixmyjs/lib/cli.js:136

Closed this issue · 3 comments

Hi

I've got this error when I try run fixmyjs on code below:

fixmyjs -r codeBelow.js
/usr/local/lib/node_modules/fixmyjs/lib/cli.js:136
      throw ex
            ^
File: /Users/lagden/dev/js/support/codeBelow.js
Error: Unknown statement type: undefined
.
.
.

codeBelow.js

/*global define */
define(function() {

    'use strict';

    function numbers(c) {
        c = c.replace(/[^\d]/g, '').split('');
        for (var i = 0, len = c.length; i < len; i++)
            c[i] = parseInt(c[i], 10);
        return c;
    }

    function isCnpj(c) {

        var b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2],
            i,
            n;

        c = numbers(c);

        if (c.length !== 14)
            return false;

        for (i = 0, n = 0; i < 12; n += c[i] * b[++i]);
        if (c[12] !== (((n %= 11) < 2) ? 0 : 11 - n))
            return false;

        for (i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
        if (c[13] !== (((n %= 11) < 2) ? 0 : 11 - n))
            return false;

        return true;
    }

    function isCpf(c) {

        var s,
            n,
            i;

        c = numbers(c);

        if (c.length !== 11)
            return false;

        if (new RegExp("^" + c[0] + "{11}$").test(c.join('')))
            return false;

        for (s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);
        if (c[9] !== (((n %= 11) < 2) ? 0 : 11 - n))
            return false;

        for (s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--);
        if (c[10] !== (((n %= 11) < 2) ? 0 : 11 - n))
            return false;

        return true;
    }

    function isCpfCnpj(v) {
        return isCnpj(v) || isCpf(v);
    }

    return isCpfCnpj;

});

I think this syntax is the problem

for (s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);

I made a small script to confirm:

function xxx() {
    var c = [3,5,6,7,1,1,3,8,0,0,0,1,0,5],
        i, n,
        b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];

    for (i = 0, n = 0; i < 12; n += c[i] * b[++i]);

    console.log(n);
}

Tested on cli and online

Fail

Thanks, I think I see what's going on.