Site icon Being Software Craftsman (DFTBA)

Consistent C# coding styles in .NET Core and VS 2019

Are you a part of champion C# team who has developers from Different background (JavaScript, Python, Java, Ruby etc.)?

Some of them may prefer their own ways of indentations, placing curly brace locations (JavaScriptish), even not putting them at all (Python-ish).

Curly Brace Conventions by the JavaScript community.
But, C# community prefers that the opening or closing brace within a C# statement, element, or expression should be placed on its own line.


Members from your team have different perspectives over C# coding styles however your team want everyone to follow agreed guideline as if code is written by a single developer and it’s readable?

Are you tired of seeing/receiving linting comments in the C# code reviews?

Multiple violations: Space required after if and closing parenthesis, Extra parenthesis


Do you want to automatically find and fix those as a part of C# code self-reviews?

Omission of curly brace introduced a serious bug. return Buzz will gets always executed.

remove unused variables, remove unused methods, remove unused namespaces and MANY MORE.


Answer to these questions are combination of tools:


If you have a single or multiple project make sure you create a .editorconfig at root level (Solution level) so that all the rules are applicable to all the projects under a solution.

Steps:

A solution with multiple projects (For you it could be 10 or 100 projects)




Error List window in the visual studio showing fixable warnings.

Raise the bar


You can even push yourself and set few rules as errors in the .editorconfigs

Option from IDE to set some guideline as Error and other options.
Set obvious suggestions as an error and some as none to reduce the noise.


Do you want to try it before applying it to your project?

Here is the git repo link:

https://github.com/way2datta/.net-practices/tree/master/Linters




Exit mobile version