Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

improperly ignoring UTF-16LE files #145

Open
ryepup opened this issue Aug 23, 2018 · 1 comment
Open

improperly ignoring UTF-16LE files #145

ryepup opened this issue Aug 23, 2018 · 1 comment

Comments

@ryepup
Copy link

ryepup commented Aug 23, 2018

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
Copy link
Author

ryepup commented Feb 4, 2020

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant