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

Statements: 11.76% (2 / 17)      Branches: 0% (0 / 13)      Functions: 0% (0 / 2)      Lines: 11.76% (2 / 17)      Ignored: none     

All files » stylus-lint/src/checks/ » checkForValidValues.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 87                              1         1                                                                                                                                    
/**
* 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)
*/
 
 
// super super rough atm
// @TODO inherit check for all values
// @TODO regex to match any color
// @TODO regex to match any length (ie, px, %, whatever)
// @TODO dont throw warnings if html
 
 
const
    ignoreMe = /[$.#{}(=]|(if)|(for)|(@block)/, // dont throw false positives on user created names or syntax
    valid = false;
 
 
module.exports = function checkForValidProperties( line, arr, validCSS, validHTML ) {
    'use strict';
    if ( typeof line === 'undefined' ||
        typeof validCSS === 'undefined' ||
        typeof validHTML === 'undefined' ) {
        return;
    }
 
    var len = validHTML.length,
        i = 0;
 
    // filter out white space
    arr = arr.filter(function( str ) {
        return str.length > 0;
    });
 
    console.log( arr );
 
    // not empty, not something we ignore
    if ( !ignoreMe.test( line ) ) {
 
        // loop through our valid css json
        for ( var prop in validCSS ) {
 
            // console.log( validCSS[prop] );
 
            // get keys, the properties, which is where we'll start
            if ( validCSS.hasOwnProperty( prop ) ) {
 
                // console.log( validCSS[prop] )
                // console.log( validCSS[prop].length );
 
                // loop through css array
                if ( validCSS[prop] ) {
                    for ( i; i < validCSS[prop].length; i++ ) {
                        // if exact string match,
                        if ( arr[1] === validCSS[ i ] ) {
                            valid = true;
                            // console.log( html[i] );
                            return true;
                        }
                    }
                }
 
                // // if we have an exact css match
                // if ( arr[0] === valid[prop] ) {
                //     return true;
                // }
                // // else no css match, check if html property
                // else {
 
                //     // loop through html array
                //     for ( i; i < len; i++ ) {
                //         // if exact string match,
                //         if ( arr[0] === validHTML[ i ] ) {
                //             valid = true;
                //             // console.log( html[i] );
                //             return true;
                //         }
                //     }
                // }
            }
        }
 
        return false;
    }
 }