improperly ignoring UTF-16LE files
I'm trying to use eclint as part of a CI pipeline. One frequent problem I have is some IDEs save files with unusual encodings that are treated as binary by git and other tools. This prevents code review, diffing, linting, etc. I was trying to use editorconfig to specify a UTF-8 charset, and eclint to unsure all our encodings are useful before code hits the master branch. Currently, eclint is ignoring some files.
Reproduction case:
- unzip ignoring-utf16le.zip
- run
eclint check
Expected behavior:
- print a message like
invalid charset: utf-16le, expected: utf-8 - exits with non-zero return code
Actual behavior:
- prints nothing
- exits with zero return code
Investigation
I debugged a little bit and I think I found the cause, the excludeBinaryFile guard in https://github.com/jedmao/eclint/blob/master/lib/cli.ts#L39
When given my bad.sql sample file, the file-type library thinks that's an MP3. Small test code to prove that:
const readChunk = require('read-chunk');
const fileType = require('file-type');
const buffer = readChunk.sync('bad.sql', 0, 4100);
console.log(JSON.stringify(fileType(buffer)));
I'm unsure of how to correct this; all I can think of is:
- file a bug with
file-type - add logic in
eclintto consider binary-looking files if there are editorconfig rules that would apply to that filename; the charset rules feel useless if we never evaluate them
Looks like file-type has fixed their bug upstream, and also introduced backwards incompatible API changes. I think a small patch to cli.ts might do it. Is this project still active?