Linters and Formatters

In collaborative coding efforts, whether for a website or an embedded device, varying opinions on styling and best practices are inevitable. Code reviews often become a platform for bikeshedding—discussions about seemingly trivial details such as spacing or bracket placement. In my experience, the most reliable method to ensure consistency is to delegate code styling to an algorithm, allowing humans to focus on the essential business logic. Employing a code formatter not only streamlines the process but also minimizes differences, particularly in areas like newlines or other superficial elements.

There are two primary types of code checkers: those that primarily focus on code styling and others that scrutinize code for potential dangers or bad practices. In mature programming languages, a variety of formatters and linters are readily available. The following list is a list of tools I frequently use:

LanguageLinterStyler
PythonPylintBlack
Cclang-tidyclangFormat
.NET/C#dotnet-format
TypeScriptgtsgts (prettier under the hood)

Furthermore, GitHub has developed an internal set of linters and formatters across various languages, consolidated into a tool known as the SuperLinter. This versatile tool seamlessly integrates into GitHub pipelines, offering comprehensive checks for major programming languages.

It is imperative for any serious code development to incorporate these formatters and linters into the workflow, with compliance enforced through continuous integration (CI) checks. Without these checks integrated into the pipeline, achieving consistency becomes a challenge, as individuals may neglect adhering to coding standards.

Written by me and improved by ChatGPT

Leave a Reply

Your email address will not be published. Required fields are marked *