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

Statements: 95.45% (21 / 22)      Branches: 96.67% (29 / 30)      Functions: 100% (2 / 2)      Lines: 95.24% (20 / 21)      Ignored: none     

All files » stylus-lint/src/checks/ » checkForEfficiency.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      1 11061     11060 34675       11060           173   95   28 1     27       67   46 3     43       21   17 7     10       10         78      
'use strict';
 
// check for 0 0 0 0 or 50px 0 50px 0 type mistakes
module.exports = function checkForEfficiency( line, arr ) {
    if ( typeof line !== 'string' || typeof arr === 'undefined') { return; }
 
    // filter the array from the line with all white space removed
    arr = arr.filter(function( str ) {
        return str.length > 0;
    });
 
    // if margin or padding we run the tests
    if ( arr[0] === 'margin' ||
        arr[0] === 'padding' ||
        arr[0] === '\tmargin' ||
        arr[0] === '\tpadding' ) {
 
        // if line is potentially inefficient it needs to be at least this long
        if ( arr.length > 2 ) {
            // ex: margin 0 5px
            if ( arr.length === 3 ) {
                // ex margin 0 0
                if ( arr[1] === arr[2] )  {
                    return false;
                }
                else {
                    return true;
                }
            }
            // ex margin 0 5px 10px
            else if ( arr.length === 4 ) {
                // ex margin 0 5px 0
                if ( arr[1] === arr[3] ) {
                    return false;
                }
                else {
                    return true;
                }
            }
            // ex margin 0 50px 10px 7px
            else if ( arr.length === 5 ) {
                // ex margin 0 5px 0 5px
                if ( arr[1] === arr[3] && arr[2] === arr[4] ) {
                    return false;
                }
                // ex margin 0 5px 5px 5px
                else Iif ( arr[1] !== arr[3] && arr[2] === arr[4] ) {
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        else {
            return true;
        }
    }
}