Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any lint tools for C and C++ that check formatting?

I have a codebase that is touched by many people. While most people make an effort to keep the code nicely formatted (e.g. consistent indentation and use of braces), some don't, and even those that do can't always do it because we all use different editors, so settings like spaces vs. tabs are different.

Is there any standard lint tool that checks that code is properly formatted, but doesn't actually change it (like indent but that returns only errors and warnings)?

While this question could be answered generally, my focus is on C and C++, because that's what this project is written in.

like image 501
Nathan Fellman Avatar asked Mar 14 '10 11:03

Nathan Fellman


People also ask

Does C have a linter?

Over the years, different versions of lint have been developed for many C and C++ compilers, and while modern-day compilers have lint-like functions, lint-like tools have also advanced their capabilities.

Is Linting the same as formatting?

A linter will typically report violations, but it's usually up to the programmer to fix the problem, while a code formatter tends to apply its rules directly to the source code, thus correcting formatting mistakes automatically.

What is Linting in C?

Linting is the automated checking of your source code for programmatic and stylistic errors. This is done by using a lint tool (otherwise known as linter). A lint tool is a basic static code analyzer. The term linting originally comes from a Unix utility for C.

Is Prettier a linter?

Prettier can be run as a plugin for ESLint, which allows you to lint and format your code with a single command. Anything you can do to simplify your dev process is a win in my book.


2 Answers

Google uses cpplint. This is their style guide.

like image 99
Nikola Smiljanić Avatar answered Oct 23 '22 10:10

Nikola Smiljanić


The Linux kernel uses a tool that does exactly this - it's called checkpatch. You'd have to modify it to check your coding standards rather than theirs, but it could be a good basis to work from. (It is also designed for C code rather than C++).

like image 25
caf Avatar answered Oct 23 '22 10:10

caf