Code coverage report for stylus-lint/src/parse.js

Statements: 95.24% (20 / 21)      Branches: 83.33% (5 / 6)      Functions: 100% (4 / 4)      Lines: 95% (19 / 20)      Ignored: none     

All files » stylus-lint/src/ » parse.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61    1                         1 76   76 76 74     74 296       296         296 1006     296       74             74 12682   12682 12682       74 4      
'use strict';
 
var
    fs = require('fs'),
    done = require('./done'),
    test = require('./test');
 
 
/**
 * @description parses file for testing by removing extra new lines and block comments
 * @param  {string} file        [the current file being parsed]
 * @param  {number} len         [total number of files to parse]
 * @param  {number} fileNum     [the current file being parsed (# of len) ]
 * @returns test function
 */
module.exports = function parse( app, file, len, fileNum ) {
    var stripComments = /(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)/gm;
 
    return fs.readFile(file, { encoding: 'utf8' }, function( err, data ) {
        if ( err ) { throw err; }
        var lines;
 
        // remove block comments / empty lines from files
        lines = data.replace(stripComments, function( match ) {
            var lines = match.split(/\r\n|\r|\n/),
                lineLen = lines.length - 1,
                output = ' ';
 
            Iif ( lineLen === 1 ) {
                return ' ';
            }
            else {
 
                while ( lineLen-- ) {
                    output += '\n';
                }
 
                return output;
            }
        });
 
        lines = lines.split('\n');
 
        /**
         * so, this function trims each line and then tests it
         * @param  {string} [line] the line of stylus to test
         * @return {function} run test
         */
        lines.forEach(function( line, i ) {
            var output = line.trim();
            // line nos don't start at 0
            i++;
            return test( app, line, i, output, file );
        });
 
        // if at the last file, call the done function to output results
        if ( fileNum === len ) {
            return done( app );
        }
    });
}