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

format report output #635

Closed
4 tasks
BioPhoton opened this issue Apr 17, 2024 · 3 comments
Closed
4 tasks

format report output #635

BioPhoton opened this issue Apr 17, 2024 · 3 comments
Labels
➕ enhancement new feature or request 🧩 utils 🤓 UX UX improvement for CLI users

Comments

@BioPhoton
Copy link
Collaborator

User story

As a reader of the CLI reports I want to be able to easily consume the generated information.
Formatting is key here. Even if many IDEs support a markdown viewer or auto-format JSON files, it still helps to be able to read the reports in a plain editor.

The current output of the markdown format is not formatted.

Acceptance criteria

  • implement helper form text formatting by wrapping prettier
    • accept the content to format and a optional argument for the format
  • format all markdown formats accordingly
  • ensure formatting is given over snapshot tests

Implementation details

Prettier wrapper:

// packages/utils/src/lib/formatting.ts
import { format, Options } from 'prettier';

export function formatText(
  content: string,
  parser: Options['parser'] = 'typescript'
) {
  return format(content, {
    parser
  }).trim();
}

Markdown helper:

// packages/utils/src/lib/report/md/table.ts
import { formatText } from '../formatting';

export function tableHtml(data: (string | number)[][]): string {
  if (data.length === 0) {
    throw new Error("Data can't be empty");
  }

  const tableContent = data.map((arr, index) => {
    if (index === 0) {
      const headerRow = arr.map(s => `<th>${s}</th>`).join('');
      return `<tr>${headerRow}</tr>`;
    }
    const row = arr.map(s => `<td>${s}</td>`).join('');
    return `<tr>${row}</tr>`;
  });
  return formatText(`<table>${tableContent.join('')}</table>`;
}
@BioPhoton BioPhoton added ➕ enhancement new feature or request 🤓 UX UX improvement for CLI users 🧩 utils labels Apr 17, 2024
@matejchalk
Copy link
Collaborator

We should check if prettier is installed and run it if available. That way we don't have to list an extra dependency.

@BioPhoton
Copy link
Collaborator Author

I believe this one was closed by the new md-build library.
Cc @matejchalk

@matejchalk
Copy link
Collaborator

Indeed, after #755 was merged the tables have padding and alignment to make the source more readable. In general, the output should be prettified already, so there's no need to run Prettier afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
➕ enhancement new feature or request 🧩 utils 🤓 UX UX improvement for CLI users
Projects
None yet
Development

No branches or pull requests

2 participants