From 41a4910fdc75b309b63e4b438a44e7a00b439aff Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 12 Sep 2015 19:20:05 +0200 Subject: [PATCH] Add support for `note` properties in `verbose` mode --- index.js | 8 ++++++++ test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/index.js b/index.js index 7c2d8ff..8b9dc26 100644 --- a/index.js +++ b/index.js @@ -129,6 +129,7 @@ function padRight(value, minimum) { * @param {Object} [options.silent=false] - Do not output * messages without `fatal` set to true. Also sets * `quiet` to `true`. + * @param {Object} [options.verbose=false] - Output notes. * @return {string} - Formatted files. */ function reporter(files, options) { @@ -139,6 +140,7 @@ function reporter(files, options) { var listing = false; var summaryColor; var summary; + var verbose; if (!files) { return ''; @@ -152,6 +154,8 @@ function reporter(files, options) { options = {}; } + verbose = options.verbose || false; + if (options.silent) { removeNonFatalMessages(files); } @@ -214,6 +218,10 @@ function reporter(files, options) { reason = message.stack; } + if (verbose && message.note) { + reason += '\n' + message.note; + } + return [ '', padLeft(location, POSITION_LENGTH), diff --git a/test.js b/test.js index 594811d..561fa06 100644 --- a/test.js +++ b/test.js @@ -217,6 +217,34 @@ describe('vfile-reporter', function () { ].join('\n')); }); + it('should support `note` in verbose mode', function () { + var file = toVFile('a.js'); + var warning = file.warn('Whoops'); + + warning.note = [ + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ', + 'nulla tellus, ornare sed auctor nec, feugiat sit amet justo. ', + '', + 'See http://lipsum.com for more information.' + ].join('\n'); + + file.warn('...and some more warnings'); + + equal(clean(reporter(file, { + 'verbose': true + })), [ + 'a.js', + ' 1:1 warning Whoops', + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ', + 'nulla tellus, ornare sed auctor nec, feugiat sit amet justo. ', + '', + 'See http://lipsum.com for more information.', + ' 1:1 warning ...and some more warnings', + '', + '⚠ 2 warnings' + ].join('\n')); + }); + it('should ignore successful files in `quiet` mode', function () { var a = toVFile('a.js'); var b = toVFile('b.js');