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

Add Prettier Formatting for Markdown Files and Pre-Commit Hook #543

Merged
merged 3 commits into from
Feb 3, 2024

Conversation

MarvNC
Copy link
Member

@MarvNC MarvNC commented Jan 19, 2024

  • Adds Prettier
  • Adds .prettierconfig currently with the only rule being proseWrap: true
  • Adds prettierignore set to ignore everything except markdown files
  • Adds pre-commit hook

Maybe this could eventually be expanded to cover the code as well (#517 )

Copy link

github-actions bot commented Jan 19, 2024

✔️ No visual differences introduced by this PR.

View Playwright Report (note: open the "playwright-report" artifact)

@MarvNC MarvNC marked this pull request as ready for review January 19, 2024 01:16
@MarvNC MarvNC requested a review from a team as a code owner January 19, 2024 01:16
@toasted-nutbread
Copy link

This may be a personal taste thing, so others feel free to chime in with any related opinions, but i think 80 character line limits (or "targets", as prettier is reporting to not be a true limit) is always way too short. Perhaps it doesn't matter since at the end of the day, Github ignores that for the most part, and maybe others feel differently. IMO if something is going to use a line limit, 120 is a bit more tolerable.

Unrelated: it's almost unbelievable how awful complex C++ code can look with an auto-formatter with an 80 character line limit :(

@MarvNC
Copy link
Member Author

MarvNC commented Jan 19, 2024

I was considering changing that to 100 but figured defaults are generally preferred, I'd support a wider width for readmes. I find 80 width fine though for code as it prevents too much wrapping from happening when you have two editors open side to side on a small screen.

Copy link
Member

@Casheeew Casheeew left a comment

Choose a reason for hiding this comment

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

Prettier seems to do a lot of stuff that eslint stylistic can already do, which we are already using one of their plugins (stylistic/eslint-plugin-ts).
prose-wrap can be achieved by https://eslint.style/rules/js/max-len. Adding prettier means having to maintain a bunch more config files and one more github action.

Is there anything prettier can do that stylistic cant that I might not know of?

CONTRIBUTING.md Outdated Show resolved Hide resolved
@MarvNC
Copy link
Member Author

MarvNC commented Jan 19, 2024

Prettier seems to do a lot of stuff that eslint stylistic can already do, which we are already using one of their plugins (stylistic/eslint-plugin-ts). prose-wrap can be achieved by https://eslint.style/rules/js/max-len. Adding prettier means having to maintain a bunch more config files and one more github action.

Is there anything prettier can do that stylistic cant that I might not know of?

I wasn't aware, but from what I understand, eslint is more intended to lint and catch issues while prettier is intended to actually make decisions about formatting. Stylistic doesn't seem to support markdown from what I'm finding.

package.json Outdated Show resolved Hide resolved
@MarvNC MarvNC changed the title Add Prettier Formatting for Markdown Files Add Prettier Formatting for Markdown Files and Pre-Commit Hook Jan 21, 2024
djahandarie
djahandarie previously approved these changes Jan 27, 2024
Copy link
Collaborator

@djahandarie djahandarie left a comment

Choose a reason for hiding this comment

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

LGTM now that the scope is just for markdown. Though needs conflict resolution. @MarvNC

@MarvNC
Copy link
Member Author

MarvNC commented Jan 27, 2024

LGTM now that the scope is just for markdown. Though needs conflict resolution. @MarvNC

Thanks, done. @djahandarie do you have any opinions on changing the print width?

@djahandarie
Copy link
Collaborator

djahandarie commented Jan 31, 2024

@MarvNC Honestly, I'm against max line lengths and auto-wrapping, I think it's better for editors of files to be able to use line breaks with some semantic meaning (i.e., indicating some actual unit or separation of interest), with further concerns like overflow left to each viewer's editing environment.

@MarvNC
Copy link
Member Author

MarvNC commented Jan 31, 2024

@djahandarie I think it's more annoying to have no wrapping for markdown. If you choose to manually break you'll have to re-break every time you edit the text, and lengths will never be consistent and it's just more effort to break. Single line breaks have no semantic meaning after being rendered since you need a double break and I don't see much reason for giving them meaning that's only visible when viewing the raw md. Never linebreaking and relying on editor word wrap is a solution, but it's not too accessible depending on what editor you use, and word wrap can make viewing tables very annoying so I don't prefer it.

@toasted-nutbread
Copy link

toasted-nutbread commented Feb 1, 2024

Throwing another thought in here, but I don't really have a strong opinion either way, at least not until there is an obvious ugly situation in practice:

Mandatory line length limits have the potential to cause a lot of diffs when changing a small section of a larger paragraph, since it has to reorganize the entire block. The way I've generally approached markdown source is that I manually word wrap at sentence or fragment boundaries (i.e. at a period or comma), or if I feel the line gets to be unreasonably long (e.g. when embedding URLs).

If I want the raw source to word wrap, most editors have a feature to do this. For example, VSCode word wraps markdown files by default.

@djahandarie
Copy link
Collaborator

@MarvNC FWIW I basically 100% agree with toasted-nutbread here

@MarvNC
Copy link
Member Author

MarvNC commented Feb 3, 2024

My reason for wanting this is that I always format when I edit stuff, and so if I were to edit markdown there would be a bunch of unnecessary diffs (even without word wrap). I guess it's not a big deal though, and maybe not worth adding the hook to change some random * to - and enforce some indentation/line breaks in places.

@MarvNC MarvNC closed this Feb 3, 2024
@djahandarie
Copy link
Collaborator

My reason for wanting this is that I always format when I edit stuff, and so if I were to edit markdown there would be a bunch of unnecessary diffs (even without word wrap)

Not sure I understand... there is agreement that we want a formatter, for the exact reason you state (i.e., auto-formatting results in more consistent output and reduced diff noise). The discussion is just regarding word wrapping settings within that.

If we just disable the wrapping here, won't your editor also not wrap? Or does it forcefully wrap everything regardless of what we do in this PR?

maybe not worth adding the hook to change some random * to - and enforce some indentation/line breaks in places.

What's the downside? Seems fine to me to have it for those things.

@MarvNC
Copy link
Member Author

MarvNC commented Feb 3, 2024

If we just disable the wrapping here, won't your editor also not wrap? Or does it forcefully wrap everything regardless of what we do in this PR?

Sorry, I misunderstood 😅
I'll redo this branch without word wrap applied.

@MarvNC MarvNC reopened this Feb 3, 2024
@MarvNC MarvNC force-pushed the prettier-markdown branch 2 times, most recently from f9a11fc to 735d7ca Compare February 3, 2024 04:05
@MarvNC
Copy link
Member Author

MarvNC commented Feb 3, 2024

Okay, there should be no visible changes in the markdown files now.

...why are there conflicts, nvm

@MarvNC MarvNC closed this Feb 3, 2024
@MarvNC MarvNC force-pushed the prettier-markdown branch from 735d7ca to d7db65a Compare February 3, 2024 04:18
@MarvNC MarvNC reopened this Feb 3, 2024
@djahandarie djahandarie added this pull request to the merge queue Feb 3, 2024
Merged via the queue into yomidevs:master with commit 97c5c74 Feb 3, 2024
10 of 11 checks passed
@MarvNC MarvNC deleted the prettier-markdown branch February 3, 2024 04:48
@djahandarie djahandarie added the kind/meta The issue or PR is meta label Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/meta The issue or PR is meta
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants