diff --git a/bin/recess b/bin/recess index 69cbcbe..cd0544e 100755 --- a/bin/recess +++ b/bin/recess @@ -25,16 +25,22 @@ 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 @@ -42,7 +48,7 @@ paths = options.argv.remain 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 @@ -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) diff --git a/lib/core.js b/lib/core.js index f10bdc1..8270069 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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) { diff --git a/package.json b/package.json index 722e675..c1233b8 100644 --- a/package.json +++ b/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 (https://github.com/fat)" , "keywords": ["css", "lint"] , "licenses": [ { "type": "Apache-2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0" } ] diff --git a/test/types/lint.js b/test/types/lint.js index d838c17..312e839 100644 --- a/test/types/lint.js +++ b/test/types/lint.js @@ -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) \ No newline at end of file