Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize should not be mandatory when defining a custom formatter #4293

Closed
TommyMoscatelli opened this issue Jan 5, 2024 · 1 comment
Closed
Labels

Comments

@TommyMoscatelli
Copy link

Which package?

cli-lib

Describe the bug

The current Formatter interface requires to define a custom serialize function.

export interface Formatter {
  serialize: SerializeFn
  format: FormatFn
  compile: CompileFn
  compareMessages?: Comparator
}

But the current code is already checking if serialize is a function, otherwise it applies the default serialization:

if (typeof formatter.serialize === 'function') {
  return formatter.serialize(formatter.format(results as any))
}
return stringify(formatter.format(results as any), {
  space: 2,
  cmp: formatter.compareMessages || undefined,
})

Expected behavior

To apply the default serialization, the formatter interface should be:

export interface Formatter {
  serialize?: SerializeFn
  format: FormatFn
  compile: CompileFn
  compareMessages?: Comparator
}
@TommyMoscatelli TommyMoscatelli changed the title {serialize} should not be mandatory when defining a custom formatter serialize should not be mandatory when defining a custom formatter Jan 5, 2024
@longlho
Copy link
Member

longlho commented Jan 16, 2024

this should be fixed in latest version

@longlho longlho closed this as completed Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants