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

Improve formatting configuration #2183

Conversation

ahobsonsayers
Copy link
Contributor

@ahobsonsayers ahobsonsayers commented Oct 5, 2023

When developing my first contrbution to this repo in #2182 , I noticed that the configuration of the formatting could be improved slightly to help people developing in VSCode and other IDEs, as well as aid with keeping consistent formatting across the codebase - assuming this is what you want. This was particularly relevant to me as I noticed when editing some existing files in my other PR, that my IDE was trying to format it differently to how it currently was, which i had to be careful to avoid.

I have moved your prettier config from the vscode settings to a .prettierrc file so that it is IDE agnostic - vetur will still use this config. Additionally i have added prettier to the dev dependancies and added a task to run prettier across all files should you wish to do this at some point (I did not run this for this PR).

I hope these improvements simply help contributers know the formatting this project would like, allows them to easily ensure they are meeting the style and helps avoid changing the formatting of existing files.

If this is not what is wanted, please let me know, it just seemed like an easy win that I think is helpful (well for me at least)

@mfcar
Copy link
Contributor

mfcar commented Oct 5, 2023

Hey @ahobsonsayers, I think this is a great addition. Sometimes I have problems because I use a different IDE (WebStorm), and always forget to check the formatting with vscode.

Can you add an EditorConfig file? Prettier enforces formatting after saving, while EditorConfig enforces formatting during editing. (https://stackoverflow.com/questions/48363647/editorconfig-vs-eslint-vs-prettier-is-it-worthwhile-to-use-them-all#comment110968436_48471763)

I started to use this on the project:

root = true

[*]
indent_style = space
indent_size = 2
insert_final_newline = false
charset = utf-8
trim_trailing_whitespace = true

@ahobsonsayers
Copy link
Contributor Author

ahobsonsayers commented Oct 5, 2023

Great idea @mfcar! I have now added an .editorconfig in a new commit. I also use EditorConfig myself but was unsure if this project wanted to use it so i didnt want to assume.

I have also added equivalent settings to the vscode json for those that use vscode but dont have the editorconfig extension (although i have added the editor config extension as a workspace recommendation!)

One caveat is that prettier does not allow cofiguring whether a final new line is inserted or not. It is very opinionated on this and there is no way to change its behaviour on this

References about this:

Out of interest, what is the reason for no trailing newline? Im not bothered by it either way, but im interested in the choice 🙂

@mfcar
Copy link
Contributor

mfcar commented Oct 5, 2023

Out of interest, what is the reason for no trailing newline? Im not bothered by it either way, but im interested in the choice 🙂

I've noticed that many files don't have an empty line at the end, but as a personal preference, I prefer having an empty new line. In my opinion, it helps me better distinguish the end of the file 😁

@ahobsonsayers
Copy link
Contributor Author

I also prefer a new line at the end of the file, and there are a lot of good reasons why it is good practice too.

Maybe it is ok then that prettier enforces the new line at the end, better than having a mixture of some files with it and some files without right? Consistency is king! Is this something that this project is going to be ok with?

@advplyr
Copy link
Owner

advplyr commented Oct 7, 2023

I'm good with enforcing a newline at the end of the file.

I've been testing the format command and getting this warning:

[warn] Ignored unknown option { editorconfig: true }.

There are a few changes prettier is making that I'll have to get used to but I think this is great.

@ahobsonsayers
Copy link
Contributor Author

Thanks for the reply @advplyr

I'm good with enforcing a newline at the end of the file.

Wonderful, i have updated the config in the latest commit to reflect this.

I've been testing the format command and getting this warning

Thanks for spotting this. Fixed it in the latest commit by removing it. Related to this issue: prettier/prettier#6176

@advplyr
Copy link
Owner

advplyr commented Apr 30, 2024

I ended up putting this in cb1ebd4 excluding the prettier formatter for now since that was updating every file that I couldn't review in one sitting. Mentioned here #2853 (comment)
Thanks!

@advplyr advplyr closed this Apr 30, 2024
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