From 60ee04b9b9c573aadca23dd69cf9fa8a27592e37 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Fri, 10 Apr 2020 12:18:07 -0700 Subject: [PATCH] linting improvements - check tsx as well - check brace-style - error more instead of warn --- .eslintrc.json | 20 +++-- package.json | 2 +- .../proteopedia-wrapper/ui/controls.tsx | 5 +- src/mol-data/generic/linked-list.ts | 6 +- src/mol-data/int/impl/ordered-set.ts | 27 ++++-- src/mol-data/int/impl/sorted-array.ts | 84 +++++++++++++------ src/mol-io/common/msgpack/encode.ts | 15 ++-- src/mol-io/common/utf8.ts | 17 ++-- .../reader/common/text/number-parser.ts | 6 +- src/mol-io/writer/cif/encoder/binary.ts | 3 +- src/mol-math/graph/int-adjacency-graph.ts | 7 +- src/mol-math/linear-algebra/matrix/evd.ts | 3 +- .../structure/query/utils/structure-set.ts | 14 +++- .../structure/util/subset-builder.ts | 5 +- .../structure/util/unique-subset-builder.ts | 3 +- src/mol-plugin-state/snapshots.ts | 3 +- .../line-graph/line-graph-component.tsx | 56 ++++++------- src/mol-plugin-ui/controls/slider.tsx | 6 +- src/mol-script/runtime/query/table.ts | 50 ++++++----- src/mol-util/make-dir.ts | 5 +- src/mol-util/param-mapping.ts | 3 +- src/mol-util/zip/bin.ts | 16 ++-- src/mol-util/zip/deflate.ts | 6 +- src/mol-util/zip/zip.ts | 3 +- src/servers/volume/common/file.ts | 5 +- src/servers/volume/server/local-api.ts | 5 +- 26 files changed, 220 insertions(+), 155 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index b9185e66b..28e806148 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,8 +14,9 @@ "rules": { "@typescript-eslint/ban-types": "warn", "@typescript-eslint/class-name-casing": "off", + "indent": "off", "@typescript-eslint/indent": [ - "warn", + "error", 4 ], "@typescript-eslint/member-delimiter-style": [ @@ -33,7 +34,7 @@ ], "@typescript-eslint/prefer-namespace-keyword": "warn", "@typescript-eslint/quotes": [ - "warn", + "error", "single", { "avoidEscape": true, @@ -44,22 +45,27 @@ "off", null ], - "@typescript-eslint/type-annotation-spacing": "warn", + "@typescript-eslint/type-annotation-spacing": "error", "arrow-parens": [ "off", "as-needed" ], + "brace-style": "off", + "@typescript-eslint/brace-style": [ + "error", + "1tbs", { "allowSingleLine": true } + ], "comma-dangle": "off", "eqeqeq": [ - "warn", + "error", "smart" ], "import/order": "off", "no-eval": "warn", "no-new-wrappers": "warn", - "no-trailing-spaces": "warn", + "no-trailing-spaces": "error", "no-unsafe-finally": "warn", - "no-var": "warn", - "spaced-comment": "warn" + "no-var": "error", + "spaced-comment": "error" } } \ No newline at end of file diff --git a/package.json b/package.json index 34f59326c..895748255 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/molstar/molstar/issues" }, "scripts": { - "lint": "eslint src/**/*.ts", + "lint": "eslint src/**/*.{ts,tsx}", "test": "npm run lint && jest", "build": "npm run build-tsc && npm run build-extra && npm run build-webpack", "build-tsc": "tsc --incremental", diff --git a/src/examples/proteopedia-wrapper/ui/controls.tsx b/src/examples/proteopedia-wrapper/ui/controls.tsx index ed402e5a1..df970158b 100644 --- a/src/examples/proteopedia-wrapper/ui/controls.tsx +++ b/src/examples/proteopedia-wrapper/ui/controls.tsx @@ -13,7 +13,6 @@ import { StateElements } from '../helpers'; export function volumeStreamingControls(plugin: PluginContext, parent: Element) { ReactDOM.render(<PluginContextContainer plugin={plugin}> - <TransformUpdaterControl nodeRef={StateElements.VolumeStreaming} /> - </PluginContextContainer>, - parent); + <TransformUpdaterControl nodeRef={StateElements.VolumeStreaming} /> + </PluginContextContainer>, parent); } \ No newline at end of file diff --git a/src/mol-data/generic/linked-list.ts b/src/mol-data/generic/linked-list.ts index fbea58bd8..efd64e347 100644 --- a/src/mol-data/generic/linked-list.ts +++ b/src/mol-data/generic/linked-list.ts @@ -89,15 +89,13 @@ class LinkedListImpl<T> implements LinkedList<T> { if (node.previous !== null) { node.previous.next = node.next; - } - else if (/* first == item*/ node.previous === null) { + } else if (/* first == item*/ node.previous === null) { this.first = node.next; } if (node.next !== null) { node.next.previous = node.previous; - } - else if (/* last == item*/ node.next === null) { + } else if (/* last == item*/ node.next === null) { this.last = node.previous; } diff --git a/src/mol-data/int/impl/ordered-set.ts b/src/mol-data/int/impl/ordered-set.ts index 858d4abf7..47a91eed2 100644 --- a/src/mol-data/int/impl/ordered-set.ts +++ b/src/mol-data/int/impl/ordered-set.ts @@ -150,8 +150,11 @@ function unionII(a: I, b: I) { const minA = I.min(a), minB = I.min(b); if (areRangesIntersecting(a, b)) return I.ofRange(Math.min(minA, minB), Math.max(I.max(a), I.max(b))); let lSize, lMin, rSize, rMin; - if (minA < minB) { lSize = sizeA; lMin = minA; rSize = sizeB; rMin = minB; } - else { lSize = sizeB; lMin = minB; rSize = sizeA; rMin = minA; } + if (minA < minB) { + lSize = sizeA; lMin = minA; rSize = sizeB; rMin = minB; + } else { + lSize = sizeB; lMin = minB; rSize = sizeA; rMin = minA; + } const arr = new Int32Array(sizeA + sizeB); for (let i = 0; i < lSize; i++) arr[i] = i + lMin; for (let i = 0; i < rSize; i++) arr[i + lSize] = i + rMin; @@ -328,9 +331,13 @@ export function indexedIntersect(idxA: OrderedSetImpl, a: S, b: S): OrderedSetIm let j = startJ; while (O < lenI && j < endJ) { const x = a[getAt(idxA, O)], y = b[j]; - if (x < y) { O++; } - else if (x > y) { j++; } - else { commonCount++; O++; j++; } + if (x < y) { + O++; + } else if (x > y) { + j++; + } else { + commonCount++; O++; j++; + } } // no common elements @@ -345,9 +352,13 @@ export function indexedIntersect(idxA: OrderedSetImpl, a: S, b: S): OrderedSetIm j = startJ; while (O < lenI && j < endJ) { const x = a[getAt(idxA, O)], y = b[j]; - if (x < y) { O++; } - else if (x > y) { j++; } - else { indices[offset++] = j; O++; j++; } + if (x < y) { + O++; + } else if (x > y) { + j++; + } else { + indices[offset++] = j; O++; j++; + } } return ofSortedArray(indices); diff --git a/src/mol-data/int/impl/sorted-array.ts b/src/mol-data/int/impl/sorted-array.ts index 35e83338e..87eacf6b0 100644 --- a/src/mol-data/int/impl/sorted-array.ts +++ b/src/mol-data/int/impl/sorted-array.ts @@ -146,8 +146,8 @@ export function areIntersecting(a: Nums, b: Nums) { let { startI: i, startJ: j, endI, endJ } = getSuitableIntersectionRange(a, b); while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } + if (x < y) i++; + else if (x > y) j++; else return true; } return false; @@ -164,9 +164,13 @@ export function isSubset(a: Nums, b: Nums) { let equal = 0; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } - else { i++; j++; equal++; } + if (x < y) { + i++; + } else if (x > y) { + j++; + } else { + i++; j++; equal++; + } } return equal === lenB; } @@ -197,9 +201,13 @@ export function union(a: Nums, b: Nums): Nums { // insert the common part while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { indices[offset++] = x; i++; } - else if (x > y) { indices[offset++] = y; j++; } - else { indices[offset++] = x; i++; j++; } + if (x < y) { + indices[offset++] = x; i++; + } else if (x > y) { + indices[offset++] = y; j++; + } else { + indices[offset++] = x; i++; j++; + } } // insert the remaining common part @@ -224,9 +232,13 @@ function getCommonCount(a: Nums, b: Nums, startI: number, startJ: number, endI: let commonCount = 0; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } - else { i++; j++; commonCount++; } + if (x < y) { + i++; + } else if (x > y) { + j++; + } else { + i++; j++; commonCount++; + } } return commonCount; } @@ -251,9 +263,13 @@ export function intersect(a: Nums, b: Nums) { let j = startJ; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } - else { indices[offset++] = x; i++; j++; } + if (x < y) { + i++; + } else if (x > y) { + j++; + } else { + indices[offset++] = x; i++; j++; + } } return ofSortedArray(indices); @@ -268,9 +284,13 @@ export function subtract(a: Nums, b: Nums) { let commonCount = 0; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } - else { i++; j++; commonCount++; } + if (x < y) { + i++; + } else if (x > y) { + j++; + } else { + i++; j++; commonCount++; + } } // A isnt intersecting B ===> A @@ -288,9 +308,13 @@ export function subtract(a: Nums, b: Nums) { j = sJ; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { indices[offset++] = x; i++; } - else if (x > y) { j++; } - else { i++; j++; } + if (x < y) { + indices[offset++] = x; i++; + } else if (x > y) { + j++; + } else { + i++; j++; + } } // insert the "tail" @@ -323,9 +347,13 @@ export function indicesOf(a: Nums, b: Nums): Nums { let commonCount = 0; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } - else { i++; j++; commonCount++; } + if (x < y) { + i++; + } else if (x > y) { + j++; + } else { + i++; j++; commonCount++; + } } const lenA = a.length; @@ -340,9 +368,13 @@ export function indicesOf(a: Nums, b: Nums): Nums { j = sJ; while (i < endI && j < endJ) { const x = a[i], y = b[j]; - if (x < y) { i++; } - else if (x > y) { j++; } - else { indices[offset++] = i; i++; j++; } + if (x < y) { + i++; + } else if (x > y) { + j++; + } else { + indices[offset++] = i; i++; j++; + } } return ofSortedArray(indices); diff --git a/src/mol-io/common/msgpack/encode.ts b/src/mol-io/common/msgpack/encode.ts index 35231843a..9fa997674 100644 --- a/src/mol-io/common/msgpack/encode.ts +++ b/src/mol-io/common/msgpack/encode.ts @@ -88,8 +88,7 @@ function encodedSize(value: any) { for (let i = 0; i < length; i++) { size += encodedSize(value[i]); } - } - else { + } else { let keys = Object.keys(value); length = keys.length; for (let i = 0; i < length; i++) { @@ -257,8 +256,7 @@ function encodeInternal(value: any, view: DataView, bytes: Uint8Array, offset: n if (isArray) { length = value.length; - } - else { + } else { keys = Object.keys(value); length = keys.length; } @@ -266,13 +264,11 @@ function encodeInternal(value: any, view: DataView, bytes: Uint8Array, offset: n if (length < 0x10) { view.setUint8(offset, length | (isArray ? 0x90 : 0x80)); size = 1; - } - else if (length < 0x10000) { + } else if (length < 0x10000) { view.setUint8(offset, isArray ? 0xdc : 0xde); view.setUint16(offset + 1, length); size = 3; - } - else if (length < 0x100000000) { + } else if (length < 0x100000000) { view.setUint8(offset, isArray ? 0xdd : 0xdf); view.setUint32(offset + 1, length); size = 5; @@ -282,8 +278,7 @@ function encodeInternal(value: any, view: DataView, bytes: Uint8Array, offset: n for (let i = 0; i < length; i++) { size += encodeInternal(value[i], view, bytes, offset + size); } - } - else { + } else { for (let i = 0, _i = keys!.length; i < _i; i++) { const key = keys![i]; size += encodeInternal(key, view, bytes, offset + size); diff --git a/src/mol-io/common/utf8.ts b/src/mol-io/common/utf8.ts index 83cc3f075..706fe90db 100644 --- a/src/mol-io/common/utf8.ts +++ b/src/mol-io/common/utf8.ts @@ -59,24 +59,21 @@ function _utf8Read(data: Uint8Array, offset: number, length: number) { for (let i = offset, end = offset + length; i < end; i++) { let byte = data[i]; - // One byte character if ((byte & 0x80) === 0x00) { + // One byte character chunk[chunkOffset++] = chars[byte]; - } - // Two byte character - else if ((byte & 0xe0) === 0xc0) { + } else if ((byte & 0xe0) === 0xc0) { + // Two byte character chunk[chunkOffset++] = chars[((byte & 0x0f) << 6) | (data[++i] & 0x3f)]; - } - // Three byte character - else if ((byte & 0xf0) === 0xe0) { + } else if ((byte & 0xf0) === 0xe0) { + // Three byte character chunk[chunkOffset++] = String.fromCharCode( ((byte & 0x0f) << 12) | ((data[++i] & 0x3f) << 6) | ((data[++i] & 0x3f) << 0) ); - } - // Four byte character - else if ((byte & 0xf8) === 0xf0) { + } else if ((byte & 0xf8) === 0xf0) { + // Four byte character chunk[chunkOffset++] = String.fromCharCode( ((byte & 0x07) << 18) | ((data[++i] & 0x3f) << 12) | diff --git a/src/mol-io/reader/common/text/number-parser.ts b/src/mol-io/reader/common/text/number-parser.ts index 27adc16cc..4f609cec7 100644 --- a/src/mol-io/reader/common/text/number-parser.ts +++ b/src/mol-io/reader/common/text/number-parser.ts @@ -71,8 +71,9 @@ export function parseFloat(str: string, start: number, end: number) { return neg * (ret + point / div); } else if (c === 53 || c === 21) { // 'e'/'E' return parseScientific(neg * ret, str, _start + 1, end); + } else { + break; } - else break; } return neg * ret; } @@ -137,8 +138,9 @@ export function getNumberType(str: string): NumberType { return NumberType.NaN; // string starts with e/E or -e/-E } return getNumberTypeScientific(str, start + 1, end); + } else { + break; } - else break; } return start === end ? NumberType.Int : NumberType.NaN; } diff --git a/src/mol-io/writer/cif/encoder/binary.ts b/src/mol-io/writer/cif/encoder/binary.ts index 9040dc7e6..a80e1afeb 100644 --- a/src/mol-io/writer/cif/encoder/binary.ts +++ b/src/mol-io/writer/cif/encoder/binary.ts @@ -188,8 +188,7 @@ function getFieldData(field: Field<any, any>, arrayCtor: ArrayCtor<string | numb if (isStr) array[offset] = ''; allPresent = false; - } - else { + } else { mask[offset] = Column.ValueKind.Present; array[offset] = getter(key, d, offset); } diff --git a/src/mol-math/graph/int-adjacency-graph.ts b/src/mol-math/graph/int-adjacency-graph.ts index 600ab01f0..04c62438d 100644 --- a/src/mol-math/graph/int-adjacency-graph.ts +++ b/src/mol-math/graph/int-adjacency-graph.ts @@ -54,8 +54,11 @@ export namespace IntAdjacencyGraph { getEdgeIndex(i: VertexIndex, j: VertexIndex): number { let a, b; - if (i < j) { a = i; b = j; } - else { a = j; b = i; } + if (i < j) { + a = i; b = j; + } else { + a = j; b = i; + } for (let t = this.offset[a], _t = this.offset[a + 1]; t < _t; t++) { if (this.b[t] === b) return t; } diff --git a/src/mol-math/linear-algebra/matrix/evd.ts b/src/mol-math/linear-algebra/matrix/evd.ts index 789d314e6..7bd2056ae 100644 --- a/src/mol-math/linear-algebra/matrix/evd.ts +++ b/src/mol-math/linear-algebra/matrix/evd.ts @@ -77,8 +77,7 @@ function symmetricTridiagonalize(a: number[], d: number[], e: number[], order: n a[(j * order) + i] = 0.0; a[(i * order) + j] = 0.0; } - } - else { + } else { // Generate Householder vector. for (let k = 0; k < i; k++) { d[k] /= scale; diff --git a/src/mol-model/structure/query/utils/structure-set.ts b/src/mol-model/structure/query/utils/structure-set.ts index 2e1cf2d1a..9741f3f35 100644 --- a/src/mol-model/structure/query/utils/structure-set.ts +++ b/src/mol-model/structure/query/utils/structure-set.ts @@ -44,8 +44,11 @@ export function structureAreIntersecting(sA: Structure, sB: Structure): boolean if (sA === sB) return true; let a, b; - if (sA.units.length < sB.units.length) { a = sA; b = sB; } - else { a = sB; b = sA; } + if (sA.units.length < sB.units.length) { + a = sA; b = sB; + } else { + a = sB; b = sA; + } const aU = a.units, bU = b.unitMap; @@ -64,8 +67,11 @@ export function structureIntersect(sA: Structure, sB: Structure): Structure { if (!structureAreIntersecting(sA, sB)) return Structure.Empty; let a, b; - if (sA.units.length < sB.units.length) { a = sA; b = sB; } - else { a = sB; b = sA; } + if (sA.units.length < sB.units.length) { + a = sA; b = sB; + } else { + a = sB; b = sA; + } const aU = a.units, bU = b.unitMap; const units: Unit[] = []; diff --git a/src/mol-model/structure/structure/util/subset-builder.ts b/src/mol-model/structure/structure/util/subset-builder.ts index 56f1d14c6..13c082495 100644 --- a/src/mol-model/structure/structure/util/subset-builder.ts +++ b/src/mol-model/structure/structure/util/subset-builder.ts @@ -21,8 +21,9 @@ export class StructureSubsetBuilder { addToUnit(parentId: number, e: ElementIndex) { const unit = this.unitMap.get(parentId); - if (!!unit) { unit[unit.length] = e; } - else { + if (!!unit) { + unit[unit.length] = e; + } else { this.unitMap.set(parentId, [e]); this.ids[this.ids.length] = parentId; } diff --git a/src/mol-model/structure/structure/util/unique-subset-builder.ts b/src/mol-model/structure/structure/util/unique-subset-builder.ts index 21ebf6788..fb713a805 100644 --- a/src/mol-model/structure/structure/util/unique-subset-builder.ts +++ b/src/mol-model/structure/structure/util/unique-subset-builder.ts @@ -24,8 +24,7 @@ export class StructureUniqueSubsetBuilder { const unit = this.unitMap.get(parentId); if (!!unit) { if (UniqueArray.add(unit, e, e)) this.elementCount++; - } - else { + } else { const arr: UArray = UniqueArray.create(); UniqueArray.add(arr, e, e); this.unitMap.set(parentId, arr); diff --git a/src/mol-plugin-state/snapshots.ts b/src/mol-plugin-state/snapshots.ts index b34bb3c97..9ae2b8ad4 100644 --- a/src/mol-plugin-state/snapshots.ts +++ b/src/mol-plugin-state/snapshots.ts @@ -210,8 +210,9 @@ class PluginStateSnapshotManager extends StatefulPluginComponent<{ if (this.state.isPlaying) { this.stop(); this.plugin.state.animation.stop(); + } else { + this.play(); } - else this.play(); } constructor(private plugin: PluginContext) { diff --git a/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx b/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx index f623e05c9..1503f5531 100644 --- a/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx +++ b/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx @@ -15,7 +15,7 @@ interface LineGraphComponentState { } export default class LineGraphComponent extends React.Component<any, LineGraphComponentState> { - private myRef:any; + private myRef: any; private height: number; private width: number; private padding: number; @@ -123,11 +123,11 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo // TODO: SET canSelectMultiple = fasle } - private handleClick = (id:number) => (event:any) => { + private handleClick = (id: number) => (event: any) => { // TODO: add point to selected array } - private handleMouseDown = (id:number) => (event: any) => { + private handleMouseDown = (id: number) => (event: any) => { if(id === 0 || id === this.state.points.length-1){ return; } @@ -164,17 +164,13 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo if ((svgP.x < (padding) || svgP.x > (this.width+(padding))) && (svgP.y > (this.height+(padding)) || svgP.y < (padding))) { updatedCopyPoint = Vec2.create(this.updatedX, this.updatedY); - } - else if (svgP.x < padding) { + } else if (svgP.x < padding) { updatedCopyPoint = Vec2.create(padding, svgP.y); - } - else if( svgP.x > (this.width+(padding))) { + } else if( svgP.x > (this.width+(padding))) { updatedCopyPoint = Vec2.create(this.width+padding, svgP.y); - } - else if (svgP.y > (this.height+(padding))) { + } else if (svgP.y > (this.height+(padding))) { updatedCopyPoint = Vec2.create(svgP.x, this.height+padding); - } - else if (svgP.y < (padding)) { + } else if (svgP.y < (padding)) { updatedCopyPoint = Vec2.create(svgP.x, padding); } else { updatedCopyPoint = Vec2.create(svgP.x, svgP.y); @@ -230,8 +226,8 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo this.change(points); this.gElement.innerHTML = ''; this.ghostPoints = []; - document.removeEventListener("mousemove", this.handleDrag, true); - document.removeEventListener("mouseup", this.handlePointUpdate, true); + document.removeEventListener('mousemove', this.handleDrag, true); + document.removeEventListener('mouseup', this.handlePointUpdate, true); } private handleDoubleClick(event: any) { @@ -267,8 +263,8 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo this.change(points); } - private deletePoint = (i:number) => (event: any) => { - if(i===0 || i===this.state.points.length-1){ return; } + private deletePoint = (i: number) => (event: any) => { + if(i===0 || i===this.state.points.length-1){ return; } const points = this.state.points.filter((_,j) => j !== i); points.sort((a, b) => { if(a[0] === b[0]){ @@ -334,21 +330,21 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo const points: any[] = []; let point: Vec2; for (let i = 0; i < this.state.points.length; i++){ - if(i != 0 && i != this.state.points.length-1){ + if(i !== 0 && i !== this.state.points.length-1){ point = this.normalizePoint(this.state.points[i]); points.push(<PointComponent - key={i} - id={i} - x={point[0]} - y={point[1]} - nX={this.state.points[i][0]} - nY={this.state.points[i][1]} - selected={false} - delete={this.deletePoint} - onmouseover={this.props.onHover} - onmousedown={this.handleMouseDown(i)} - onclick={this.handleClick(i)} - />); + key={i} + id={i} + x={point[0]} + y={point[1]} + nX={this.state.points[i][0]} + nY={this.state.points[i][1]} + selected={false} + delete={this.deletePoint} + onmouseover={this.props.onHover} + onmousedown={this.handleMouseDown(i)} + onclick={this.handleClick(i)} + />); } } return points; @@ -357,8 +353,8 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo private renderLines() { const points: Vec2[] = []; let lines = []; - let min:number; - let maxX:number; + let min: number; + let maxX: number; let maxY: number; let normalizedX: number; let normalizedY: number; diff --git a/src/mol-plugin-ui/controls/slider.tsx b/src/mol-plugin-ui/controls/slider.tsx index ba53065ec..12a66eeef 100644 --- a/src/mol-plugin-ui/controls/slider.tsx +++ b/src/mol-plugin-ui/controls/slider.tsx @@ -733,7 +733,7 @@ export class SliderBase extends React.Component<SliderBaseProps, SliderBaseState ref: this.handleElements[i] })); if (!range) { handles.shift(); } - + const sliderClassName = classNames({ [prefixCls!]: true, [`${prefixCls}-with-marks`]: Object.keys(marks).length, @@ -743,8 +743,8 @@ export class SliderBase extends React.Component<SliderBaseProps, SliderBaseState }); return ( - <div ref={this.sliderElement} className={sliderClassName} - onTouchStart={disabled ? noop : this.onTouchStart as any} + <div ref={this.sliderElement} className={sliderClassName} + onTouchStart={disabled ? noop : this.onTouchStart as any} onMouseDown={disabled ? noop : this.onMouseDown as any} > <div className={`${prefixCls}-rail`} /> diff --git a/src/mol-script/runtime/query/table.ts b/src/mol-script/runtime/query/table.ts index dbd42f193..4cac2762a 100644 --- a/src/mol-script/runtime/query/table.ts +++ b/src/mol-script/runtime/query/table.ts @@ -228,36 +228,46 @@ const symbols = [ })(ctx)), // ============= GENERATORS ================ - D(MolScript.structureQuery.generator.atomGroups, function structureQuery_generator_atomGroups(ctx, xs) { return Queries.generators.atoms({ - entityTest: xs['entity-test'], - chainTest: xs['chain-test'], - residueTest: xs['residue-test'], - atomTest: xs['atom-test'], - groupBy: xs['group-by'] - })(ctx) }), + D(MolScript.structureQuery.generator.atomGroups, function structureQuery_generator_atomGroups(ctx, xs) { + return Queries.generators.atoms({ + entityTest: xs['entity-test'], + chainTest: xs['chain-test'], + residueTest: xs['residue-test'], + atomTest: xs['atom-test'], + groupBy: xs['group-by'] + })(ctx) + }), D(MolScript.structureQuery.generator.all, function structureQuery_generator_all(ctx) { return Queries.generators.all(ctx) }), D(MolScript.structureQuery.generator.empty, function structureQuery_generator_empty(ctx) { return Queries.generators.none(ctx) }), - D(MolScript.structureQuery.generator.bondedAtomicPairs, function structureQuery_generator_bondedAtomicPairs(ctx, xs) { return Queries.generators.bondedAtomicPairs(xs && xs[0])(ctx) }), - D(MolScript.structureQuery.generator.rings, function structureQuery_generator_rings(ctx, xs) { return Queries.generators.rings(xs?.['fingerprint']?.(ctx) as any, xs?.['only-aromatic']?.(ctx))(ctx) }), + D(MolScript.structureQuery.generator.bondedAtomicPairs, function structureQuery_generator_bondedAtomicPairs(ctx, xs) { + return Queries.generators.bondedAtomicPairs(xs && xs[0])(ctx) + }), + D(MolScript.structureQuery.generator.rings, function structureQuery_generator_rings(ctx, xs) { + return Queries.generators.rings(xs?.['fingerprint']?.(ctx) as any, xs?.['only-aromatic']?.(ctx))(ctx) + }), // ============= MODIFIERS ================ - D(MolScript.structureQuery.modifier.includeSurroundings, function structureQuery_modifier_includeSurroundings(ctx, xs) { return Queries.modifiers.includeSurroundings(xs[0] as any, { - radius: xs['radius'](ctx), - wholeResidues: !!(xs['as-whole-residues'] && xs['as-whole-residues'](ctx)), - elementRadius: xs['atom-radius'] - })(ctx) }), + D(MolScript.structureQuery.modifier.includeSurroundings, function structureQuery_modifier_includeSurroundings(ctx, xs) { + return Queries.modifiers.includeSurroundings(xs[0] as any, { + radius: xs['radius'](ctx), + wholeResidues: !!(xs['as-whole-residues'] && xs['as-whole-residues'](ctx)), + elementRadius: xs['atom-radius'] + })(ctx) + }), D(MolScript.structureQuery.modifier.wholeResidues, function structureQuery_modifier_wholeResidues(ctx, xs) { return Queries.modifiers.wholeResidues(xs[0] as any)(ctx) }), D(MolScript.structureQuery.modifier.union, function structureQuery_modifier_union(ctx, xs) { return Queries.modifiers.union(xs[0] as any)(ctx) }), D(MolScript.structureQuery.modifier.expandProperty, function structureQuery_modifier_expandProperty(ctx, xs) { return Queries.modifiers.expandProperty(xs[0] as any, xs['property'])(ctx) }), D(MolScript.structureQuery.modifier.exceptBy, function structureQuery_modifier_exceptBy(ctx, xs) { return Queries.modifiers.exceptBy(xs[0] as any, xs['by'] as any)(ctx) }), - D(MolScript.structureQuery.modifier.includeConnected, function structureQuery_modifier_includeConnected(ctx, xs) { return Queries.modifiers.includeConnected({ - query: xs[0] as any, - bondTest: xs['bond-test'], - wholeResidues: !!(xs['as-whole-residues'] && xs['as-whole-residues'](ctx)), - layerCount: (xs['layer-count'] && xs['layer-count'](ctx)) || 1 - })(ctx) }), + D(MolScript.structureQuery.modifier.includeConnected, function structureQuery_modifier_includeConnected(ctx, xs) { + return Queries.modifiers.includeConnected({ + query: xs[0] as any, + bondTest: xs['bond-test'], + wholeResidues: !!(xs['as-whole-residues'] && xs['as-whole-residues'](ctx)), + layerCount: (xs['layer-count'] && xs['layer-count'](ctx)) || 1 + })(ctx) + }), // ============= COMBINATORS ================ diff --git a/src/mol-util/make-dir.ts b/src/mol-util/make-dir.ts index 051203d65..a8f4ed6fb 100644 --- a/src/mol-util/make-dir.ts +++ b/src/mol-util/make-dir.ts @@ -12,8 +12,9 @@ export function makeDir(path: string, root?: string): boolean { root = (root || '') + dir + '/'; - try { fs.mkdirSync(root); } - catch (e) { + try { + fs.mkdirSync(root); + } catch (e) { if (!fs.statSync(root).isDirectory()) throw new Error(e); } diff --git a/src/mol-util/param-mapping.ts b/src/mol-util/param-mapping.ts index 14f985e79..861bb64c3 100644 --- a/src/mol-util/param-mapping.ts +++ b/src/mol-util/param-mapping.ts @@ -23,8 +23,7 @@ export function ParamMapping<S, T, Ctx>(def: { values(t: T, ctx: Ctx): S, update(s: S, t: Mutable<T>, ctx: Ctx): void, apply?(t: T, ctx: Ctx): void | Promise<void> - }) => ParamMapping<S, T, Ctx> -{ + }) => ParamMapping<S, T, Ctx> { return ({ values, update, apply }) => ({ params: typeof def.params === 'function' ? def.params as any : ctx => def.params, getTarget: def.target, diff --git a/src/mol-util/zip/bin.ts b/src/mol-util/zip/bin.ts index c3a41a169..6edbdc1c6 100644 --- a/src/mol-util/zip/bin.ts +++ b/src/mol-util/zip/bin.ts @@ -91,11 +91,17 @@ export function sizeUTF8(str: string) { let i = 0; for(let ci = 0; ci < strl; ci++) { const code = str.charCodeAt(ci); - if ((code&(0xffffffff-(1<< 7)+1)) === 0) { i++ ; } - else if((code&(0xffffffff-(1<<11)+1)) === 0) { i+=2; } - else if((code&(0xffffffff-(1<<16)+1)) === 0) { i+=3; } - else if((code&(0xffffffff-(1<<21)+1)) === 0) { i+=4; } - else throw 'e'; + if ((code&(0xffffffff-(1<< 7)+1)) === 0) { + i++ ; + } else if((code&(0xffffffff-(1<<11)+1)) === 0) { + i+=2; + } else if((code&(0xffffffff-(1<<16)+1)) === 0) { + i+=3; + } else if((code&(0xffffffff-(1<<21)+1)) === 0) { + i+=4; + } else { + throw 'e'; + } } return i; } diff --git a/src/mol-util/zip/deflate.ts b/src/mol-util/zip/deflate.ts index 464805474..25cec469f 100644 --- a/src/mol-util/zip/deflate.ts +++ b/src/mol-util/zip/deflate.ts @@ -96,8 +96,9 @@ export function _deflateRaw(data: Uint8Array, out: Uint8Array, opos: number, lvl const dgi = _goodIndex(dst, U.df0); U.dhst[ dgi]++; ebits += U.exb[lgi] + U.dxb[dgi]; lits[li] = (len<<23)|(i-cvrd); lits[li+1] = (dst<<16)|(lgi<<8)|dgi; li+=2; cvrd = i + len; + } else { + U.lhst[data[i]]++; } - else { U.lhst[data[i]]++; } lc++; } } @@ -302,8 +303,9 @@ function _lenCodes(tree: number[], set: number[]) { const zc = Math.min((lz+1-i)>>>1, 6); set.push(16, zc-3); i += zc*2-2; + } else { + set.push(l, 0); } - else set.push(l, 0); } return len>>>1; } diff --git a/src/mol-util/zip/zip.ts b/src/mol-util/zip/zip.ts index 8d43d4771..081451dd0 100644 --- a/src/mol-util/zip/zip.ts +++ b/src/mol-util/zip/zip.ts @@ -105,8 +105,9 @@ async function _readLocal(runtime: RuntimeContext, data: Uint8Array, o: number, const buf = new Uint8Array(usize); await inflateRaw(runtime, file, buf); out[name] = buf; + } else { + throw `unknown compression method: ${cmpr}`; } - else throw `unknown compression method: ${cmpr}`; } export async function inflateRaw(runtime: RuntimeContext, file: Uint8Array, buf?: Uint8Array) { diff --git a/src/servers/volume/common/file.ts b/src/servers/volume/common/file.ts index 753512601..d522224b1 100644 --- a/src/servers/volume/common/file.ts +++ b/src/servers/volume/common/file.ts @@ -34,8 +34,9 @@ function makeDir(path: string, root?: string): boolean { root = (root || '') + dir + '/'; - try { fs.mkdirSync(root); } - catch (e) { + try { + fs.mkdirSync(root); + } catch (e) { if (!fs.statSync(root).isDirectory()) throw new Error(e); } diff --git a/src/servers/volume/server/local-api.ts b/src/servers/volume/server/local-api.ts index de87df318..930aa0c33 100644 --- a/src/servers/volume/server/local-api.ts +++ b/src/servers/volume/server/local-api.ts @@ -104,8 +104,9 @@ function makeDir(path: string, root?: string): boolean { root = (root || '') + dir + '/'; - try { fs.mkdirSync(root); } - catch (e) { + try { + fs.mkdirSync(root); + } catch (e) { if (!fs.statSync(root).isDirectory()) throw new Error(e); } -- GitLab