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

Statements: 88.24% (30 / 34)      Branches: 90.48% (19 / 21)      Functions: 100% (4 / 4)      Lines: 88.24% (30 / 34)      Ignored: none     

All files » stylus-lint/src/checks/ » checkForValidProperties.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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86      1               1 11195   3       11192       11192   42268         11192       3280 387040     387040 2376 2376     384664 1538516 78 78       384586 6922548             3280 400160     400160 790 790     399370 7188660               7912       11192 11156     36    
'use strict';
 
// dont throw false positives on user created names or syntax
var ignoreMe = /[$.#{}(=>]|(if)|(for)|(@block)/;
 
/**
* check against a JSON of all valid css properties and values
* @returns false if property or value not considered valid
* @returns true if valid
* @returns undefined if not testable (hmmm)
*/
module.exports = function checkForValidProperties( line, valid ) {
    if ( typeof line !== 'string' ||
        typeof valid === 'undefined' ) {
        return;
    }
 
    // split by tabs and spaces, tabs mess with pattern matching
    var arr = line.split(/[\s\t,:]/),
        isValid = false;
 
    // remove white space
    arr = arr.filter(
        function( str ) {
            return str.length > 0;
        }
    );
 
    // not empty, not something we ignore
    if ( !ignoreMe.test( line ) &&
        this.state.hash === false &&
        typeof arr[0] !== 'undefined' ) {
 
        valid.css.forEach(function( val, index ) {
            var i = 0,
                j = 0;
 
            if ( arr[ 0 ] === val ) {
                isValid = true;
                return;
            }
 
            for ( i; i < valid.prefixes.length; i++ ) {
                if ( arr[ 0 ] === ( valid.prefixes[ i ] + val ) ) {
                    isValid = true;
                    return;
                }
            }
 
            for ( j; j < valid.pseudo.length; j++ ) {
                Iif ( arr[ 0 ] === ( val + valid.pseudo[ j ] ) ) {
                    isValid = true;
                    return;
                }
            }
        });
 
        valid.html.forEach(function( val, index ) {
            var i = 0,
                j = 0;
 
            if ( arr[ 0 ] === val ) {
                isValid = true;
                return;
            }
 
            for ( j; j < valid.pseudo.length; j++ ) {
                Iif ( arr[ 0 ] === ( val + valid.pseudo[ j ] ) ) {
                    isValid = true;
                    return;
                }
            }
        });
    }
    else {
        isValid = true;
    }
 
    // return true if valid match found
    if ( isValid ) {
        return true;
    }
    else {
        return false;
    }
 }