cytopia / docker-file-lint

Alpine-based Docker image to perform generic file checks on your source code in order to improve consistency within your repository (e.g. for easy usage in CI).
MIT License
13 stars 4 forks source link

file-nullbyte messes up terminal (when run against binary files?) #14

Open kbabioch opened 4 years ago

kbabioch commented 4 years ago

The file-nullbyte check seems to mess up terminals. I've checked it on multiple *nix machines (Linux, macOS) and the terminals are only showing "weird" characters and/or behave strangely, after the following command is run:

docker run --rm -v $(pwd):/data cytopia/file-lint file-nullbyte --path .

$(pwd) is the checked out repository, and contains some binary files inside the .git/ directory

The result looks something like this:

W7Om,ҧ)ӘG2
R2        iG:U!%{|=7h>r$rCzيZWbnڒ0[~`ٻ@|?B屙QlW`/UA=~F};aL_ٚ1xmIo@Mܬ
m99φiXn t?0LӚbΤy`QV(oWiƯk0vUpC6`yn]s_I+}R*g\7r3A@B{<lkuH5nY?$ebxjbBxiX9MyCgm5؈c$1qP&uQUF        xYÙx</JNI?6,D"(A(r)N<
                                                                            r$R%T-@&^(~%Yk175,c1omiwziìĿXC7;zgY6co<
                                                                                                                   fwSXSdme^Z(NЉ*lw]Tl3
                                                                                                                                       g<k..NL(K)hv9&5տlX9=-k
W3~?lwKzBwEP?Wipx|4q.YF1~K93e36ef28bb545f9c4650c7f13ce2f59b442180.pack:|* #*-2Ds*2E%к<  d_xږGՕYSOb9'YIz9sU_~^ @wYdrҴ:x/U5ӧHtYaYbNla|0m쇷k7XYpi1;
                          *h#!o<Ov6thOQ]&r5Sk$wɄ_N>VSh"ldRD@nt?|hk]fi7Li9(i؄TP
                                                                             k,ć|9g4}w0
                                                                                       nrua,
;r͎¨rvz֍Ki+d瑿AAeOV\cp?Z,<*f{woYvMSTytVnZ*                                                   F9W_̲D037웨5yi{:0~PgBӌĥ-]w˷z         ەG3L:#;@X*
                                         :i6bp?%XF?R    ѮCSa8[fOga1xmKs@ڣ"Hb}dOSWW35UNTE
./.git/objects/pack/pack-693e36ef28bb545f9c4650c7f13ce2f59b442180.pack:BrR1Ρ$AEgͤyLi(UXIDDAD!%5S          CAMV   !PCrOC<34EU'
qsɽM)epKũ                                                                                                                   U@ ⶮa`XŰ)xlZκjzΊ!,벾2Lo -OE[O.\z#6tXz`/Ѥbk8j^׳'k^؍fgOv
./.git/objects/pack/pack-693e36ef28bb545f9c4650c7f13ce2f59b442180.pack:c2ljxvPAMyFX
vIDu]E\S'v SAHSەB,%;3mSUU䡝<5s
                              f#G9duyu4}|JdS6-Ox_oT_6g
                                                      tcUN#M)oHڸUq
                                                                  %I~XDxSˮFQk#6e

                                                                                |}dUzUV]dƀ)b
./.git/objects/pack/pack-693e36ef28bb545f9c4650c7f13ce2f59b442180.pack:3
LkftbFPpHx54H}/pack/pack-693e36ef28bb545f9c4650c7f13ce2f59b442180.pack:-+z\gָ| y(Bdr\[k8'c9(yt;Umc

The terminal needs to be reset afterwards.

The example snippet for this check looks like this:

# file-crlf
FILE_NULLBYTE_EXTENSION=""
FILE_NULLBYTE_IGNORE=".git,*.svn,*.pyc"
FILE_NULLBYTE_TEXT=0
FILE_NULLBYTE_SIZE=1

This results in binary files being scanned.

Now I'm wondering:

cytopia commented 4 years ago

Scanning all files in the path is the default behaviour to be consistent with all included checks. To circumvent this you can explicitly use the argument --text to ignore all binary files.

kbabioch commented 4 years ago

Having this as default is fine (with me), but at least the example in the README.md should have FILE_NULLBYTE_TEXT set to 1.

Furthermore the check itself should still not cause errors and mis-configure the terminal. So I would still consider this to be a bug :-).

kbabioch commented 4 years ago

I've prepared a change in #15 to change the README.md accordingly. This addresses the documentation aspect, but does NOT fix the bug itself :-).