flow and travis fixes

This commit is contained in:
SheetJS 2017-06-12 16:12:23 -04:00
parent 63ef494ee7
commit 7fe46c8fa9
10 changed files with 51 additions and 9 deletions

18
.eslintrc Normal file

@ -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" ]
}
}

@ -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

@ -1,5 +1,6 @@
language: node_js
node_js:
- "8"
- "7"
- "6"
- "5"

@ -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

@ -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) {

@ -1,5 +1,5 @@
/*::
type CRC32Type = number;
type ABuf = Array<number> | Buffer;
type ABuf = Array<number> | Uint8Array | Buffer;
type CRC32TableType = Array<number> | Int32Array;
*/

@ -26,7 +26,7 @@ var CRC32;
CRC32.version = '1.0.2';
/*::
type CRC32Type = number;
type ABuf = Array<number> | Buffer;
type ABuf = Array<number> | Uint8Array | Buffer;
type CRC32TableType = Array<number> | Int32Array;
*/
/* see perf/crc32table.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<any> */) { 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 || " ";

@ -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) {

@ -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;