Adding csproj formatting
closes #819
The first pass at this was to just use the XmlTextWriter, which fixes indentation to be consistent, but also destroys line breaks.
https://github.com/belav/csharpier-repos/pull/63/files?diff=split&w=1
A notable example

Maybe instead for a first pass this can
- Get indentation consistent
- Clean up extra new lines - maybe new lines separating elements should be allowed, but if there are multiples, then remove them. It seems pretty common for people to leave a blank line between
<ItemGroup>elements. - Get the end element tags consistent -
<Tag/>should be<Tag />
I think that should be pretty easy to do using the existing Doc system.
Then the two remaining things I think are also needed
- A way to specify indentation options by file type. At work we use 2 spaces in csproj, but 4 spaces in cs.
- Maybe a way to specify which file types csharpier should format. I am leaning towards auto including cs, csproj, props and targets. The csharpierignore file is one way someone could opt out of formatting the none c# files. Maybe there should be an option instead? Something like
# this would be the default value
filesToFormat:
- cs
- csproj
- props
- targets
Do you have any thoughts @shocklateboy92 ?
Actually, maybe more like what prettier does. Which can be combined with options for files, and at some point also allow custom formatters
tabWidth: 4
overrides:
- files: "*.csproj"
options:
tabWidth: 2
- files: ["*.props", "*.targets"]
formatter: none
- files: "*.ps1"
formatter: PluginThatFormatsPowershell
😃 Hi there, I am using both csharpier and prettier in my projects and wondering if this would be some duplicate effort.
I have been using prettier for everything besides .cs files (like JSON files), and for .csproj (XML) files there is @prettier/plugin-xml.
The plugin uses linguist-languages to identify XML file types base on extensions, and it already includes file types like .csproj, .props and .targets. The list of extensions for XML can be found here. So far the experience is pretty good.
There may also be tooling concerns (VSCode settings) for including csproj formatting in csharpier. For instance, users may need to set csharpier as the default XML formatter, but is it a good idea?
Anyway, csharpier is a nice tool, and thanks for the effort to keep improving it.
😃 Hi there, I am using both csharpier and prettier in my projects and wondering if this would be some duplicate effort.
I have been using prettier for everything besides .cs files (like JSON files), and for .csproj (XML) files there is @prettier/plugin-xml.
My initial pass for this was just intended to clean up whitespace and indentation, but I already ran into reasons why I think it needs to do a bit more than that and can probably use their code as a starting point. Thanks for sharing the link!
Even if prettier already supports this type of formatting I still see value in csharpier providing the functionality. There are situations where someone may not want to deal with node/npm and still be able to format xml. For a web app, they probably already have node but there are plenty of other types projects out there.