From d81e9aca9e5452ad5fc7c2b723e7f2bff9dc9d98 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 29 Apr 2015 00:33:31 +0200 Subject: [PATCH] Add formatter option to allow registration of custom reporters --- src/cli/common.js | 12 ++++++++++++ src/cli/node.js | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cli/common.js b/src/cli/common.js index 9e2c66d0..44f77bef 100644 --- a/src/cli/common.js +++ b/src/cli/common.js @@ -12,6 +12,7 @@ function cli(api) { var globalOptions = { "help" : { "format" : "", "description" : "Displays this information." }, "format" : { "format" : "", "description" : "Indicate which format to use for output." }, + "formatter" : { "format" : "", "description" : "Path to a formatter to load. Only supported in Node.js" }, "list-rules" : { "format" : "", "description" : "Outputs all of the rules available." }, "quiet" : { "format" : "", "description" : "Only output when errors are present." }, "errors" : { "format" : "", "description" : "Indicate which rules to include as errors." }, @@ -223,6 +224,17 @@ function cli(api) { api.print("csslint: No files specified."); exitCode = 1; } else { + if (api.isNode && options.formatter) { + /*jshint node:true */ + var path = require("path"); + var fullPath = path.resolve(process.cwd(), options.formatter); + + var customFormatter = require(fullPath); + + CSSLint.addFormatter(customFormatter); + /*jshint node:false */ + } + if (!CSSLint.hasFormat(formatId)) { api.print("csslint: Unknown format '" + formatId + "'. Cannot proceed."); exitCode = 1; diff --git a/src/cli/node.js b/src/cli/node.js index 689de36d..f677eeaf 100644 --- a/src/cli/node.js +++ b/src/cli/node.js @@ -75,5 +75,7 @@ cli({ } catch (ex) { return ""; } - } + }, + + isNode: true });