Code coverage report for stylus-lint/index.js

Statements: 71.43% (25 / 35)      Branches: 67.86% (19 / 28)      Functions: 100% (5 / 5)      Lines: 73.53% (25 / 34)      Ignored: none     

All files » stylus-lint/ » index.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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262                            1                                                                                         1                                                                     1                                           1                                         1   5   5 4 4   4 72         2                       1                                                                         1 1     1 1             1         1         1         1                       1       1           1                     1  
#!/usr/bin/env node
 
/**
 * Stylus Lint (splinter) (the p is silent)
 * @description A basic, configurable, node based, stylus linter cli
 *              read() -> parse() -> test() -> done()
 *              or
 *              watch() -> read() -> parse() -> test() -> done()
 * @flow
*/
 
'use strict';
 
// all modules go here
var
	stampit = require('stampit'),
    fs = require('fs'),
    glob = require('glob').Glob,
    done = require('./src/done'),
    help = require('./src/help'),
    read = require('./src/read'),
    parse = require('./src/parse'),
    test = require('./src/test'),
    ver = require('./src/version'),
    watch = require('./src/watch'),
    alphabetCheck           = require('./src/checks/alphabetCheck'),
    blockStyleCorrect       = require('./src/checks/checkBlockStyle'),
    brackets                = require('./src/checks/checkForBrackets'),
    checkBorderNone         = require('./src/checks/checkBorderNone'),
    colon                   = require('./src/checks/checkForColon'),
    commaStyleCorrect       = require('./src/checks/checkCommaStyle'),
    commentStyleCorrect     = require('./src/checks/checkCommentStyle'),
    cssLiteral              = require('./src/checks/checkForCssLiteral'),
    deDupeZ                 = require('./src/checks/zIndexDeDupe'),
    duplicates              = require('./src/checks/duplicateCheck'),
    efficient               = require('./src/checks/checkForEfficiency'),
    extendStyleCorrect      = require('./src/checks/checkForExtendStyle'),
    hasComment              = require('./src/checks/checkForComment'),
    hashEnding              = require('./src/checks/checkForHashEnd'),
    hashStarting            = require('./src/checks/checkForHashStart'),
    leadingZero             = require('./src/checks/checkForLeadingZero'),
    mixedSpacesAndTabs      = require('./src/checks/checkForMixedSpacesTabs'),
    namingConvention        = require('./src/checks/checkNamingConvention'),
    normalizeZ              = require('./src/checks/zIndexNormalize'),
    parenStyleCorrect       = require('./src/checks/checkForParenStyle'),
    placeholderStyleCorrect = require('./src/checks/checkForPlaceholderStyle'),
    semicolon               = require('./src/checks/checkForSemicolon'),
    startsWithComment       = require('./src/checks/checkForCommentStart'),
    tooMuchNest             = require('./src/checks/checkNesting'),
    universalSelector       = require('./src/checks/checkForUniversal'),
    validProperty           = require('./src/checks/checkForValidProperties'),
    varStyleCorrect         = require('./src/checks/checkVarStyle'),
    whitespace              = require('./src/checks/checkForTrailingWhitespace'),
    zeroUnits               = require('./src/checks/checkForZeroUnits');
 
 
/**
 * configuration related properties
 */
var config = stampit().state({
    config: {
        'alphabetical': true, // check that properties are sorted alphabetically
        'borderNone': true, // check for use of border none and recommend border 0
        'brackets': true, // check for { or }, unless used in a hash
        'colons': false, // check for unecessary colons
        'commaSpace': true, // check for spaces after commas (0, 0, 0, .18)
        'commentSpace': false, // check for space after line comment
        'cssLiteral': false, // if true disallow css literals
        'depthLimit': false, // set a maximum selector depth (dont nest more than 4 deep)
        'duplicates': true, // check if properties or selectors are duplicate
        'efficient': true, // check for margin 0 0 0 0 and recommend margin 0
        'enforceVarStyle': false, // check for $ when declaring vars (doesnt check use)
        'enforceBlockStyle': false, // check for @block when defining blocks
        'extendPref': false, // prefer a specific syntax when using @extends (or @extend)
        'globalDupe': false, // throw duplicate selector warning across all files instead of curr file
        'indentSpaces': 4, // how many spaces should we prefer when indenting, pass in false if hard tabs
        'leadingZero': true, // find cases where 0.# is used, prefer .#
        'maxWarnings': 10, // should we have a max amount of warnings, and error out if we go over
        'mixed': false, // check for mixed spaces and tabs
        'namingConvention': false, // lowercase-dash, camelCase, lowercase-underscore, or false (dont check)
        'parenSpace': false, // check for extra space inside parens when defining or using mixins
        'placeholders': true, // only allow @extending of placeholder vars
        'semicolons': false, // check for unecessary semicolons
        'trailingWhitespace': true, // check for trailing whitespace
        'universal': true, // check for use of * and recommend against it
        'valid': true, // check if prop or value is a valid assignment
        'zeroUnits': true, // check for use of 0px | 0em | 0rem | 0% | etc and recommend 0 instead
        'zIndexDuplicates': true, // just find duplicate z index values
        'zIndexNormalize': 5 // suggest a normalized z index value, base of whatever this is
    }
});
 
 
// flags for the app
var flags = stampit().state({
    flags: [
        '-c',
        '-w',
        '-s',
        '-v',
        '-h',
        '--config',
        '--watch',
        '--strict',
        '--version',
        '--help',
        '--harmony'
    ]
});
 
 
/**
 * @description i hold the state
 * @todo prolly dont need so many arrays
 * @return {Object} [i expose properties to the entire app]
 */
var state = stampit().state({
    state: {
    	cssBlock: false,
    	dir: undefined,
    	hash: false,
    	strictMode: false,
    	testsEnabled: true, // are we running linter tests
    	toggleBlock: false // @stylint off
    },
    warnings: [],
    alphaCache: [],
    selectorCache: [],
    rootCache: [],
    zCache: []
});
 
 
/**
 * @description i hold the functionality
 * @return {Object} [i expose the modules to the entire app, so we only do it once]
 */
var coreMethods = stampit().methods({
    getFiles: function( path ) {
        var app = this;
 
        glob(path, {}, function( err, files ) {
            Iif ( err ) { throw err; }
            var len = files.length - 1;
 
            files.forEach(function( file, i ) {
                return app.parseFile( app, file, len, i );
            });
        });
    },
    setConfig: function( path ) {
        return JSON.parse( fs.readFileSync( process.cwd() + '/' + path ) );
    },
    done: done,
    help: help,
    read: read,
    parseFile: parse,
    test: test,
    ver: ver,
    watch: watch
});
 
 
var testMethods = stampit().methods({
    alphabetCheck: alphabetCheck,
    blockStyleCorrect: blockStyleCorrect,
    brackets: brackets,
    checkBorderNone: checkBorderNone,
    colon: colon,
    commaStyleCorrect: commaStyleCorrect,
    commentStyleCorrect: commentStyleCorrect,
    cssLiteral: cssLiteral,
    deDupeZ: deDupeZ,
    duplicates: duplicates,
    efficient: efficient,
    extendStyleCorrect: extendStyleCorrect,
    hasComment: hasComment,
    hashEnding: hashEnding,
    hashStarting: hashStarting,
    leadingZero: leadingZero,
    mixedSpacesAndTabs: mixedSpacesAndTabs,
    namingConvention: namingConvention,
    normalizeZ: normalizeZ,
    parenStyleCorrect: parenStyleCorrect,
    placeholderStyleCorrect: placeholderStyleCorrect,
    semicolon: semicolon,
    startsWithComment: startsWithComment,
    tooMuchNest: tooMuchNest,
    universalSelector: universalSelector,
    validProperty: validProperty,
    varStyleCorrect: varStyleCorrect,
    whitespace: whitespace,
    zeroUnits: zeroUnits
});
 
 
/**
 * @description i initialize everything
 * @return {Function} [calls the part of the app we want, depending on state]
 */
var init = stampit().enclose(function () {
    var configIndex;
 
    // if path/ passed in use that for the dir
    Eif ( process.argv[2] && this.flags.indexOf( process.argv[2] ) === -1 ) {
        this.state.dir = process.argv[2];
    }
    else {
        this.state.dir = process.cwd();
    }
 
	// display help message if user types --help
	Iif ( process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1 ) {
		return this.help( this );
	}
 
	// output version # from package.json
	Iif ( process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1 ) {
		return this.ver( this );
	}
 
    // turn on strict if strict flag passed
	Iif ( process.argv.indexOf('-s') !== -1 || process.argv.indexOf('--strict') !== -1 ) {
	    this.state.strictMode = true;
	}
 
	// if -c or --config flags used
	Iif ( process.argv.indexOf('-c') !== -1 || process.argv.indexOf('--config') !== -1 ) {
        if ( process.argv.indexOf('-c') !== -1 ) {
            configIndex = process.argv.indexOf('-c');
        }
        else {
            configIndex = process.argv.indexOf('--config');
        }
 
        this.config = this.setConfig( process.argv[ configIndex + 1] );
	}
 
    // fire watch or read based on flag
    Iif ( process.argv.indexOf('-w') !== -1 || process.argv.indexOf('--watch') !== -1 ) {
        return this.watch( this, this.state.dir );
    }
    else {
        return this.read( this, this.state.dir );
    }
});
 
 
// var there be light ( * )
var Lint = stampit().compose(
    flags,
    config,
    state,
    coreMethods,
    testMethods,
    init
).create();
 
 
// var us 'share' our light with others
module.exports = Lint;
// export Lint;