Is there a Prettier equivalent for C#? #7000
-
I'm doing a lot of React development at the moment and I'm loving how Prettier is an opinionated way of formatting your code. Essentially, when you run the Format Document command, the file is formatted according to the Prettier rules; it's deterministic so there's essentially only one correct way to write each line of code (I don't think it formats whitespace between lines of code). It would be great if there was a Roslyn Analyser that could do this for you. That is, you spec your styling rules in Is there anything out there that does this and conforms to the rules of the analyser NuGet packages added to your project? For example, if I've add the StyleCop NuGet package and create a few overrides to the StyleCop rules in
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 16 replies
-
Well, both R# and Rider are doing it but they are paid solutions. |
Beta Was this translation helpful? Give feedback.
-
StyleCopAnalyzers is an obvious choice. But I think the project is pretty much dead as there hasn't been a non-beta release for nearly four years and the last beta release was from nearly a year ago. It's also somewhat "old fashioned" in its opinions, so needs a lot of configuring. As long as you are using at least the .NET 5 SDK, the code style analyzers that were previously part of VS (the IDExxxx rules) are now built into the SDK so can be applied in pipelines etc, so they be the better choice for you. See https://learn.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview?view=vs-2022. |
Beta Was this translation helpful? Give feedback.
-
Looks like a small but somewhat active project. I'm going to go out on a limb that perhaps super-opinionated formatters are less important to C# developers, who probably find the options provider out-of-the-box with Visual Studio or |
Beta Was this translation helpful? Give feedback.
-
Yup. W e get the opposite feedback non-stop. That people want an incredibly configurable formatter that will let them tweak each and every potential decision it makes. Our ecosystem tends heavily to personal style and not fiat. |
Beta Was this translation helpful? Give feedback.
See: https://csharpier.com/
Looks like a small but somewhat active project.
I'm going to go out on a limb that perhaps super-opinionated formatters are less important to C# developers, who probably find the options provider out-of-the-box with Visual Studio or
dotnet format
to be sufficient. I'm personally not a fan of super-opinionated formatters and find myself fighting with them in projects that do require their use.