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

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

All files » stylus-lint/src/checks/ » zIndexDeDupe.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 11187   11186           11186   34 188 120     68       34 561 37       34     11186  
'use strict';
 
// check for z-index values that are duplicated elsewhere
module.exports = function deDupeZIndex( line ) {
    if ( typeof line !== 'string' ) { return; }
 
    var indentCount = 0,
        context = 0,
        isItADupe = false,
        arr = line.split(/[\s\t,:]/);
 
    // the most basic of checks, throw warning if zindex duplicated elsewhere
    if ( line.indexOf('z-index') !== -1 ) {
 
        arr.forEach(function( val, i ) {
            if ( arr[i].length === 0 ) {
                indentCount++; // spaces or tabs
            }
            else {
                context = indentCount / this.config.indentSpaces;
            }
        }.bind( this ));
 
        this.zCache.forEach(function( val, i ) {
            if ( this.zCache[i][0] === arr[ arr.length - 1 ] && context === this.zCache[i][1] ) {
                isItADupe = true;
            }
        }.bind( this ));
 
        this.zCache.push( [ arr[ arr.length - 1 ], context ] );
    }
 
    return isItADupe;
}