Skip to content

feat: Generic pretty-printer implementation#39

Merged
vadimkibana merged 3 commits into
mainfrom
universal-pretty-printer
Mar 6, 2026
Merged

feat: Generic pretty-printer implementation#39
vadimkibana merged 3 commits into
mainfrom
universal-pretty-printer

Conversation

@vadimkibana
Copy link
Copy Markdown
Collaborator

@vadimkibana vadimkibana commented Mar 3, 2026

Summary

Partially addresses: elastic/kibana#242923

See README for detailed description of this library.

Below is an example of how the printer works in a nutshell:

import { text, group, indent, line, softline, join, layout } from './printer';

const doc = group([
  text('SELECT'),
  indent([line, join(
    [text(','), line],
    [text('a'), text('b'), text('c')]
  )]),
  line,
  text('FROM t'),
]);

layout(doc, { printWidth: 40 });
// SELECT
//   a,
//   b,
//   c
// FROM t

layout(doc, { printWidth: 80 });
// SELECT a, b, c FROM t

Details

Technical details, breaking changes or considerations you have made while working in this PR.

Checklist

  • Unit tests have been added or updated.
  • The proper documentation has been added or updated.
  • If this PR contains breaking changes, you have explained them using the BREAKING CHANGE: change syntax.
  • The PR title has the correct conventional commit label in the title, this is crucial for the correct versioning of this package. Check the following cheat shit.
    Title Label Release
    breaking: true (!) major
    feat minor
    fix patch
    refactor patch
    perf patch
    build patch
    docs patch
    chore patch
    revert patch

@vadimkibana vadimkibana force-pushed the universal-pretty-printer branch from 8c17a77 to 53d3cda Compare March 5, 2026 18:26
@vadimkibana vadimkibana changed the title Universal pretty printer Generic pretty-printer implementation Mar 5, 2026
@vadimkibana vadimkibana marked this pull request as ready for review March 5, 2026 18:29
@vadimkibana vadimkibana requested a review from a team as a code owner March 5, 2026 18:29
@vadimkibana vadimkibana changed the title Generic pretty-printer implementation feat: Generic pretty-printer implementation Mar 5, 2026
@stratoula
Copy link
Copy Markdown
Contributor

@vadimkibana are you going to also add a Readme? It will be easier for me to follow the implementation 🙏

@vadimkibana
Copy link
Copy Markdown
Collaborator Author

@stratoula Yes! Here it is.

Comment thread src/printer/README.md
import { text, group, indent, line, softline, join, layout } from './printer';

const doc = group([
text('SELECT'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to use ES|QL examples?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 🤷

Copy link
Copy Markdown
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice! 🙌

expect(text('hello')).toBe('hello');
});

it('returns empty string for empty input', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important 😄

Comment thread src/printer/builders.ts
*
* Like `hardline`, forces enclosing groups to break.
*/
export const literalline: Doc = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const literalline: Doc = [
export const literalLine: Doc = [

Not sure if this is intended but I see we have this format in general so I guess we want to be consistent (?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rename in next PR.

Comment thread src/printer/builders.ts
/**
* Like `literalline` but does NOT force parent group to break.
*/
export const literallineWithoutBreakParent: LineNode = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const literallineWithoutBreakParent: LineNode = {
export const literalLineWithoutBreakParent: LineNode = {

same as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rename in next PR.

@vadimkibana vadimkibana merged commit 3460a26 into main Mar 6, 2026
4 checks passed
@vadimkibana vadimkibana deleted the universal-pretty-printer branch March 6, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants