Code coverage report for stylus-lint/src/checks/checkForLeadingZero.js

Statements: 100% (14 / 14)      Branches: 100% (10 / 10)      Functions: 100% (2 / 2)      Lines: 100% (13 / 13)      Ignored: none     

All files » stylus-lint/src/checks/ » checkForLeadingZero.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    1     1 11053 11052         11052 34648       11052   18 147 10         11052 10     11042      
'use strict';
 
var leadingZero = /( |,)(0\.)+|(^0\.)+/;
 
// check for leading 0
module.exports = function hasLeadingZero( line, arr ) {
    if ( typeof line !== 'string' ) { return; }
    var i = 0,
        len = arr.length,
        zeroFound = false;
 
    // remove whitespace from array
    arr = arr.filter(function( str ) {
        return str.length > 0;
    });
 
    // return true if leading zero found and not used as part of range
    if ( line.indexOf('0.') !== -1 && line.indexOf('0..') === -1) {
        // console.log( arr );
        for ( i; i < len; i++ ) {
            if ( leadingZero.test( arr[i] ) ) {
                zeroFound = true;
            }
        }
    }
 
    if ( zeroFound ) {
        return true;
    }
    else {
        return false;
    }
 
}