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

Statements: 100% (11 / 11)      Branches: 100% (10 / 10)      Functions: 100% (1 / 1)      Lines: 100% (10 / 10)      Ignored: none     

All files » stylus-lint/src/checks/ » checkForMixedSpacesTabs.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    1                     1 6     5   3 2       1           2 1       1      
'use strict';
 
var
    tabs  = /\t/,       // was a tab used, at all
    spaces = /\s{2,}/;  // check for 2 or more spaces (if hard tabs, shouldn't find anything)
 
/**
 * check for mixed spaces and tabs
 * @param  {string} line  the line being tested
 * @param  {number} indentSpaces  default is 4. if set to false the we do hard tabs instead of spaces
 * @return {boolean} true if mixed spaces and tabs, false if not
 * @todo  this is kinda not 100% reliable in it's current form
 */
module.exports = function checkMixedSpacesAndTabs( line, indentSpaces ) {
    if ( typeof line !== 'string' || typeof indentSpaces === 'undefined' ) { return; }
 
    // if this isnt set to false then we're indenting with spaces
    if ( typeof indentSpaces === 'number' ) {
        // look for hard tabs
        if ( tabs.test( line ) ) {
            return true;
        }
        // soft tabs, no hard tabs, all good
        else {
            return false;
        }
    }
    // else you're a hard tab believer
    else {
        // look for 2 or more spaces
        if ( spaces.test( line ) ) {
            return true;
        }
        // hard tab, no spaces, all good
        else {
            return false;
        }
    }
}