Skip to content

Commit

Permalink
Add support for note properties in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 12, 2015
1 parent 0320c4a commit 41a4910
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -139,6 +140,7 @@ function reporter(files, options) {
var listing = false;
var summaryColor;
var summary;
var verbose;

if (!files) {
return '';
Expand All @@ -152,6 +154,8 @@ function reporter(files, options) {
options = {};
}

verbose = options.verbose || false;

if (options.silent) {
removeNonFatalMessages(files);
}
Expand Down Expand Up @@ -214,6 +218,10 @@ function reporter(files, options) {
reason = message.stack;
}

if (verbose && message.note) {
reason += '\n' + message.note;
}

return [
'',
padLeft(location, POSITION_LENGTH),
Expand Down
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 41a4910

Please sign in to comment.