Beispiel #1
0
 function getPluginMethods(pluginPath,plugin) {
     var methods = {};
     for (var name in plugin) {
         var func = plugin[name];
         if (typeof func === "function" && PLUGIN_METHODS.indexOf(name) > -1) {
             JSLINT('('+String(func)+')', {node: true, sloppy: true, white: true, vars: true, maxerr: Infinity, forin: true});
             if (!JSLINT.tree.first) {
                 console.error('In file ' + pluginPath + ' in function exports. ' + name + ':');
                 JSLINT.data().errors.forEach(function (error) {
                     if (error) {
                         console.error(error.reason);
                         if (error.evidence) {
                             console.error(error.evidence+'\n');
                         }
                     }
                 });
                 throw new Error('JSLINT could not parse function');
             }
             methods[name] = JSLINT.tree.first[0].first.map(function (param) {
                 return param.string;
             });
         }
     }
     return methods;
 }
    filenames.forEach(function(filename) {
        var data = fs.readFileSync('./' + filename);

        // Fix UTF8 with BOM
        if (0xEF === data[0] && 0xBB === data[1] && 0xBF === data[2]) {
            data = data.slice(3);
        }
        data = data.toString("utf8");

        console.log('[JSLINT]', filename);

        if (!jslint(data, JSLINT_OPTIONS)) {
            throw {
                filename: filename,
                report: jslint.data()
            }
        }
        files.push({
            'name': filename,
            'content': data
        });
    });
Beispiel #3
0
    Command._lintOneFile = function(infile, outfile) {
        var jslint = require('jslint'),
            OPTS = {
                'continue': true, // Tolerate continue
                node: true,
                predef: [
                    // CommonJS
                    'exports',
                    // YUI
                    'YUI', 'YUI_config', 'YAHOO', 'YAHOO_config', 'Y',
                    // Node
                    'global', 'process', 'require', '__filename', 'module',
                    // Browser
                    'document', 'navigator', 'console', 'self', 'window'
                ]
            },
            errors = 0,
            i = 0,
            e,
            input,
            len,
            success,
            pad,
            data;

        input = libfs.readFileSync(infile);
        if (!input) {
            utils.error("Failed to open file '" + infile + "'.", Command.usage);
            return 0;
        }
        input = input.toString('utf8');

        // remove shebang (lifted from node.js)
        input = input.replace(/^\#\!.*/, '');

        success = jslint(input, OPTS);
        if (!success) {
            errors = len = jslint.errors.length;
            for (i = 0; i < len; i += 1) {
                pad = String(i + 1);
                while (pad.length < 4) {
                    pad = ' ' + pad;
                }
                e = jslint.errors[i];
                if (e) {
                    outfile.write(pad + ' ' + e.line + ',' + e.character +
                        ': ' + e.reason + '\n');
                    outfile.write('     ' +
                        (e.evidence || '').replace(/^\s+|\s+$/, '') + '\n');
                }
            }
        }

        data = jslint.data();
        data.functions.forEach(function(f) {
            if (f.name.charAt(0) === '_') {
                pad = String(i + 1);
                while (pad.length < 4) {
                    pad = ' ' + pad;
                }
                outfile.write(pad + ' ' + f.line + ': ' +
                        "Unexpected leading '_' in '" + f.name + "'.\n");
                i += 1;
                errors += 1;
            }
            if (f['var']) {
                f['var'].forEach(function(v) {
                    if (v.charAt(0) === '_') {
                        pad = String(i + 1);
                        while (pad.length < 4) {
                            pad = ' ' + pad;
                        }
                        outfile.write(pad + ' ' + f.line + ': ' +
                                "Unexpected leading '_' in '" + v + "'.\n");
                        outfile.write('     ' +
                                'function ' + f.name + '\n');
                        i += 1;
                        errors += 1;
                    }
                });
            }
        });

        return errors;
    };