Skip to content

Commit

Permalink
Add verbose option for more info
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 21, 2023
1 parent b2005e4 commit f44e365
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/file-set-pipeline/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export async function log(context, settings) {
...settings.reporterOptions,
color: settings.color,
quiet: settings.quiet,
silent: settings.silent
silent: settings.silent,
verbose: settings.verbose
}
)

Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
* Whether to treat input as a syntax tree (default: `options.tree`).
* @property {boolean | undefined} [treeOut]
* Whether to output as a syntax tree (default: `options.tree`).
* @property {boolean | undefined} [verbose=false]
* Report extra info (default: `false`); given to the reporter.
*
* @typedef Settings
* Resolved {@link Options `Options`} passed around.
Expand Down Expand Up @@ -182,6 +184,7 @@
* @property {Options['silent']} silent
* @property {Options['quiet']} quiet
* @property {Options['frail']} frail
* @property {Options['verbose']} verbose
*
* @callback VFileReporter
* Reporter.
Expand Down Expand Up @@ -368,6 +371,7 @@ export function engine(options, callback) {
settings.silent = options.silent
settings.quiet = options.quiet
settings.frail = options.frail
settings.verbose = options.verbose

// Process.
fileSetPipeline.run({files: settings.files}, settings, next)
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ Configuration (TypeScript type).
— whether to treat input as a syntax tree
* `treeOut` (`boolean`, default: `options.tree`)
— whether to output as a syntax tree
* `verbose` (`boolean`, default: `false`)
— report extra info; given to the reporter
### `Preset`
Expand Down
38 changes: 38 additions & 0 deletions test/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,44 @@ test('reporting', async function (t) {
}
)

await t.test('should report extra info w/ `verbose`', async function () {
const stderr = spy()

const code = await run({
cwd: new URL('one-file/', fixtures),
extensions: ['txt'],
files: ['.'],
processor: noop().use(
/** @type {import('unified').Plugin<[], Literal>} */
function () {
return function (_, file) {
const message = file.message('x')
message.url = 'https://example.com'
message.note = 'lorem ipsum'
}
}
),
streamError: stderr.stream,
verbose: true
})

assert.equal(code, 0)
assert.equal(
stderr(),
[
'one.txt',
' warning x',
' [url]:',
' https://example.com',
' [note]:',
' lorem ipsum',
'',
'⚠ 1 warning',
''
].join('\n')
)
})

await t.test('should support custom given reporters', async function () {
const stderr = spy()

Expand Down

0 comments on commit f44e365

Please sign in to comment.