Search code examples
c#stylecopdotnet-clidotnet-format

How to use `dotnet format` to apply specific StyleCop rule globally?


I have installed StyleCop.Analyzers on my project that is written using C#. The rules severity are set to suggestion.

How can I apply specific rules on the entire project using dotnet format?

I tried executing dotnet format SolutionName.sln --diagnostics SA1122 to convert all "" to string.Empty. Many files were updated (file timestamp changed), but none of the "" were replaced by string.Empty as expected.

How can I use dotnet format to apply specific format rule globally so I don't have to manually make the changes?


Solution

  • This maybe an issue in the CLI command. It works when used with other arguments like --severity info

    dotnet format SolutionName.sln --severity info --diagnostics SA1122