Introduction

In the current era of open source projects with numerous diverse contributors from different organizations and different parts of the world, one of the primary requirements of maintaining any repo is enforcing code style guidelines across the code base. Historically, this has been done through exhaustive documentation and code reviews to catch any violations of these coding guidelines. However, this approach has its flaws and requires a lot of man hours on maintaining the documentation and performing exhaustive code reviews.

With the automated code style and naming rules that are built into Visual Studio 2017, users can customize and configure the enforcement levels for individual rules and prompt visual indicators for violations, such as suggestions or squiggles in the editor and diagnostics in the error list, with appropriate severity (error/warning/informational message). Additionally, the rules come with a code fix that can automatically fix one or more instances of the violations across the document, project, or solution. With the new EditorConfig support in Visual Studio 2017, these rule configurations can be enforced and customized at each folder level via an .editorconfig file. Additionally, the .editorconfig files can be checked into the repo alongside the sources so that the rules are enforced for every user that contributes to the repo.

EditorConfig (http://editorconfig.org/) is an open source file format that helps developers configure and enforce formatting and code style conventions to achieve consistent, more readable codebases. EditorConfig files are easily checked into source control and are applied at repository and project levels. EditorConfig conventions override their equivalents in your personal settings, such that the conventions of the codebase take precedence over the individual developer.

In this chapter, we will introduce you to these code style rules, show you how to configure them in the Visual Studio 2017 IDE, and save these settings into an EditorConfig file. Additionally, we will introduce you to a very popular third-party Roslyn analyzer, the PublicAPI analyzer, that allows tracking the public API surface of .NET assemblies through additional non-source text files checked into the repo, and provides diagnostics and code fixes when there is a breaking API change or a new addition to the public API that is not documented in the public API files. We will also walk you through configuring StyleCop analyzers for a .NET project, a popular third-party code style analyzer, and an alternative to the built-in Visual Studio code style rules for enforcing code style.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset