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

Prettier formatting #550

Merged
merged 4 commits into from
Jan 9, 2025
Merged

Prettier formatting #550

merged 4 commits into from
Jan 9, 2025

Conversation

NC-jsAhonen
Copy link
Contributor

@NC-jsAhonen NC-jsAhonen commented Dec 9, 2024

In some places, the code formatting is a bit off, and some rows are very difficult to read because they are so long.

These changes enable format-on-save feature on mvj-ui repo according to prettier defaults. Please try and see if it works for you, and suggest any changes that come to mind.

It might be necessary to format the whole repo, but I haven't done it yet for this PR yet.

Please test ignoring Robert's "initial to typescript conversion" by running

git config blame.ignoreRevsFile .git-blame-ignore-revs

to set the ignore file in your local git settings, and restarting VSCode. I couldn't make it to work, but perhaps you can.

@juho-kettunen-nc
Copy link
Contributor

Awesome, this will make working in this repository much smoother. Will try later.

@juho-kettunen-nc
Copy link
Contributor

juho-kettunen-nc commented Dec 10, 2024

What settings would you prefer in the .prettierrc for JS files? Maybe the same settings as we currently have in .editorconfig?

  • indent with spaces
  • unix line endings
  • indent size 2 spaces
  • trim trailing whitespace
  • insert final newline

Additionally, looks like the Prettier extension does the following by default, so it would be good to write them out in the config file so we don't get surprised later:

  • add dangling comma
  • semicolons ; at the end of each statement
  • double quotes " for strings instead of single quotes '

Which line length do you prefer? Looks like prettier enforces 80 by default. This is of course a safe default, but we could also allow for 100 or 120 if we prefer.
EDIT: I might prefer 100, because 80 feels a bit claustrophobic with all the necessary type definitions of TS, and 120 might be to long when viewing multiple files side by side even on an ultrawide monitor.

Should we continue using the editorconfig file, or remove it and only use prettierrc? Prettier is expected to understand the editorconfig file, and should override them with those in prettierrc in case of double definitions.

@NC-jsAhonen
Copy link
Contributor Author

@juho-kettunen-nc I added explicit configs

@juho-kettunen-nc
Copy link
Contributor

Thanks, I like these settings. What about you @henrinie-nc ?

@juho-kettunen-nc
Copy link
Contributor

And @NC-jsAhonen , do you have additional settings in mind, or how do you like these proposed settings?

@juho-kettunen-nc
Copy link
Contributor

I tested the new settings on the file src/leases/helpers.ts. The line length setting will influence number of lines in the file, due to new line wrapping:

  • no formatter: ~2900 lines
  • 80 chars per line: ~3900 lines
  • 100 chars per line: ~3600 lines

I liked 100 chars per line, as in the latest commit.

@henrinie-nc
Copy link
Contributor

Thanks, I like these settings. What about you @henrinie-nc ?

I would go with the defaults in order to avoid further discussions about the settings and endless fine tuning. :)

@NC-jsAhonen NC-jsAhonen marked this pull request as ready for review January 9, 2025 09:27
@henrinie-nc
Copy link
Contributor

Lets configure prettier to format only ts and tsx files and reformat the project.

@@ -0,0 +1,8 @@
{
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.

Done

@juho-kettunen-nc
Copy link
Contributor

Please test ignoring Robert's "initial to typescript conversion" by running

git config blame.ignoreRevsFile .git-blame-ignore-revs

to set the ignore file in your local git settings, and restarting VSCode. I couldn't make it to work, but perhaps you can.

This works for me, it ignores both your prettier formatting and Robert's typescript conversion, but only when the ignored commit is NOT the first commit of that line's timeline.

For example, line 9 of src/api/callApi.ts was changed in both your and Robert's commit, but I only see blame from 6 years ago. On the other hand, some other file whose history starts with the typescript conversion will show blame for the initial commit, even if that commit is on the ignore list.

Copy link
Contributor

@henrinie-nc henrinie-nc left a comment

Choose a reason for hiding this comment

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

good to go

@NC-jsAhonen NC-jsAhonen merged commit 20a7b50 into develop Jan 9, 2025
3 checks passed
@NC-jsAhonen NC-jsAhonen deleted the prettier-formatting branch January 9, 2025 12:30
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.

3 participants