Linux tool to check spelling of comments in c/c++ source code

Emacs has ispell-comments-and-strings which works pretty well from inside the editor. It relies on the syntax highlighting mechanism to identify comments and strings, so it works with any language for which you have good highlighting.

No idea if how you make it work with your IDE.


I needed something like this too. It needed to be able to run not only on Linux though.

I've seen that spell checking is often paired with an IDE (like with eclipse). I wanted a tool that was completely independent of any IDE however, because I wanted to be able to run it in automated/scripted contexts like Travis-CI builds or AppVeyor CI builds.

Looked around a little for such a tool and then decided to write my own.

What I came up with was pyspellcode which meets these needs. It's a python script that uses clang and hunspell which should readily run on Linux at least. The script:

  1. runs clang to get its AST dump output,
  2. reads through the AST info and finds the comment nodes,
  3. passes the words from those to hunspell for checking, and then
  4. reports back words that weren't recognized.

What was an interesting surprise for me is how deeply clang parses C++ comments even into doxygen elements and embedded HTML markup. This made it possible to use clang's AST to do things like ignore words nested within <code>...</code> blocks and I took advantage of that in the script.

The script's available from GitHub as a Zlib licensed open source project. It's just alpha software at the moment with at least one parsing bug in it but if there's interest in it, I'll give it more priority.

Hope this helps!