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

New: Markdown Formatter #4040

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EddyHaigh
Copy link

Pull request checklist

Make sure you:

For non-trivial changes, please make sure you also:

  • Added/Updated related documentation.
  • Added/Updated related tests.

Short description of the change(s)

This change adds a Markdown formatter related to issue: #3962
The new formatter does add some duplication of code between the HTML and Markdown formatter and would benefit from creating a shared formatter utils package.

Copy link
Member

@molant molant left a comment

Choose a reason for hiding this comment

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

Took a quick look between meetings and it's looking great.
Thanks a lot @EddyHaigh !

I left a couple comments but you might want to hold until @sarvaje and @antross can spend sometime before doing anything.

@@ -0,0 +1,86 @@
{
"name": "@hint/formatter-markdown",
"version": "1.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

I believe the first version needs to be 0.0.1 or similar so it gest bumped automatically by our release script.

for (const lang of languagesToCheck) {
const file = path.join(rootPath, lang, messagesFileName);

if (fs.existsSync(file)) { // eslint-disable-line no-sync
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment saying fs.exists is deprecated and that's why we use the sync version?

* @param result The webhint scan result.
*/
/* istanbul ignore next [too hard to test] */
private createMarkdown(result: AnalysisResult) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment with an example of how the markdown should look like?

markdown += `${this.getMessage('hints')}: ${result.hintsCount}`;
markdown += MarkdownHelpers.newLine;

result.categories.forEach((category) => {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about refactoring this a bit to make it easier to read?
Maybe replace each forEach with a map so it can return the content for each one and then you can add them to markdown after a [].join(MardownHelpers.newlLine) or something similar?

Copy link
Author

Choose a reason for hiding this comment

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

@molant I've changed this to use map but I'm not sure if it is right or not.

"@hint/utils-types": "^1.1.0",
"lodash": "^4.17.20",
"fs-extra": "^9.0.1",
"moment": "^2.29.0"
Copy link
Member

Choose a reason for hiding this comment

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

This is a note for the core team:

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should create an issue to replace moment?

Copy link
Member

Choose a reason for hiding this comment

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

Done in #4044

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

I've seen we'have removed it from the HTML formatted so I've removed it from this formatter.

Copy link
Contributor

@sarvaje sarvaje left a comment

Choose a reason for hiding this comment

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

Looking good, just a few things.

@@ -0,0 +1,106 @@
{
"backToTop": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clean this file, I think that most of the strings are not used.

"@hint/utils-types": "^1.1.0",
"lodash": "^4.17.20",
"fs-extra": "^9.0.1",
"moment": "^2.29.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

packages/formatter-markdown/src/formatter.ts Outdated Show resolved Hide resolved
import * as fs from 'fs-extra';

import path = require('path');
import { cwd } from 'process';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Move not local import/requires to the top of the file (fs-extra, path, process)

@@ -0,0 +1,337 @@
import * as path from 'path';
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a lot of duplicated code with the formatter-html maybe it is worth it to open an issue to create a utils-formatter package to refactor both, formatter-html and formatter-markdown.

@webhintio/core thoughts?

* @param level The header level e.g. h3 / ###.
*/
public static createHeader(header: string, level: number): string {
return level > 0 ? ` ${header}`.padStart(1).padStart(header.length + 1 + level, '#') : header;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it padStart(1) necessary?

Copy link
Contributor

@sarvaje sarvaje left a comment

Choose a reason for hiding this comment

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

Thanks for the update!

Just a few more things :)

@@ -0,0 +1,277 @@
# Webhint Report - 2020-10-02T20:19:10.489Z
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to have this as an example.

In my opinion, a shorter version (just one pass and one hint/warning/error) as part of the README.md would be enough.

@molant @antross what do you think?

packages/formatter-markdown/src/formatter.ts Outdated Show resolved Hide resolved
packages/formatter-markdown/src/formatter.ts Show resolved Hide resolved
@EddyHaigh EddyHaigh force-pushed the feature/markdown-formatter branch from 676491f to fa764d3 Compare October 3, 2020 00:21
@EddyHaigh EddyHaigh requested a review from molant October 10, 2020 11:51
@EddyHaigh EddyHaigh force-pushed the feature/markdown-formatter branch 2 times, most recently from e54049e to 705b780 Compare November 12, 2020 00:17
@sanmai-NL
Copy link

@EddyHaigh Looking forward to this.

@antross antross added the agenda label Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants