Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Comparison

Several well-known tools remove comments from source code, and most of them were built for a different job than OComment was. This page is about scope, not quality: each of these does its own job well, and the useful question is which job you have.

The rows below describe each project’s documented purpose and scope, taken from its own documentation, and were not benchmarked or feature-tested here. Tools change; check the current documentation of anything on this page before relying on a row. Only the OComment column describes software this book can check: the rest is read off other projects’ own documentation.

OCommentstrip-commentsdecommentcloc --strip-commentsgcc -E -fpreprocessed
What it isA comment checker and removerA Node.js library and CLI for stripping commentsA Node.js library for stripping commentsA line counter, with a comment-stripping side outputA C preprocessor
Built toReport, gate, and remove comments under a policyStrip comments from JavaScript-style sourceStrip comments while preserving string literalsCount lines of codePreprocess C-family translation units
Language coverage30 languages and 18 dialects, plus declarative profiles and WebAssembly pluginsJavaScript and other C-style syntaxesJavaScript, JSON, CSS, HTMLVery broad, from its own per-language comment tableC, C++, Objective-C, and their preprocessed inputs
Keeps tool directives by defaultYes — shebangs, encoding preambles, //go:build, lint controls, optimiser hints, MySQL versioned commentsDocuments an option for keeping /*! “protected” commentsDocuments an option for keeping /*! “protected” commentsNot a stated goalNot a stated goal
Configurable per pathYes, [[overrides]] globs in .ocomment.tomlThrough the calling programThrough the calling programNoNo
Check-only mode with a CI exit codeYes, ocomment checkNoNoNoNo
Machine-readable reportJSON, JSONL, SARIF, GitHub annotationsNoNoCounts, in several formatsNo
Rewrites files in placeYes, as one rollback-backed transactionThrough the calling programThrough the calling programWrites a stripped copy of each fileWrites to standard output
Non-UTF-8 inputScanned and preserved byte for byteNot statedNot statedNot statedSet by -finput-charset
Keeps line numbersYes under lines and columns, but for the one YAML line a block scalar would read back; compact gives them up by designNot statedNot statedNot statedRewrites line structure, and emits line markers
Editor integrationLSP 3.18 server, VS Code extensionNoNoNoNot applicable
Independent cross-checkAn OCaml reference implementation compared on every fixture
Installs asA single static binary, or a crateAn npm packageAn npm packageA Perl script or packagePart of a C toolchain

When something else is the right tool

  • You want a count, not a rewrite. cloc answers “how much of this is comment?” directly, across more languages than any comment remover needs to support, and writing the stripped copies is a side output of that.
  • You are already inside a Node build step, transforming strings in memory rather than files on disk. A library you can call is less friction than a binary you have to install, and strip-comments and decomment are libraries first.
  • You are preprocessing C anyway. If the compiler is already running over the translation unit, gcc -E has removed the comments as part of the job. Note that it is doing much more than that — macro expansion, includes, line markers — so its output is not the same file minus comments.

What OComment adds

  • A policy, not a switch. A comment that another program reads is not commentary, and the default keeps every one it recognises. See Why was this comment kept?.
  • An answer to “why”. --explain names the rule and the setting behind every decision, which is what makes a house rule reviewable rather than mysterious.
  • A gate. ocomment check exits 1 on findings and speaks SARIF, so the same tool that removes comments can hold a line in CI and in a pre-commit hook. This repository uses it on itself.
  • Bytes in, bytes out. BOMs, CRLF, missing trailing newlines, and non-UTF-8 bytes outside the edited spans survive a rewrite, and every removal is committed as one transaction.
  • A second implementation. The OCaml reference implementation shares no code with the Rust one, and the two are compared on the scanner, the classification, the diagnostics, the edits, the transformed bytes, and the source maps.