-
Notifications
You must be signed in to change notification settings - Fork 692
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
base: main
Are you sure you want to change the base?
New: Markdown Formatter #4040
Conversation
There was a problem hiding this 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", |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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:
- We are using version 2.28.0 in another package (maybe that's why
yarn.lock
gets updated?) - moment is considered legacy now by their team, we should think about moving to other alternatives
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #4044
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
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.
There was a problem hiding this 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": { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
import * as fs from 'fs-extra'; | ||
|
||
import path = require('path'); | ||
import { cwd } from 'process'; |
There was a problem hiding this comment.
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/require
s to the top of the file (fs-extra
, path
, process
)
@@ -0,0 +1,337 @@ | |||
import * as path from 'path'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
676491f
to
fa764d3
Compare
e54049e
to
705b780
Compare
@EddyHaigh Looking forward to this. |
a7fa443
to
50764d4
Compare
Pull request checklist
Make sure you:
For non-trivial changes, please make sure you also:
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.