Skip to content

Commit

Permalink
add option for stripping colors from linting output
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Apr 18, 2012
1 parent 8291a94 commit 3f2f45c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -19,6 +19,7 @@ OPTIONS
- --compile - compiles your code and outputs it to the terminal. Fixes white space and sort order. Can compile css or less.
- --compress - compress your compiled code.
- --config - accepts a path, which specifies a json config object
- --stripColors - removes color from output (useful when logging)
- --noIDs - doesn't complain about using IDs in your stylesheets
- --noJSPrefix - doesn't complain about styling `.js-` prefixed classnames
- --noOverqualifying - doesn't complain about overqualified selectors (ie: `div#foo.bar`)
Expand Down
2 changes: 2 additions & 0 deletions lib/core.js
Expand Up @@ -33,6 +33,8 @@ RECESS.prototype = {

, log: function (str, force) {

if (this.options.stripColors) str = str.stripColors

// if compiling only write with force flag
if (!this.options.compile || force) {
this.options.cli ? console.log(str) : this.output.push(str)
Expand Down
7 changes: 5 additions & 2 deletions lib/index.js
Expand Up @@ -16,7 +16,7 @@ var RECESS = require('./core')
// define main export
module.exports = function (paths, options, callback) {

var option, i, instances = []
var option, message, i, instances = []

// if no options default to empty object
options = options || {}
Expand All @@ -35,7 +35,9 @@ module.exports = function (paths, options, callback) {

// if not compiling, let user know which files will be linted
if (!options.compile && options.cli) {
console.log("\nAnalyzing the following files: " + ((paths + '').replace(/,/g, ', ') + '\n').grey)
message = "\nAnalyzing the following files: " + ((paths + '').replace(/,/g, ', ') + '\n').grey
options.stripColors && (message = message.stripColors)
console.log(message)
}

// for each path, create a new RECESS instance
Expand Down Expand Up @@ -76,6 +78,7 @@ module.exports.DEFAULTS = RECESS.DEFAULTS = {
, noUniversalSelectors: true
, prefixWhitespace: true
, strictPropertyOrder: true
, stripColors: false
, zeroUnits: true
}

Expand Down
19 changes: 19 additions & 0 deletions test/types/lint.js
Expand Up @@ -14,6 +14,7 @@ var assert = require('assert')
, withCompile

console.log = function (string) { loggedStr = string }

withOutCompile = new RECESS.Constructor(null, { cli: true })
withOutCompile.log('first')
assert.equal(loggedStr, 'first', 'console.log was not called when compile was true')
Expand All @@ -27,6 +28,24 @@ var assert = require('assert')

}()

//--stripColor
!function () {
var log = console.log
, loggedStr
, cliInstance

console.log = function (string) { loggedStr = string }

cliInstance = new RECESS.Constructor(null, { cli: true })
cliInstance.log('hello'.red)
assert.equal(loggedStr, 'hello'.red, 'console.log was called with colored string')
cliInstance = new RECESS.Constructor(null, { cli: true, stripColors: true })
cliInstance.log('hello'.red)
assert.equal(loggedStr, 'hello', 'console.log was called with color stripped string')

console.log = log
}()


//VALIDATIONS.strictPropertyOrder
!function () {
Expand Down

0 comments on commit 3f2f45c

Please sign in to comment.