Skip to content

Commit 41a4910

Browse files
committed
Add support for note properties in verbose mode
1 parent 0320c4a commit 41a4910

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function padRight(value, minimum) {
129129
* @param {Object} [options.silent=false] - Do not output
130130
* messages without `fatal` set to true. Also sets
131131
* `quiet` to `true`.
132+
* @param {Object} [options.verbose=false] - Output notes.
132133
* @return {string} - Formatted files.
133134
*/
134135
function reporter(files, options) {
@@ -139,6 +140,7 @@ function reporter(files, options) {
139140
var listing = false;
140141
var summaryColor;
141142
var summary;
143+
var verbose;
142144

143145
if (!files) {
144146
return '';
@@ -152,6 +154,8 @@ function reporter(files, options) {
152154
options = {};
153155
}
154156

157+
verbose = options.verbose || false;
158+
155159
if (options.silent) {
156160
removeNonFatalMessages(files);
157161
}
@@ -214,6 +218,10 @@ function reporter(files, options) {
214218
reason = message.stack;
215219
}
216220

221+
if (verbose && message.note) {
222+
reason += '\n' + message.note;
223+
}
224+
217225
return [
218226
'',
219227
padLeft(location, POSITION_LENGTH),

test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,34 @@ describe('vfile-reporter', function () {
217217
].join('\n'));
218218
});
219219

220+
it('should support `note` in verbose mode', function () {
221+
var file = toVFile('a.js');
222+
var warning = file.warn('Whoops');
223+
224+
warning.note = [
225+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ',
226+
'nulla tellus, ornare sed auctor nec, feugiat sit amet justo. ',
227+
'',
228+
'See http://lipsum.com for more information.'
229+
].join('\n');
230+
231+
file.warn('...and some more warnings');
232+
233+
equal(clean(reporter(file, {
234+
'verbose': true
235+
})), [
236+
'a.js',
237+
' 1:1 warning Whoops',
238+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ',
239+
'nulla tellus, ornare sed auctor nec, feugiat sit amet justo. ',
240+
'',
241+
'See http://lipsum.com for more information.',
242+
' 1:1 warning ...and some more warnings',
243+
'',
244+
'⚠ 2 warnings'
245+
].join('\n'));
246+
});
247+
220248
it('should ignore successful files in `quiet` mode', function () {
221249
var a = toVFile('a.js');
222250
var b = toVFile('b.js');

0 commit comments

Comments
 (0)