diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..3ae0c77 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,18 @@ +{ + "env": { "shared-node-browser":true }, + "globals": {}, + "parserOptions": { + "ecmaVersion": 3, + }, + "plugins": [ "html", "json" ], + "!extends": "eslint:recommended", + "rules": { + "no-console": 0, + "no-bitwise": 0, + "curly": 0, + "comma-style": [ 2, "last" ], + "no-trailing-spaces": 2, + "semi": [ 2, "always" ], + "comma-dangle": [ 2, "never" ] + } +} diff --git a/.flowconfig b/.flowconfig index 1a3ec98..25fc1ab 100644 --- a/.flowconfig +++ b/.flowconfig @@ -25,3 +25,5 @@ misc/flowdeps.js [options] module.file_ext=.js module.file_ext=.njs +module.ignore_non_literal_requires=true +suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore diff --git a/.travis.yml b/.travis.yml index 87a0966..c529897 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: + - "8" - "7" - "6" - "5" diff --git a/Makefile b/Makefile index 569a2af..739f1d2 100644 --- a/Makefile +++ b/Makefile @@ -9,20 +9,22 @@ ULIB=$(shell echo $(LIB) | tr a-z A-Z) DEPS=$(sort $(wildcard bits/*.js)) TARGET=$(LIB).js FLOWTARGET=$(LIB).flow.js +FLOWTGTS=$(TARGET) $(AUXTARGETS) +CLOSURE=/usr/local/lib/node_modules/google-closure-compiler/compiler.jar ## Main Targets .PHONY: all all: $(TARGET) $(AUXTARGETS) ## Build library and auxiliary scripts -$(TARGET) $(AUXTARGETS): %.js : %.flow.js +$(FLOWTGTS): %.js : %.flow.js node -e 'process.stdout.write(require("fs").readFileSync("$<","utf8").replace(/^[ \t]*\/\*[:#][^*]*\*\/\s*(\n)?/gm,"").replace(/\/\*[:#][^*]*\*\//gm,""))' > $@ $(FLOWTARGET): $(DEPS) cat $^ | tr -d '\15\32' > $@ bits/01_version.js: package.json - echo "CRC32.version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@ + echo "$(ULIB).version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@ .PHONY: clean clean: clean-baseline ## Remove targets and build artifacts @@ -56,12 +58,19 @@ clean-baseline: ## Remove test baselines ## Code Checking .PHONY: lint -lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks +lint: $(TARGET) $(AUXTARGETS) ## Run eslint checks + @eslint --ext .js,.njs,.json,.html,.htm $(TARGET) $(AUXTARGETS) $(CMDS) $(HTMLLINT) package.json bower.json + if [ -e $(CLOSURE) ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi + +.PHONY: old-lint +old-lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks @jshint --show-non-errors $(TARGET) $(AUXTARGETS) @jshint --show-non-errors $(CMDS) @jshint --show-non-errors package.json @jshint --show-non-errors --extract=always $(HTMLLINT) @jscs $(TARGET) $(AUXTARGETS) + if [ -e $(CLOSURE) ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi + .PHONY: flow flow: lint ## Run flow checker diff --git a/bin/crc32.njs b/bin/crc32.njs index cbee101..62bffb7 100755 --- a/bin/crc32.njs +++ b/bin/crc32.njs @@ -69,6 +69,7 @@ if(!process.stdin.isTTY) filename = filename || "-"; if(filename.length===0) die("crc32: must specify a filename ('-' for stdin)",1); var crc32 = seed; +// $FlowIgnore -- Writable is callable but type sig disagrees var writable = require('stream').Writable(); writable._write = function(chunk, e, cb) { crc32 = X.buf(chunk, crc32); cb(); }; writable._writev = function(chunks, cb) { diff --git a/bits/10_types.js b/bits/10_types.js index 2d11289..6abb587 100644 --- a/bits/10_types.js +++ b/bits/10_types.js @@ -1,5 +1,5 @@ /*:: type CRC32Type = number; -type ABuf = Array | Buffer; +type ABuf = Array | Uint8Array | Buffer; type CRC32TableType = Array | Int32Array; */ diff --git a/crc32.flow.js b/crc32.flow.js index 9416373..ba392bb 100644 --- a/crc32.flow.js +++ b/crc32.flow.js @@ -26,7 +26,7 @@ var CRC32; CRC32.version = '1.0.2'; /*:: type CRC32Type = number; -type ABuf = Array | Buffer; +type ABuf = Array | Uint8Array | Buffer; type CRC32TableType = Array | Int32Array; */ /* see perf/crc32table.js */ diff --git a/demo/browser.flow.js b/demo/browser.flow.js index 31b9504..1fc81bd 100644 --- a/demo/browser.flow.js +++ b/demo/browser.flow.js @@ -3,7 +3,7 @@ /*:: declare var CRC32: CRC32Module; */ var X = CRC32; -function console_log() { if(typeof console !== 'undefined') console.log.apply(console, [].slice.call(arguments)); } +function console_log(/*:: ...args:Array */) { if(typeof console !== 'undefined') console.log.apply(console, [].slice.call(arguments)); } function lpad(s/*:string*/, len/*:number*/, chr/*:?string*/)/*:string*/{ var L/*:number*/ = len - s.length, C/*:string*/ = chr || " "; diff --git a/demo/work.js b/demo/work.js index fe91cdb..bfb4eee 100644 --- a/demo/work.js +++ b/demo/work.js @@ -1,7 +1,7 @@ /* js-crc32 (C) 2014-present SheetJS -- http://sheetjs.com */ /*:: declare var CRC32: CRC32Module; */ /*:: declare var self: DedicatedWorkerGlobalScope; */ -importScripts('/js-crc32' + '/crc32.js'); +importScripts('../crc32.js'); /*::self.*/postMessage({t:"ready"}); var recrc = function(f, crc, l) { diff --git a/demo/worker.flow.js b/demo/worker.flow.js index 8c26a02..e357561 100644 --- a/demo/worker.flow.js +++ b/demo/worker.flow.js @@ -26,6 +26,17 @@ function process_value(val/*:CRC32Type*/, progress/*:number*/) { else out.innerText = o; } +/*:: +type WMessage = { + t:string; + f:File; + crc:CRC32Type; + l:number; + sz:number; + bytes:number; +}; +*/ + /*# Drag and Drop File */ var handle_drop/*:EventHandler*/ = (function(e/*:DragEvent*/) { e.stopPropagation(); @@ -34,9 +45,9 @@ var handle_drop/*:EventHandler*/ = (function(e/*:DragEvent*/) { var files/*:FileList*/ = e.dataTransfer.files; var f/*:File*/ = files[0]; - var worker = new Worker("/js-crc32" + "/demo/work.js"); + var worker = new Worker("demo/work.js"); worker.postMessage(f); - worker.onmessage = function(M) { var m = M.data; switch(m.t) { + worker.onmessage = function(M) { var m/*:WMessage*/ = (M.data/*:any*/); switch(m.t) { case 'ready': break; case 'start': break; case 'data': process_value(m.crc, 100 * m.bytes / f.size); break;