Many programmers pay little attention to the whitespace in their source code, such as spaces, tabs, new-lines, etc. The common thinking is that compilers (C, C++, etc.) ignore whitespace anyway, so why bother? But, as a professional software developer you should not ignore whitespace, because it can cause all sorts of problems, some of them illustrated in the figure below:
QClean is a simple and blazingly fast command-line utility to automatically clean whitespace in your source code. QClean is deployed as a natively compiled executable and is located in the sub-directory qtools/bin/. QClean is available in portable source code and can be compiled on all desktop platforms (Windows and POSIX—Linux, macOS...).
Typically, you invoke QClean from a command-line prompt without any parameters. In that case, QClean will clean up white space in the current directory and recursively in all its sub-directories.
PATH
environment variable (see Installing QTools), you can run qclean
directly from your terminal window.As you can see in the screen shot above, QClean processes the files and prints out the names of the cleaned up files. Also, you get information as to what has been cleaned, for example, "Trail-WS" means that trailing whitespace has been cleaned up. Other possibilities are: "CR" (cleaned up DOS/Windows (CR) end-of-lines), "LF" (cleaned up Unix (LF) end-of-lines), and "Tabs" (replaced Tabs with spaces).
QClean takes the following command-line parameters:
PARAMETER | DEFAULT | COMMENT |
---|---|---|
[root-dir] | . | root directory to clean (relative or absolute) |
OPTIONS | ||
-h | help (show help message and exit) | |
-q | query only (no cleanup when -q present) | |
-r | check also read-only files | |
-l[limit] | 80 | line length limit (not checked when -l absent) |
QClean fixes the following whitespace problems:
-l
option, default 80 characters per line).QClean applies the following rules for cleaning the whitespace depending on the file types:
FILE TYPE | END-OF-LINE | TRAILING WS | TABS | LONG-LINES |
---|---|---|---|---|
.c | Unix (LF) | remove | replace | check |
.h | Unix (LF) | remove | replace | check |
.cpp | Unix (LF) | remove | replace | check |
.hpp | Unix (LF) | remove | replace | check |
.s/.S | Unix (LF) | remove | replace | check |
.asm | Unix (LF) | remove | replace | check |
.txt | Unix (LF) | remove | replace | don't check |
.xml | Unix (LF) | remove | replace | don't check |
.dox | Unix (LF) | remove | replace | don't check |
.md | Unix (LF) | remove | replace | don't check |
.bat | Unix (LF) | remove | replace | don't check |
.ld | Unix (LF) | remove | replace | check |
.py | Unix (LF) | remove | replace | check |
.pyw | Unix (LF) | remove | replace | check |
.java | Unix (LF) | remove | replace | check |
Makefile | Unix (LF) | remove | leave | check |
mak_* | Unix (LF) | remove | leave | check |
.mak | Unix (LF) | remove | leave | check |
.make | Unix (LF) | remove | leave | check |
.html | Unix (LF) | remove | replace | don't check |
.htm | Unix (LF) | remove | replace | don't check |
.css | Unix (LF) | remove | replace | don't check |
.eww | Unix (LF) | remove | replace | don't check |
.ewp | Unix (LF) | remove | replace | don't check |
.ewd | Unix (LF) | remove | replace | don't check |
.icf | Unix (LF) | remove | replace | don't check |
.sln | Unix (LF) | remove | replace | don't check |
.vcxproj | Unix (LF) | remove | replace | don't check |
.filters | Unix (LF) | remove | replace | don't check |
.vcxproj.filters | Unix (LF) | remove | replace | don't check |
.project | Unix (LF) | remove | replace | don't check |
.cproject | Unix (LF) | remove | replace | don't check |
.pro | Unix (LF) | remove | replace | don't check |
.m | Unix (LF) | remove | replace | check |
.lnt | Unix (LF) | remove | replace | check |
.cfg | Unix (LF) | remove | replace | don't check |
.properties | Unix (LF) | remove | replace | don't check |
l_fileTypes
in the qclean/source/main.c
file. Also, you can change the Tab size by modifying the TAB_SIZE
constant (currently set to 4) as well as the default line-limit by modifying the LINE_LIMIT
constant (currently set to 80) at the top of the qclean/source/main.c
file. Of course, after any such modification, you need to re-build the QClean executable and copy it into the qtools/bin directory.