belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.42k stars 99 forks source link

Request for support of custom file extensions to scan/fix #1220

Closed NovaVoidHowl closed 3 months ago

NovaVoidHowl commented 7 months ago

Request

As it currently stands, it is not possible to scan C# files that have custom extensions (for build/deployment processes etc.) The only work around for this, is to have a special script/process: that changes the extension, runs CSharpier, then puts the extension back.

Concept

Add a config section to the '.csharpierrc.*' that allows the user to pick the file extensions to target ie.

printWidth: 120
useTabs: false
tabWidth: 2
fileExtensions:
  - .cs
  - .cs.custom
belav commented 7 months ago

I have a PR with partly implemented csproj formatting and had the same idea because it made sense to allow someone to use that formatter for xml, props, etc. I'll work on getting the ability to specify formatters for other extensions it into the next release.

One possibility

formatters:
  - type: csharp
    extensions: [ ".cs", ".cs.custom" ]
  - type: xml
    extensions: [ ".xml", ".csproj" ]

Or maybe support it with .editorconfig.

[*.{cs,cs.custom}]
csharpier_formatter = csharp

[*.xml]
csharpier_formatter = xml

I should also take a look at how prettier does this.