Skip to content

Commit

Permalink
Merge pull request #492 from akmorrow13/add-in-flow-2
Browse files Browse the repository at this point in the history
lint and tests passing with new flow version
  • Loading branch information
akmorrow13 authored Aug 27, 2018
2 parents 8934954 + 3fe57b8 commit 7a57554
Show file tree
Hide file tree
Showing 96 changed files with 1,259 additions and 920 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true,
"experimentalObjectRestSpread": true
}
},
"plugins": [
"react"
],
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"rules": {
"semi": ["error", "always"],
"quotes": ["off", "double"],
"no-tabs": "off",
"new-cap": "off",
"no-unused-vars": ["error", {"args": "none"}],
"no-console": ["error", { "allow": ["warn", "error", "log"] }],
"react/no-find-dom-node": "warn",
"react/no-string-refs": "warn"

},
"settings": {
"react": {
"pragma": "React",
"version": "15.6.1"
}
}
}
3 changes: 2 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[ignore]
.*node_modules/config-chain/test/*
.*node_modules/flow-bin.*
.*node_modules/jsxhint.*
.*node_modules/.*mocha.*
Expand Down Expand Up @@ -30,7 +31,7 @@

[libs]
lib
types
node_modules/data-canvas/flowtype

[options]
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false # Use container-based infrastructure
language: node_js
node_js:
- "5.1"
- "6.14"

script: >
npm run build &&
Expand Down
17 changes: 11 additions & 6 deletions lib/q.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare module "q" {
promise: Promise<T>;
resolve(value: T): void;
reject(reason: any): void;
delay(time: number):void;
notify(value: any): void;
makeNodeResolver(): (reason: any, value: T) => void;
}
Expand All @@ -44,7 +45,7 @@ declare module "q" {
/**
* The then method from the Promises/A+ specification, with an additional progress handler.
*/
then<U>(onFulfill?: (value: T) => U | IPromise<U>, onReject?: (error: any) => U | IPromise<U>, onProgress?: Function): Promise<U>;
then<T, U>(onFulfill?: (value: T) => U | IPromise<U> | Promise<U>, onReject?: (error: any) => U | IPromise<U>, onProgress?: Function): Promise<U>;

/**
* Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
Expand Down Expand Up @@ -164,13 +165,13 @@ declare module "q" {
}

// If no value provided, returned promise will be of void type
declare function when<T, U>(): Promise<void>;
declare function when(): Promise<void>;

// if no fulfill, reject, or progress provided, returned promise will be of same type
declare function when<T, U>(value: T | IPromise<T>): Promise<T>;
declare function when<T, U>(value: T | IPromise<T>,): Promise<T>;

// If a non-promise value is provided, it will not reject or progress
declare function when<T, U>(value: T | IPromise<T>, onFulfilled: (val: T) => U | IPromise<U>, onRejected?: (reason: any) => U | IPromise<U>, onProgress?: (progress: any) => any): Promise<U>;
declare function when<T, U>(value: T | IPromise<T>, onFulfilled: (val: T) => U | IPromise<U>, onRejected?: (reason: any) => U | IPromise<U>, onProgress?: (progress: any) => any, ...rest: Array<void>): Promise<U>;

/**
* Currently "impossible" (and I use the term loosely) to implement due to TypeScript limitations as it is now.
Expand Down Expand Up @@ -200,8 +201,10 @@ declare module "q" {
/**
* Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
*/
declare function all<A, B, C>(promises: [Promise<A>, Promise<B>, Promise<C>]): Promise<[A, B, C]>;
declare function all<A, B, C>(promises: [Promise<A>, Promise<B>]): Promise<[A, B]>;
declare function all(promises: Promise<any>[]): Promise<any>; // catch all
// declare function all<A, B, C, D>(promises: [Promise<A>, Promise<B>, Promise<C>, Promise<D>]): Promise<[A, B, C, D]>;
// declare function all<A, B, C>(promises: [Promise<A>, Promise<B>, Promise<C>]): Promise<[A, B, C]>;
// declare function all<A, B>(promises: [Promise<A>, Promise<B>]): Promise<[A, B]>;

/**
* Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected.
Expand Down Expand Up @@ -314,4 +317,6 @@ declare module "q" {
* Calling resolve with a non-promise value causes promise to be fulfilled with that value.
*/
declare function resolve<T>(object: T): Promise<T>;

