OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Add CSharpier config

Open Skrypt opened this issue 2 years ago • 20 comments

Ran dotnet csharpier . on the root folder of Orchard Core to reformat everything.

Adds Csharpier configs and VS Code settings for CSharpier.

Skrypt avatar Feb 09 '24 03:02 Skrypt

Should it be part of the project? Does it mean someone will run the tool locally? I don't think I would like the CI to block my PR because I missed a space. (I know I don't like it when it happens in other repos, example ImageSharp).

sebastienros avatar Feb 15 '24 19:02 sebastienros

Yes, we will need to run the tool locally to reformat everything at some point. We can also add a VS Code setting so that it be applied on saving the file automatically. I wanted to see if we would adopt it or not first.

Skrypt avatar Feb 15 '24 21:02 Skrypt

Formatting with CSharpier will not be reformatted by Visual Studio afterward from what I've seen so far.

Skrypt avatar Feb 15 '24 21:02 Skrypt

This pull request has merge conflicts. Please resolve those before requesting a review.

github-actions[bot] avatar Feb 16 '24 04:02 github-actions[bot]

Yes I support this.

means no more opinions about what code style to be using. And less noise on prs, saying please format it like this.

I believe it can also be installed on the CI to autoformat and push back, which would be a good future improvement.

👍

deanmarcussen avatar Feb 16 '24 07:02 deanmarcussen

I think it would be nice to create an action that runs it once a week to create a PR automatically.

Side question, why not dotnet-format. It's part of the SDK and it support the editorconfig file which already have our formatting preferences.

sebastienros avatar Feb 16 '24 17:02 sebastienros

Would need to compare it with CSharpier. I believe it supports editorConfig too but maybe not the same way. Need to read documentation.

I have nothing against dotnet-format I did not even know it existed! Let's open a second draft PR to compare.

Skrypt avatar Feb 16 '24 17:02 Skrypt

This pull request has merge conflicts. Please resolve those before requesting a review.

github-actions[bot] avatar Feb 16 '24 17:02 github-actions[bot]

Ok, took a look and tested dotnet-format. The difference is that CSharpier allows to configure a max-length per line which is what we want to achieve (to be able to see code without scrolling left and right all the time).

See https://github.com/dotnet/format/blob/main/docs/Supported-.editorconfig-options.md#core-options

Though, dotnet-format will reorder the usings just like VS do when CTRL + K + D or CTRL + R + G which CSharpier doesn't do.

Also dotnet format was a lot more slower than CSharpier when doing a bulk update.

Skrypt avatar Feb 17 '24 04:02 Skrypt

This will break every PR we have pending. It's the same reason why we have not yet converted all of our classes to use file-scope namespaces.

image

MikeAlhayek avatar Feb 17 '24 22:02 MikeAlhayek

Also, CSharpier does not yet support c#12. Not sure if this is a problem or not for us.

MikeAlhayek avatar Feb 17 '24 22:02 MikeAlhayek

Yes, seems like it has issues with Primary constructors. Does'nt remove the private readonly vars properly. Though we would need to start using it.

Also, dotnet-format on the counterpart doesn't do much line-length wrapping.

https://github.com/dotnet/format/issues/246

Skrypt avatar Feb 19 '24 22:02 Skrypt

I am do not mind the values used. But, I do not want to break every PR as result. But, at some point we would have to decide when to close these old PR so we are able to make this kind of change easily.

MikeAlhayek avatar Feb 19 '24 23:02 MikeAlhayek

you're not breaking every pr, just creating merge conflicts.

resolve the merge conflict from the other pr side, and save it, and it will reformat.

deanmarcussen avatar Feb 19 '24 23:02 deanmarcussen

Maybe ... running the same tool/options only of the modified files in the PRs would fix the merge conflicts

sebastienros avatar Feb 19 '24 23:02 sebastienros

This pull request has merge conflicts. Please resolve those before requesting a review.

github-actions[bot] avatar Feb 21 '24 18:02 github-actions[bot]

Is there an option to remove the trailing comas when multi-lines is converted to single lines? ", }

sebastienros avatar Feb 21 '24 20:02 sebastienros

No, there is only few configuration options.

Skrypt avatar Feb 21 '24 20:02 Skrypt

I guess we would need to combine dotnet-format and CSharpier to get to a complete result with all these options.

Skrypt avatar Feb 21 '24 20:02 Skrypt

yeah the point with CSharpier is that it's opiniated, so has very few options

deanmarcussen avatar Feb 21 '24 20:02 deanmarcussen

I like this, although I got PTSD from the amount of files changed just by getting a glimpse of the number in the top-right tab :D. But we need it automated, otherwise, we'll need to redo it manually all the time. So, either reformat automatically on push from GitHub Actions as others mentioned, or run it with --check and fail the workflow if formatting is missing and require people to do that manually.

Piedone avatar Mar 22 '24 23:03 Piedone

It seems that this pull request didn't really move for quite a while. Is this something you'd like to revisit any time soon or should we close? Please comment if you'd like to pick it up.

github-actions[bot] avatar Jul 02 '24 20:07 github-actions[bot]

Closing this pull request because it has been stale for very long. If you think this is still relevant, feel free to reopen it.

github-actions[bot] avatar Jul 18 '24 00:07 github-actions[bot]