eclint icon indicating copy to clipboard operation
eclint copied to clipboard

improperly ignoring UTF-16LE files

Open ryepup opened this issue 7 years ago • 1 comments

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:

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 eclint to 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

ryepup avatar Aug 23 '18 21:08 ryepup

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?

ryepup avatar Feb 04 '20 13:02 ryepup