csharpier
csharpier copied to clipboard
Unable to configure tab usage
Hi there,
I have went through documentation to check how to configure tab usage in files and it was pretty straightforward so my configuration is like this:
- created
.csharpierrc.json
- added configuration properties shown in attachment.
With this configuration I am still unable to see tabs being used instead of spaces as seen in second picture (git diff). This file is located at the root directory and it is being used locally by git hooks where tool is installed as global tool and in GitLab pipeline so we ensure configuration consistency among environments.
Thanks in advance for any help.
Kind regards!
Hey, Are you using a version prior to 0.17.0? Support for tabs was added then. Otherwise from my testing I believe tabs are working as expected. If you are on 0.17.0+, then maybe it isn't locating the configuration file. CSharpier will search starting in the path it is formatting up through parent directories until it finds one or reaches the root without finding one. Maybe you have another configuration file somewhere without tabs on. It will also look for .csharpierrc, .csharpierrc.json, .csharpierrc.yaml, and .csharpierrc.yml. I don't recall which one takes priority if it finds multiples in a directory. You could also try changing printWidth to something small to see if it is picking up that option but not the tabs option. I tested out invalid json, and that errors out immediately.
Oh and including the option for preprocessorSymbolSets
will slow down formatting. It will reformat each file using those symbols. CSharpier understands how to read basic conditional compilation, the option is there for anyone who has more complex logic in conditional compilation. I should perhaps move it out of the example config to avoid that problem. The rosyln and .net runtime repos are the only place I've really seem complex conditional compilation.
Hi @belav ,
Thanks for answering. I am currently on 0.16.0 version and that is probable cause of this behaviour. I am unable to upgrade to higher versions because we are using .NET 5 and this is highest version that supports .NET 5.
I have question regarding preprocessorSymbolSets
. I am not sure how does this work even though I went throught documentation. Do you have maybe some other example for this ?
Thanks :)
CSharpier requires .NET 6 to run which is independent from the version of .NET that a project is targeting. We have a project at work that still targets .NET 5, but it can be formatted with the latest csharpier. Updating CSharpier would mean anyone on your team plus any build systems would need to have .NET 6 installed which I could still see being a blocker.
For preprocessorSymbolSets
you would only need to set it if you have something with conditional compilation that is not being formatted. CSharpier isn't smart enough to understand something like the following yet
#if FIRST
var willFormat = true;
#elif SECOND && !THIRD
var willFormat = false;
#else
var willFormat = true;
#endif
I believe you'd need to set
"preprocessorSymbolSets": ["FIRST", "SECOND", ""]
The three sets will satisfy the 3 branches of the #if
CSharpier can understand basic conditionals like the following. If you only have basic conditionals, you should just leave preprocessorSymbolSets
out of the configuration file.
#if DEBUG
var willFormat = true;
#else
var willFormat = true;
#endif
Hi @belav,
Thanks for clearing this out, now it is bit more understanable. :)
Kind regards!