Skip to content

chore: enable prettier for markdown files and apply to all files#1139

Closed
virkt25 wants to merge 3 commits intomasterfrom
style/md
Closed

chore: enable prettier for markdown files and apply to all files#1139
virkt25 wants to merge 3 commits intomasterfrom
style/md

Conversation

@virkt25
Copy link
Contributor

@virkt25 virkt25 commented Mar 15, 2018

Changes are broken down into 3 commits.

  1. Add prettier config for markdown scripts (supports GitHub Flavoured Markdown)
  2. Run prettier with new config to fix all files.
  3. Update main README to use reference style for GitHub User profile images

Connected to #1099

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Related API Documentation was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in packages/example-* were updated

@virkt25 virkt25 added this to the March 2018 milestone Mar 15, 2018
@virkt25 virkt25 self-assigned this Mar 15, 2018
@virkt25 virkt25 requested a review from bajtos as a code owner March 15, 2018 16:33
@shimks
Copy link
Contributor

shimks commented Mar 15, 2018

Have these files been manually verified after prettier's been run? If they haven't, should they be verified?

@virkt25
Copy link
Contributor Author

virkt25 commented Mar 15, 2018

Verified in what sense? Prettier changes - to * and applied the 80 character limit to all md files. Don't think it did anything else. I did skim through the files and didn't spot anything else.

Copy link
Contributor

@shimks shimks left a comment

Choose a reason for hiding this comment

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

Just one comment

README.md Outdated
Raymond Feng|Miroslav Bajtos|Ritchie Martori|Kevin Delisle
:-:|:-:|:-:|:-:
[<img src="https://avatars0.githubusercontent.com/u/540892?v=3&s=60">](http://github.com/raymondfeng)|[<img src="https://avatars2.githubusercontent.com/u/1140553?v=3&s=60">](http://github.com/bajtos)|[<img src="https://avatars2.githubusercontent.com/u/462228?v=3&s=60">](http://github.com/ritch)|[<img src="https://avatars3.githubusercontent.com/u/2053534?v=3&s=60">](http://github.com/kjdelisle)
| Raymond Feng | Miroslav Bajtos | Ritchie Martori | Kevin Delisle |
Copy link
Contributor

Choose a reason for hiding this comment

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

The readability is pretty horrendous here. Should we configure prettier so that it doesn't run on tables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to disable it for just tables in md files. Any ideas?

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 it's possible to do it just for tables in prettier. Curious to hear others' opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps prettier/prettier#3211 might help.

Copy link
Contributor Author

@virkt25 virkt25 Mar 15, 2018

Choose a reason for hiding this comment

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

Great find! I've updated the tables (with the exception of @shimks 's image since I'm not sure how to set the height attribute in reference style and GitHub's s=60 isn't working for his Avatar).

"files": "**/*.md",
"options": {
"parser": "markdown",
"proseWrap": "always"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

preserve didn't enforce lines to be max 80 characters in width (which is what I'm trying to achieve with this PR). Hence went with always.

- [ ] Related API Documentation was updated
- [ ] Affected artifact templates in `packages/cli` were updated
- [ ] Affected example projects in `packages/example-*` were updated
* [ ] `npm test` passes on your machine
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, why * is better than -? Is there a configuration option to override?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've looked into this a while ago, and prettier doesn't have configurable list styling, and it doesn't look to be in scope for a while. prettier/prettier#3025

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No config option other than to extend the markdown parser used by prettier and change that there. * and - are treated the same by GFM (GitHub Flavoured Markdown). I think the markdown parser just uses * as it's style.

In VSCode, you can continue using - and saving the file will format it to use * now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Forcing to use * is fairly annoying :-(

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I also like - more than *. However, I am happy to give up this preference in exchange for automated linting & formatting of Markdown files.

Perhaps we can contribute a feature to prettier to make the preference of * vs. - configurable? They already allow configuration of the quote symbol used in JavaScript files (' or "), I think that should serve as a good precedent?

*.json
*.md
CHANGELOG.md
.sandbox
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add packages/*/CHANGELOG.md here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think CHANGELOG.md already covers nesting files with the same name.

[superkhau]: https://avatars1.githubusercontent.com/u/1617364?v=3&s=60
[loay]: https://avatars3.githubusercontent.com/u/1986928?v=3&s=60
[crandmck]: https://avatars2.githubusercontent.com/u/2925364?v=3&s=60
[virkt25]: https://avatars1.githubusercontent.com/u/3311536?v=3&s=60
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@bajtos
Copy link
Member

bajtos commented Mar 16, 2018

+1 for applying Prettier to all markdown files

@virkt25 could you please check that the VS Code extension we use to apply Prettier formatting is correctly configured to reformat Markdown files on save? I remember turning automatic reformatting off - see https://github.com/strongloop/loopback-next/blob/20a41ac7081a8cead0011447b5a8e5794a320ded/.vscode/settings.json#L7-L9

@bajtos
Copy link
Member

bajtos commented Mar 16, 2018

I remember turning automatic reformatting off

Ah, that was done for EJS templates, not markdown - see c1d7a52

@virkt25
Copy link
Contributor Author

virkt25 commented Mar 16, 2018

Yep, the VSCode extension works great in re-formatting the files. It automatically does word wrapping to 80 characters, adjusts tables based on content, changes - to *, etc.

@virkt25 virkt25 force-pushed the style/md branch 2 times, most recently from 62360d7 to f7f713b Compare March 20, 2018 20:44
@virkt25
Copy link
Contributor Author

virkt25 commented Mar 20, 2018

@strongloop/lb-next-dev

Do we want to proceed with this PR or should it be abandoned / closed?

PROS:

  • We get linting on markdown files (80 character word wrap is applied for us automatically ... which should make reviews easier for future.

CONS:

  • Lists switch from - to *. For newly generated lists that use -, prettier will covert them to *. For existing lists, we must use * because otherwise Prettier will treat the new addition of - as a new list as per the CommonMark spec / guidelines. This is a feature of Prettier. It doesn't allow for config of default list bullets. See issue: Prettier mangles lists with mixed list syntaxes prettier/prettier#3871
    By using this plugin https://github.com/neilsustc/vscode-markdown, we can have a newline automatically give us a bullet (same pointer as list). This could be a solution for this issue_

@raymondfeng
Copy link
Contributor

I still feel being forced to use * instead of - is pretty annoying. Please note that we have to use Shift + 8 to type * while - is one key stroke.

@virkt25
Copy link
Contributor Author

virkt25 commented Mar 26, 2018

Closing this as we want prettier to support - for lists instead of * before adding this to linting.

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.

5 participants