function displayMetrics(file) {
    var prefix = '';

    var code = fs.readFileSync(file, 'utf-8');

    // We remove any shebang at the start of the file since that isn't valid
    // Javascript and will trip up the parser.

    code = code.replace(/^#!.*\n/, '');

    var metrics = complexity(code);

    // Walk the metrics structure and add each member to the table rows.

    function walk(data, name) {
        // Fade out anonymous functions.

        if (name.indexOf('anon@') === 0) {
            name = name.grey;
        }

        rows.push([ prefix + name, data.ecc, data.arity, data.codeLines, data.commentLines, Math.round(100 * data.commentLines / data.codeLines) ]);

        // Add two spaces to the prefix before the next depth, to illustrate
        // the hierarchy in the table.

        prefix += '  ';
        _.each(data.children, walk);
        prefix = prefix.slice(0,prefix.length-2);
    }
    walk(metrics, path.basename(file).blue.bold);
}
function displayMetrics(file) {
    var prefix = '';

    var code = fs.readFileSync(file, 'utf-8');

    // We remove any shebang at the start of the file since that isn't valid
    // Javascript and will trip up the parser.

    code = code.replace(/^#!.*\n/, '');

    var metrics = complexity(code);

    // Walk the metrics structure and add each member to the table rows.

    function walk(data, name) {
        // Fade out anonymous functions.

        if (name.indexOf('anon@') === 0) {
            name = name.grey;
        }

        rows.push([ prefix + name, data.ecc, data.arity, data.codeLines, data.commentLines, Math.round(100 * data.commentLines / data.codeLines) ]);

        // Add two spaces to the prefix before the next depth, to illustrate
        // the hierarchy in the table.

        prefix += '  ';
        _.each(data.children, walk);
        prefix = prefix.slice(0,prefix.length-2);
    }
    walk(metrics, path.basename(file).blue.bold);
}
function displayMetrics ( file ) { var prefix = '' ; var code = fs . readFileSync ( file , 'utf-8' ) ; // We remove any shebang at the start of the file since that isn't valid // Javascript and will trip up the parser. code = code . replace ( / ^#!.*\n / , '' ) ; var metrics = complexity ( code ) ; // Walk the metrics structure and add each member to the table rows. function walk ( data , name ) { // Fade out anonymous functions. if ( name . indexOf ( 'anon@' ) === 0 ) { name = name . grey ; } rows . push ( [ prefix + name , data . ecc , data . arity , data . codeLines , data . commentLines , Math . round ( 100 * data . commentLines / data . codeLines ) ] ) ; // Add two spaces to the prefix before the next depth, to illustrate // the hierarchy in the table. prefix += '  ' ; _ . each ( data . children , walk ) ; prefix = prefix . slice ( 0 , prefix . length - 2 ) ; } walk ( metrics , path . basename ( file ) . blue . bold ) ; }
Analyze a file and add it's metrics to the table.
Analyze a file and add it s metrics to the table .