declare function delay<T>(time: number): Promise<T>;
}
5 changes: 3 additions & 2 deletions lib/underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare module "underscore" {
declare function clone<T>(obj: T): T;

declare function isEqual<S, T>(a: S, b: T): boolean;
declare function range(a: number, b: number): Array<number>;
declare function range(a?: number, b: number, c?: number): Array<number>;
declare function extend<S, T>(o1: S, o2: T): S & T;

declare function zip<S, T>(a1: S[], a2: T[]): Array<[S, T]>;
Expand Down Expand Up @@ -41,11 +41,12 @@ declare module "underscore" {

declare function groupBy<K, T>(a: Array<T>, iteratee: (val: T, index: number)=>K): {[key:K]: T[]};

declare function min<T>(a: Array<T>|{[key:any]: T}): T;
declare function min<T>(a: Array<T>|{[key:any]: T}, iteratee: (val: T)=>any): T;
declare function max<T>(a: Array<T>|{[key:any]: T}): T;

declare function values<T>(o: {[key: any]: T}): T[];
declare function flatten(a: Array<any>): Array<any>;
declare function flatten(a: Array<any>, shallow?: boolean): Array<any>;

declare function reduce<T, R>(a: T[], fn: (memo: R, val: T, idx: number, list: T[])=>R, memo?: R): R;
declare function reduce<K, T, R>(a: {[key:K]: T}, fn: (memo: R, val: T, key: K, o: {[key:K]: T})=>R, memo?: R): R;
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,22 @@
"devDependencies": {
"arraybuffer-slice": "^0.1.2",
"babel": "^5.8.23",
"babel-eslint" : "8.2.6",
"babel-core": "^5.8.23",
"babelify": "^6.3.0",
"browserify": "^10.2.4",
"chai": "^2.0.0",
"coveralls": "2.10.x",
"envify": "^3.4.0",
"eslint": "^5.4.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^3.1.0",
"eslint-plugin-react": "7.11.1",
"exorcist": "^0.4.0",
"flow-bin": "^0.21.0",
"flow-bin": "^0.79.1",
"http-server": "^0.8.0",
"istanbul": "^0.3.17",
"jsxhint": "git://github.com/strml/JSXHint.git",
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ if [[ $package_version != $code_version ]]; then
fi

# Run the usual linter
./node_modules/.bin/jsxhint --es6module --harmony 'src/main/**/*.js' 'src/test/**/*.js'
./node_modules/.bin/eslint src/**/**/*.js
13 changes: 12 additions & 1 deletion src/main/Alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Interface for alignments, shared between BAM and GA4GH backends.
* @flow
*/

'use strict';

import type {GenomeRange} from './types';
import type ContigInterval from './ContigInterval';

// "CIGAR" operations express how a sequence aligns to the reference: does it
Expand All @@ -13,6 +15,11 @@ export type CigarOp = {
length: number
}

// converts a string into a Strand element. Must be '+' or '-'. Any other
// strings will be converted to '.'.
function strToStrand(str: string): Strand {
return str && str == '+' ? '+' : (str && str == '-' ? '-' : '.'); // either +, - or .
}

export type Strand = '-' | '+' | '.';

Expand Down Expand Up @@ -46,3 +53,7 @@ export type AlignmentDataSource = {
once: (event: string, handler: Function) => void;
off: (event: string) => void;
};

module.exports = {
strToStrand
};
12 changes: 7 additions & 5 deletions src/main/ContigInterval.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* @flow */
'use strict';

import type {GenomeRange} from './types';

import Interval from './Interval';
import {flatMap} from './utils';

Expand Down Expand Up @@ -108,10 +110,10 @@ class ContigInterval<T: (number|string)> {
}

// Comparator for use with Array.prototype.sort
static compare(a: ContigInterval, b: ContigInterval): number {
if (a.contig > b.contig) {
static compare<T: (string|number)>(a: ContigInterval<T>, b: ContigInterval<T>): number {
if (a.contig.toString() > b.contig.toString()) {
return -1;
} else if (a.contig < b.contig) {
} else if (a.contig.toString() < b.contig.toString()) {
return +1;
} else {
return a.start() - b.start();
Expand All @@ -120,7 +122,7 @@ class ContigInterval<T: (number|string)> {

// Sort an array of intervals & coalesce adjacent/overlapping ranges.
// NB: this may re-order the intervals parameter
static coalesce(intervals: ContigInterval[]): ContigInterval[] {
static coalesce<T: (string|number)>(intervals: ContigInterval<T>[]): ContigInterval<T>[] {
intervals.sort(ContigInterval.compare);

var rs = [];
Expand All @@ -143,7 +145,7 @@ class ContigInterval<T: (number|string)> {
}

static fromGenomeRange(range: GenomeRange): ContigInterval<string> {
return new ContigInterval(range.contig, range.start, range.stop);
return new ContigInterval(range.contig.toString(), range.start, range.stop);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
'use strict';

import type {PartialGenomeRange} from './types';
import type {GenomeRange, PartialGenomeRange} from './types';

import React from 'react';
import _ from 'underscore';
Expand All @@ -18,7 +18,7 @@ type Props = {
onChange: (newRange: GenomeRange)=>void;
};

class Controls extends React.Component {
class Controls extends React.Component<Props> {
props: Props;
state: void; // no state

Expand Down Expand Up @@ -50,14 +50,14 @@ class Controls extends React.Component {
if (altContig) range.contig = altContig;
}

return (_.extend({}, this.props.range, range) : any);
return (_.extend(_.clone(this.props.range), range) : any);
}

handleContigChange(e: SyntheticEvent) {
handleContigChange(e: SyntheticEvent<>) {
this.props.onChange(this.completeRange({contig: this.refs.contig.value}));
}

handleFormSubmit(e: SyntheticEvent) {
handleFormSubmit(e: SyntheticEvent<>) {
e.preventDefault();
var range = this.completeRange(utils.parseRange(this.refs.position.value));
this.props.onChange(range);
Expand Down
4 changes: 2 additions & 2 deletions src/main/LocalStringFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LocalStringFile extends AbstractFile {
}
}

getBytes(start: number, length: number): Q.Promise<ArrayBuffer> {
getBytes(start: number, length: number): Q.Promise<?ArrayBuffer> {
if (length < 0) {
return Q.reject(`Requested <0 bytes (${length})`);
}
Expand All @@ -41,7 +41,7 @@ class LocalStringFile extends AbstractFile {
}

// Read the entire file -- not recommended for large files!
getAll(): Q.Promise<ArrayBuffer> {
getAll(): Q.Promise<?ArrayBuffer> {
var buf = this.getFromCache(0, this.fileLength - 1);
return Q.when(buf);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type Props = {
onSelect: (key: string) => void;
};

class Menu extends React.Component<void, Props, void> {
class Menu extends React.Component<Props> {
props: Props;

clickHandler(idx: number, e: SyntheticMouseEvent) {
clickHandler(idx: number, e: SyntheticMouseEvent<>) {
e.preventDefault();
var item = this.props.items[idx];
if (typeof(item) == 'string') return; // for flow
Expand Down
4 changes: 2 additions & 2 deletions src/main/RemoteFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ class RemoteFile extends AbstractFile{
promiseXHR(xhr: XMLHttpRequest): Q.Promise<[any, Event]> {
var url = this.url;
var deferred = Q.defer();
xhr.addEventListener('load', function(e) {
xhr.addEventListener('load', function(e: any) {
if (this.status >= 400) {
deferred.reject(`Request for ${url} failed with status: ${this.status} ${this.statusText}`);
} else {
deferred.resolve([this.response, e]);
}
});
xhr.addEventListener('error', function(e) {
xhr.addEventListener('error', function(e: any) {
deferred.reject(`Request for ${url} failed with status: ${this.status} ${this.statusText}`);
});
this.numNetworkRequests++;
Expand Down
4 changes: 2 additions & 2 deletions src/main/RemoteRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ class RemoteRequest {
promiseXHR(xhr: XMLHttpRequest): Q.Promise<[any, Event]> {
var url = this.url;
var deferred = Q.defer();
xhr.addEventListener('load', function(e) {
xhr.addEventListener('load', function(e: any) {
if (this.status >= 400) {
deferred.reject(`Request for ${url} failed with status: ${this.status} ${this.statusText}`);
} else {
deferred.resolve([this.response, e]);
}
});
xhr.addEventListener('error', function(e) {
xhr.addEventListener('error', function(e: any) {
deferred.reject(`Request for ${url} failed with status: ${this.status} ${this.statusText}`);
});
this.numNetworkRequests++;
Expand Down
Loading

0 comments on commit 7a57554

Please sign in to comment.