Wednesday, February 2, 2011

JSLint differences and empty block warning messages...

This Rhino JavaScript version appears to avoid issuing "Empty block" warnings. Further examination reveals that the block() checker for JSLint versions out there are all slightly different.

http://www.microidc.com/usr/tools/jslint/rhino/index.html
function block(f) {
        var a, b = inblock, old_indent = indent, s = scope, t;
        inblock = f;
        scope = Object.create(scope);
        nonadjacent(token, nexttoken);
        t = nexttoken;


        funct['(verb)'] = null;
        scope = s;
        inblock = b;
        return a;
     }
The Rhino'd version at https://github.com/mikewest/jslint-utils/blob/master/lib/rhinoed_jslint.js:
function block(f) {
        var a, b = inblock, old_indent = indent, s = scope, t;
        inblock = f;
        scope = Object.create(scope);
        nonadjacent(token, nexttoken);
        t = nexttoken;


      funct['(verb)'] = null;
        scope = s;
        inblock = b;
        if (f && (!a || a.length === 0)) {
            warning("Empty block.");
        }
        return a;
    }
Douglas Crockford's official block() checker (http://www.jslint.com/webjslint.js) or at https://github.com/douglascrockford/JSLint:

function block(ordinary) {
        var a, b = inblock,
            m = strict_mode,
            s = scope,
            t;
        inblock = ordinary;
        scope = Object.create(scope);
        spaces();
        t = nexttoken;
        if (nexttoken.id === '{') {
            advance('{');
            step_in();
            if (!ordinary && !use_strict() && !m && option.strict && funct['(context)']['(global)']) {
                warning(bundle.missing_use_strict);
            }

            a = statements();
        funct['(verb)'] = null;
        scope = s;
        inblock = b;
        if (ordinary && a.length === 0) {
            warning(bundle.empty_block);
        }
        return a;

No comments:

Post a Comment