Skip to content

Commit c712310

Browse files
committed
Check binary file content when classifying
1 parent 7712a37 commit c712310

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

3-
## Next
3+
## 1.6.1
4+
*2021-08-17*
5+
- Changed binary file checking to check file content as well as extension.
46
- Fixed filename matching not comparing the full base name to the list of filename matches.
57

68
## 1.6.0

package-lock.json

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "linguist-js",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
55
"main": "dist/index.js",
66
"bin": {
@@ -36,6 +36,7 @@
3636
"commander": "^8.1.0",
3737
"cross-fetch": "^3.1.4",
3838
"glob-to-regexp": "^0.4.1",
39+
"isbinaryfile": "^4.0.8",
3940
"js-yaml": "^4.1.0",
4041
"node-cache": "^5.1.2",
4142
"tiny-glob": "^0.2.9"

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import yaml from 'js-yaml';
55
import glob from 'tiny-glob';
66
import glob2regex from 'glob-to-regexp';
77
import binaryData from 'binary-extensions';
8+
import { isBinaryFile } from 'isbinaryfile';
89
import Cache from 'node-cache';
910

1011
import * as T from './types';
@@ -185,7 +186,7 @@ export = async function analyse(root = '.', opts: T.Options = {}): Promise<T.Res
185186
}
186187
for (const file in results) {
187188
// Skip binary files
188-
if (!opts.keepBinary && binaryData.some(ext => file.endsWith(ext))) {
189+
if (!opts.keepBinary && (binaryData.some(ext => file.endsWith(ext)) || await isBinaryFile(file))) {
189190
continue;
190191
}
191192

test/test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ async function test() {
3030
await linguist(samplesFolder).then(actual => {
3131
console.log('Results:', actual);
3232
console.log('Language data:', actual.languages.all, '\n');
33-
if (!deepEqual(expected, actual)) throw new Error('Results differ from expected!');
33+
if (!deepEqual(expected, actual)) {
34+
console.warn('Results:', '\nexpected:', expected, '\nactual:', actual);
35+
throw new Error('Results differ from expected!');
36+
}
3437
});
3538
}
3639
test();

0 commit comments

Comments
 (0)