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

Basics of new override ability by extension, which will also allow other file extensions to be formatted. #1251

Merged
merged 14 commits into from
Aug 16, 2024

Conversation

belav
Copy link
Owner

@belav belav commented May 3, 2024

closes #1220

I mostly went with how prettier works for overrides. Using a file glob, a user can specify options to be used for a file. One of those options is which formatter to use. Right now this means non-standard files can be formatted with the csharp formatter. Some day the xml formatting PR will finally get some attention.

@belav belav force-pushed the extensions-for-formatter branch 2 times, most recently from 245efe4 to 21bb5eb Compare May 12, 2024 16:48
@belav belav marked this pull request as ready for review May 31, 2024 17:59
shocklateboy92
shocklateboy92 previously approved these changes Jun 19, 2024
Copy link
Collaborator

@shocklateboy92 shocklateboy92 left a comment

Choose a reason for hiding this comment

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

Bunch of suggestions, including whether partial overrides are supported.

Src/CSharpier.Cli.Tests/CliTests.cs Show resolved Hide resolved
);
if (printerOptions is not null)
{
printerOptions.IncludeGenerated = commandLineOptions.IncludeGenerated;
Copy link
Collaborator

Choose a reason for hiding this comment

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

On an unrelated note, isn't it weird that everything else in CommandLineOptions is about control flow, and just this one is about formatting?

Should we maybe consider removing this option from CLI and have it only in the config files?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I see it as similiar to directoryOrFile option dotnet csharpier <directoryOrFile> which is used to decide which files/folders to format. Currently all the options in in the config file are about what to do when a file is formatted, as opposed to what files to format. Although the new overrides option allows you to include extensions that aren't normally included.

IncludeGenerated does feel weird on PrinterOptions. I couldn't really find a better place to put it.

Long term I think csharpier should transition to what prettier does, where <directoryOrFile> uses globs. So the current command of dotnet csharpier . would be the equivalent of dotnet csharpier **/*.{cs|cst}

directoryInfo = directoryInfo.Parent;

while (directoryInfo is not null)
if (filePath.EndsWith(".cs") || filePath.EndsWith(".csx"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this check has come up in multiple places (including EditorConfigSections.cs). Do you want to extract the extensions to a constant?
Or even create a helper method?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I need to do something with it in https://github.com/belav/csharpier/pull/858/files, because that is going to add csproj/xml formatting. Maybe that is the time to switch the CLI option to use globs. I'll leave it for now and deal with it there, I'm sure there are plenty of conflicts on those lines already.

@belav belav merged commit 28c9bc4 into main Aug 16, 2024
3 checks passed
@belav belav deleted the extensions-for-formatter branch August 16, 2024 17:12
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.

Request for support of custom file extensions to scan/fix
2 participants