Skip to content

Commit

Permalink
fix "Cannot read property 'red' of undefined" finally
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Aug 19, 2012
1 parent bbe742d commit 6971513
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
11 changes: 9 additions & 2 deletions bin/recess
Expand Up @@ -25,24 +25,30 @@ options = {
, noUniversalSelectors: Boolean
, prefixWhitespace: Boolean
, strictPropertyOrder: Boolean
, version: Boolean
, watch: path
, zeroUnits: Boolean
}

// parse options
options = nopt(options, {}, process.argv)
shorthand = { 'v': ['--version'] };
options = nopt(options, shorthand, process.argv)

// if help exit
if (options.help) return recess.docs()

// set version
recess.version = require(path.join(__dirname, '..', 'package.json')).version
if (options.version) return console.log(recess.version)

// set path from remaining arguments
paths = options.argv.remain

// clean options object
delete options.argv

// check for config or default .recessrc
if (options.config || path.existsSync(config)) {
if (options.config || (fs.existsSync || path.existsSync)(config)) {
config = JSON.parse(fs.readFileSync(options.config || config))
for (i in options) config[i] = options[i]
options = config
Expand All @@ -51,6 +57,7 @@ if (options.config || path.existsSync(config)) {
// set CLI to true
options.cli = true


// if not watch - run Recess
if (!options.watch) return recess(paths, options)

Expand Down
9 changes: 7 additions & 2 deletions lib/core.js
Expand Up @@ -85,8 +85,13 @@ RECESS.prototype = {
// push to errors array
that.errors.push(err)

// less gave up trying to parse the data ;_;
that.log(err.name.red + ": " + err.message + ' of ' + err.filename.yellow + '\n')
if (err.type == 'Parse') {
// parse error
that.log("Parser error".red + (err.filename ? ' in ' + err.filename : '') + '\n')
} else {
// other exception
that.log(err.name.red + ": " + err.message + ' of ' + err.filename.yellow + '\n')
}

// if extract - then log it
err.extract && err.extract.forEach(function (line, index) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ "name": "recess"
, "description": "A simple, attractive code quality tool for CSS built on top of LESS"
, "version": "1.0.4"
, "version": "1.0.5"
, "author": "Jacob Thornton <jacob@twitter.com> (https://github.com/fat)"
, "keywords": ["css", "lint"]
, "licenses": [ { "type": "Apache-2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0" } ]
Expand Down
17 changes: 17 additions & 0 deletions test/types/lint.js
Expand Up @@ -214,4 +214,21 @@ var assert = require('assert')

}()

// Cannot read property 'red' of undefined
!function () {

var Recess = new RECESS.Constructor()
, validate = RECESS.Constructor.prototype.validate

RECESS.Constructor.prototype.validate = noop

Recess.data = ".foo { background:green;; }"

Recess.parse()

assert.notEqual(Recess.output[0], '\u001b[31mParse error\u001b[39m: Cannot read property \'red\' of undefined on line 1');
RECESS.Constructor.prototype.validate = validate

}()

console.log("✓ linting".green)

0 comments on commit 6971513

Please sign in to comment.