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 CSharpier config #15287

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Add CSharpier config #15287

wants to merge 7 commits into from

Conversation

Skrypt
Copy link
Contributor

@Skrypt Skrypt commented Feb 9, 2024

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

Adds Csharpier configs and VS Code settings for CSharpier.

TODO: Make it a Github Action

See example here: https://github.com/dotnet/arcade/blob/main/.github/workflows/backport-base.yml

@@ -0,0 +1,6 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

I like these values

sebastienros
sebastienros previously approved these changes Feb 15, 2024
@sebastienros
Copy link
Member

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).

@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 15, 2024

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
Copy link
Contributor Author

Skrypt commented Feb 15, 2024

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

Copy link

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

# Conflicts:
#	src/OrchardCore.Modules/OrchardCore.Admin/AdminAreaControllerRouteMapper.cs
#	src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs
#	src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/ValidationRules/MaxNumberOfResultsValidationRule.cs
#	src/OrchardCore.Modules/OrchardCore.AuditTrail/Controllers/AdminController.cs
#	src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ObjectGraphTypeFieldProvider.cs
#	src/OrchardCore.Modules/OrchardCore.ContentFields/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.ContentLocalization/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/AddToDeploymentPlanStartup.cs
#	src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadStartup.cs
#	src/OrchardCore.Modules/OrchardCore.CustomSettings/Drivers/CustomSettingsDisplayDriver.cs
#	src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs
#	src/OrchardCore.Modules/OrchardCore.Google/Authentication/Configuration/GoogleOptionsConfiguration.cs
#	src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs
#	src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs
#	src/OrchardCore.Modules/OrchardCore.Lists/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Controllers/AdminController.cs
#	src/OrchardCore.Modules/OrchardCore.Resources/ResourceManagementOptionsConfiguration.cs
#	src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Sms/Startup.cs
#	src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Configuration/TwitterOptionsConfiguration.cs
#	src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Types/TypedContentTypeBuilder.cs
#	src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchIndexSettingsService.cs
#	src/OrchardCore/OrchardCore.Shells.Azure/Extensions/BlobShellsOrchardCoreBuilderExtensions.cs
#	src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs
"[csharp]": {
"editor.defaultFormatter": "csharpier.csharpier-vscode",
"editor.formatOnSave": true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added VS Code settings

@deanmarcussen
Copy link
Member

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.

👍

@sebastienros
Copy link
Member

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.

@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 16, 2024

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.

Copy link

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

@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 17, 2024

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.

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Feb 17, 2024

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
Copy link
Member

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

@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 19, 2024

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.

dotnet/format#246

@MikeAlhayek
Copy link
Member

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.

@deanmarcussen
Copy link
Member

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.

@sebastienros
Copy link
Member

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

# Conflicts:
#	src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs
#	src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/ExportRemoteInstanceController.cs
#	src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs
#	src/OrchardCore.Modules/OrchardCore.Workflows/Http/Activities/HttpRequestTask.cs
Copy link

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

@sebastienros
Copy link
Member

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

@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 21, 2024

No, there is only few configuration options.

@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 21, 2024

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

@deanmarcussen
Copy link
Member

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

@@ -0,0 +1,6 @@
{
"printWidth": 180,
Copy link
Member

Choose a reason for hiding this comment

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

While opinions on the values of this vary greatly and I couldn't find a scientific answer, 180 seems higher than what everyone recommends. After much deliberation we at Lombiq settled with 120 characters like a decade ago, and it has been working well since, across generations of screen sizes (since it's rather dependent on human anatomy).

@Piedone
Copy link
Member

Piedone commented Mar 22, 2024

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 Piedone added this to the 2.1 milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants