From 7356e717acdec923b2ee3e9d26fac98ba06b6cd0 Mon Sep 17 00:00:00 2001 From: Jakub Kowalski Date: Fri, 2 Aug 2019 15:07:29 +0200 Subject: [PATCH] lint-fix --- benchmark/cruds/1-cruds.ts | 20 ++-- benchmark/cruds/2-matrix.ts | 18 +-- benchmark/cruds/operations.ts | 31 +++-- benchmark/sheets/14-numeric-matrix.ts | 6 +- src/AbsoluteCellRange.ts | 12 +- src/Config.ts | 2 +- src/DependencyGraph/AddressMapping.ts | 14 +-- src/DependencyGraph/DependencyGraph.ts | 12 +- src/DependencyGraph/FormulaCellVertex.ts | 2 +- src/DependencyGraph/Graph.ts | 5 +- src/DependencyGraph/MatrixMapping.ts | 4 +- src/DependencyGraph/MatrixVertex.ts | 2 +- src/DependencyGraph/RangeMapping.ts | 2 +- src/DependencyGraph/RangeVertex.ts | 2 +- src/DependencyGraph/ValueCellVertex.ts | 2 +- src/DependencyGraph/Vertex.ts | 2 +- src/GraphBuilder.ts | 9 +- src/HandsOnEngine.ts | 15 ++- src/Matrix.ts | 2 +- src/SingleThreadEvaluator.ts | 8 +- src/csv.ts | 2 +- src/dependencyTransformers/addColumns.ts | 8 +- src/dependencyTransformers/addRows.ts | 8 +- src/dependencyTransformers/common.ts | 7 +- src/dependencyTransformers/moveCells.ts | 21 ++-- src/dependencyTransformers/removeColumns.ts | 8 +- src/dependencyTransformers/removeRows.ts | 8 +- src/generatorUtils.ts | 2 +- src/i18n/index.ts | 6 +- src/interpreter/Interpreter.ts | 2 +- src/interpreter/plugin/CountUniquePlugin.ts | 2 +- src/interpreter/plugin/FunctionPlugin.ts | 2 +- src/interpreter/plugin/MedianPlugin.ts | 2 +- src/interpreter/plugin/RandomPlugin.ts | 1 - src/interpreter/plugin/SumifPlugin.ts | 10 +- src/parser/Cache.ts | 2 +- src/parser/FormulaParser.ts | 12 +- test/address-mapping.spec.ts | 4 +- test/change-cell-content.spec.ts | 12 +- test/compute-hash.spec.ts | 8 +- test/csv/exporting.spec.ts | 1 - test/csv/importing.spec.ts | 1 - test/date.spec.ts | 2 +- test/extending-plugins.spec.ts | 2 +- test/generatorUtils.spec.ts | 2 +- test/graph-builder.spec.ts | 24 ++-- test/graph-vertex.spec.ts | 3 +- test/graphComparator.ts | 27 ++--- test/interpreter/function-sum.spec.ts | 2 +- test/interpreter/matrix-plugin.spec.ts | 2 +- test/matrix.spec.ts | 1 - test/move-cells.spec.ts | 121 ++++++++++---------- test/parser/boolean-operators.spec.ts | 3 +- test/parser/offset-translation.spec.ts | 8 +- test/parser/parser-with-caching.spec.ts | 5 +- test/range-mapping.spec.ts | 3 +- test/removing-columns.spec.ts | 4 +- test/square-plugin-example.spec.ts | 2 +- test/testUtils.ts | 4 +- test/unparse.spec.ts | 2 +- 60 files changed, 242 insertions(+), 274 deletions(-) diff --git a/benchmark/cruds/1-cruds.ts b/benchmark/cruds/1-cruds.ts index 20b68312ed..036d1d3ad2 100644 --- a/benchmark/cruds/1-cruds.ts +++ b/benchmark/cruds/1-cruds.ts @@ -1,22 +1,22 @@ -import {HandsOnEngine} from "../../src"; -import {sheet as Sb} from "../sheets/01-simple-big"; -import {sheet as Bs} from "../sheets/06-big-sum"; -import {batch} from "./operations"; +import {HandsOnEngine} from '../../src' +import {sheet as Sb} from '../sheets/01-simple-big' +import {sheet as Bs} from '../sheets/06-big-sum' +import {batch} from './operations' function start() { let engine = HandsOnEngine.buildFromArray(Sb(10000)) - let dimensions = engine.getSheetsDimensions().get("Sheet1")! - console.log("\n== Simple big ==", dimensions) + let dimensions = engine.getSheetsDimensions().get('Sheet1')! + console.log('\n== Simple big ==', dimensions) batch(engine) engine = HandsOnEngine.buildFromArray(Sb(100000)) - dimensions = engine.getSheetsDimensions().get("Sheet1")! - console.log("\n== Simple big ==", dimensions) + dimensions = engine.getSheetsDimensions().get('Sheet1')! + console.log('\n== Simple big ==', dimensions) batch(engine) engine = HandsOnEngine.buildFromArray(Bs(100000)) - dimensions = engine.getSheetsDimensions().get("Sheet1")! - console.log("\n== Big sum ==", dimensions) + dimensions = engine.getSheetsDimensions().get('Sheet1')! + console.log('\n== Big sum ==', dimensions) batch(engine) } diff --git a/benchmark/cruds/2-matrix.ts b/benchmark/cruds/2-matrix.ts index 6e004e4da4..d4e8e99341 100644 --- a/benchmark/cruds/2-matrix.ts +++ b/benchmark/cruds/2-matrix.ts @@ -1,22 +1,22 @@ -import {Config, HandsOnEngine} from "../../src"; -import {sheet} from "../sheets/14-numeric-matrix"; -import {batch} from "./operations"; +import {Config, HandsOnEngine} from '../../src' +import {sheet} from '../sheets/14-numeric-matrix' +import {batch} from './operations' function start() { let engine = HandsOnEngine.buildFromArray(sheet(1000, 1000), new Config({ - matrixDetection: false + matrixDetection: false, })) - let dimensions = engine.getSheetsDimensions().get("Sheet1")! - console.log("\n== Matrix - detection off ==", dimensions) + let dimensions = engine.getSheetsDimensions().get('Sheet1')! + console.log('\n== Matrix - detection off ==', dimensions) batch(engine) engine = HandsOnEngine.buildFromArray(sheet(1000, 1000), new Config({ matrixDetectionThreshold: 1, - matrixDetection: true + matrixDetection: true, })) - dimensions = engine.getSheetsDimensions().get("Sheet1")! - console.log("\n== Matrix - detection on ==", dimensions) + dimensions = engine.getSheetsDimensions().get('Sheet1')! + console.log('\n== Matrix - detection on ==', dimensions) batch(engine) } diff --git a/benchmark/cruds/operations.ts b/benchmark/cruds/operations.ts index 4a3471aff1..881a783f02 100644 --- a/benchmark/cruds/operations.ts +++ b/benchmark/cruds/operations.ts @@ -1,40 +1,39 @@ -import {HandsOnEngine} from "../../src"; - +import {HandsOnEngine} from '../../src' export function addColumns(engine: HandsOnEngine) { let dimensions = getDimensions(engine) - measure("Add column at the beginning", () => engine.addColumns(0, 0, 1)) + measure('Add column at the beginning', () => engine.addColumns(0, 0, 1)) dimensions = getDimensions(engine) - measure("Add column in the middle ", () => engine.addColumns(0, half(dimensions.width), 1)) + measure('Add column in the middle ', () => engine.addColumns(0, half(dimensions.width), 1)) dimensions = getDimensions(engine) - measure("Add column at the end ", () => engine.addColumns(0, dimensions.width - 1, 1)) + measure('Add column at the end ', () => engine.addColumns(0, dimensions.width - 1, 1)) } export function addRows(engine: HandsOnEngine) { let dimensions = getDimensions(engine) - measure("Add row at the beginning", () => engine.addRows(0, 0, 1)) + measure('Add row at the beginning', () => engine.addRows(0, 0, 1)) dimensions = getDimensions(engine) - measure("Add row in the middle ", () => engine.addRows(0, half(dimensions.height), 1)) + measure('Add row in the middle ', () => engine.addRows(0, half(dimensions.height), 1)) dimensions = getDimensions(engine) - measure("Add row at the end ", () => engine.addRows(0, dimensions.height - 1, 1)) + measure('Add row at the end ', () => engine.addRows(0, dimensions.height - 1, 1)) } export function removeColumns(engine: HandsOnEngine) { let dimensions = getDimensions(engine) - measure("Remove column at the beginning", () => engine.removeColumns(0, 0, 0)) + measure('Remove column at the beginning', () => engine.removeColumns(0, 0, 0)) dimensions = getDimensions(engine) - measure("Remove column in the middle ", () => engine.removeColumns(0, half(dimensions.width), half(dimensions.width))) + measure('Remove column in the middle ', () => engine.removeColumns(0, half(dimensions.width), half(dimensions.width))) dimensions = getDimensions(engine) - measure("Remove column at the end ", () => engine.removeColumns(0, dimensions.width - 1, dimensions.width - 1)) + measure('Remove column at the end ', () => engine.removeColumns(0, dimensions.width - 1, dimensions.width - 1)) } export function removeRows(engine: HandsOnEngine) { let dimensions = getDimensions(engine) - measure("Remove row at the beginning", () => engine.removeRows(0, 0, 0)) + measure('Remove row at the beginning', () => engine.removeRows(0, 0, 0)) dimensions = getDimensions(engine) - measure("Remove row in the middle ", () => engine.removeRows(0, half(dimensions.height), half(dimensions.height))) + measure('Remove row in the middle ', () => engine.removeRows(0, half(dimensions.height), half(dimensions.height))) dimensions = getDimensions(engine) - measure("Remove row at the end ", () => engine.removeRows(0, dimensions.height - 1, dimensions.height - 1)) + measure('Remove row at the end ', () => engine.removeRows(0, dimensions.height - 1, dimensions.height - 1)) } export function batch(engine: HandsOnEngine) { @@ -49,7 +48,7 @@ function half(num: number) { } function getDimensions(engine: HandsOnEngine) { - return engine.getSheetsDimensions().get("Sheet1")! + return engine.getSheetsDimensions().get('Sheet1')! } function measure(name: String, func: () => T): { time: number, result: T } { @@ -58,5 +57,5 @@ function measure(name: String, func: () => T): { time: number, result: T } { const end = Date.now() const time = end - start console.log(`${name}: ${time} ms`) - return { time: time, result: result} + return { time, result} } diff --git a/benchmark/sheets/14-numeric-matrix.ts b/benchmark/sheets/14-numeric-matrix.ts index 18e422fa68..0ddab1f4c2 100644 --- a/benchmark/sheets/14-numeric-matrix.ts +++ b/benchmark/sheets/14-numeric-matrix.ts @@ -2,10 +2,10 @@ export function sheet(rows: number = 10000, cols: number = 100) { const sheet = [] let x = 0 - for (let i=0; i= this.end.row) && (otherRange.start.col === this.start.col) && - (otherRange.end.col === this.end.col); + (otherRange.end.col === this.end.col) } public isHorizontalPrefixOf(otherRange: AbsoluteCellRange): boolean { return (otherRange.start.col === this.start.col) && (otherRange.end.col >= this.end.col) && (otherRange.start.row === this.start.row) && - (otherRange.end.row === this.end.row); + (otherRange.end.row === this.end.row) } public withoutSuffix(suffixRange: AbsoluteCellRange): AbsoluteCellRange { @@ -226,7 +226,7 @@ export class AbsoluteCellRange { } else if (suffixRange.isVerticalSuffixOf(this)) { return this.withEnd(simpleCellAddress(this.end.sheet, this.end.col, this.end.row - suffixRange.height())) } else { - throw Error("Not a suffix") + throw Error('Not a suffix') } } @@ -238,14 +238,14 @@ export class AbsoluteCellRange { return (otherRange.end.row === this.end.row) && (otherRange.start.row <= this.start.row) && (otherRange.start.col === this.start.col) && - (otherRange.end.col === this.end.col); + (otherRange.end.col === this.end.col) } public isHorizontalSuffixOf(otherRange: AbsoluteCellRange): boolean { return (otherRange.end.col === this.end.col) && (otherRange.start.col <= this.start.col) && (otherRange.start.row === this.start.row) && - (otherRange.end.row === this.end.row); + (otherRange.end.row === this.end.row) } public includesRow(row: number) { diff --git a/src/Config.ts b/src/Config.ts index 4ffb0bd00d..bbdd0b3c8c 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -1,5 +1,5 @@ import {GPUInternalMode, GPUMode} from 'gpu.js' -import {TranslationPackage, enGB} from './i18n' +import {enGB, TranslationPackage} from './i18n' type PossibleGPUMode = GPUMode | GPUInternalMode diff --git a/src/DependencyGraph/AddressMapping.ts b/src/DependencyGraph/AddressMapping.ts index d7dfc0a7f1..6ca548d40d 100644 --- a/src/DependencyGraph/AddressMapping.ts +++ b/src/DependencyGraph/AddressMapping.ts @@ -1,8 +1,8 @@ -import {CellValue, SheetCellAddress, SimpleCellAddress, EmptyValue, simpleCellAddress} from '../Cell' +import {AbsoluteCellRange} from '../AbsoluteCellRange' +import {CellValue, EmptyValue, SheetCellAddress, SimpleCellAddress, simpleCellAddress} from '../Cell' import {Sheet} from '../GraphBuilder' +import {EmptyCellVertex, MatrixVertex} from './' import {CellVertex} from './Vertex' -import { MatrixVertex, EmptyCellVertex } from './' -import {AbsoluteCellRange} from '../AbsoluteCellRange' /** * Interface for mapping from sheet addresses to vertices. @@ -181,8 +181,8 @@ export class SparseStrategy implements IAddressMappingStrategy { } public* getEntries(sheet: number): IterableIterator<[SimpleCellAddress, CellVertex | null]> { - for (const [colNumber,col] of this.mapping) { - for (const [rowNumber,value] of col) { + for (const [colNumber, col] of this.mapping) { + for (const [rowNumber, value] of col) { yield [simpleCellAddress(sheet, colNumber, rowNumber), value] } } @@ -290,8 +290,8 @@ export class DenseStrategy implements IAddressMappingStrategy { } public* getEntries(sheet: number): IterableIterator<[SimpleCellAddress, CellVertex | null]> { - for (let y=0; y = new Set() @@ -218,7 +218,7 @@ export class DependencyGraph { public ensureNoMatrixInRange(range: AbsoluteCellRange) { if (this.matrixMapping.isMatrixInRange(range)) { - throw Error("It is not possible to move / replace cells with matrix") + throw Error('It is not possible to move / replace cells with matrix') } } @@ -233,7 +233,7 @@ export class DependencyGraph { if (sourceVertex !== null) { this.addressMapping.setCell(targetAddress, sourceVertex) let emptyVertex = null - for (let adjacentNode of this.graph.adjacentNodes(sourceVertex)) { + for (const adjacentNode of this.graph.adjacentNodes(sourceVertex)) { if (adjacentNode instanceof RangeVertex && !sourceRange.containsRange(adjacentNode.range)) { emptyVertex = emptyVertex || this.fetchOrCreateEmptyCell(sourceAddress) this.graph.addEdge(emptyVertex, adjacentNode) @@ -249,7 +249,7 @@ export class DependencyGraph { if (sourceVertex === null) { this.addressMapping.removeCell(targetAddress) } - for (let adjacentNode of this.graph.adjacentNodes(targetVertex)) { + for (const adjacentNode of this.graph.adjacentNodes(targetVertex)) { sourceVertex = sourceVertex || this.fetchOrCreateEmptyCell(targetAddress) this.graph.addEdge(sourceVertex, adjacentNode) } diff --git a/src/DependencyGraph/FormulaCellVertex.ts b/src/DependencyGraph/FormulaCellVertex.ts index 0175c4aa29..1a42d98632 100644 --- a/src/DependencyGraph/FormulaCellVertex.ts +++ b/src/DependencyGraph/FormulaCellVertex.ts @@ -1,5 +1,5 @@ -import {Ast} from '../parser' import {CellValue, SimpleCellAddress} from '../Cell' +import {Ast} from '../parser' /** * Represents vertex which keeps formula diff --git a/src/DependencyGraph/Graph.ts b/src/DependencyGraph/Graph.ts index fbb496386e..c3cad64d36 100644 --- a/src/DependencyGraph/Graph.ts +++ b/src/DependencyGraph/Graph.ts @@ -1,4 +1,3 @@ -import {EmptyCellVertex} from "./EmptyCellVertex"; export interface TopSortResult { sorted: T[], cycled: T[] } /** @@ -8,11 +7,11 @@ export class Graph { /** Set with nodes in graph. */ public nodes: Set + public specialNodes: Set + /** Nodes adjacency mapping. */ private edges: Map> - public specialNodes: Set - constructor() { this.nodes = new Set() this.edges = new Map() diff --git a/src/DependencyGraph/MatrixMapping.ts b/src/DependencyGraph/MatrixMapping.ts index 62fc0441f6..6afb36e087 100644 --- a/src/DependencyGraph/MatrixMapping.ts +++ b/src/DependencyGraph/MatrixMapping.ts @@ -66,7 +66,7 @@ export class MatrixMapping { }, this.matrixMapping.entries()[Symbol.iterator]()) } - public truncateMatricesByRows(sheet: number, startRow: number, endRow: number): Array { + public truncateMatricesByRows(sheet: number, startRow: number, endRow: number): MatrixVertex[] { const verticesToRemove = Array() for (const [key, matrix] of this.numericMatricesInRows(sheet, startRow, endRow)) { matrix.removeRows(sheet, startRow, endRow) @@ -78,7 +78,7 @@ export class MatrixMapping { return verticesToRemove } - public truncateMatricesByColumns(sheet: number, startColumn: number, endColumn: number): Array { + public truncateMatricesByColumns(sheet: number, startColumn: number, endColumn: number): MatrixVertex[] { const verticesToRemove = Array() for (const [key, matrix] of this.numericMatricesInColumns(sheet, startColumn, endColumn)) { matrix.removeColumns(sheet, startColumn, endColumn) diff --git a/src/DependencyGraph/MatrixVertex.ts b/src/DependencyGraph/MatrixVertex.ts index 1b5256f224..774edc442d 100644 --- a/src/DependencyGraph/MatrixVertex.ts +++ b/src/DependencyGraph/MatrixVertex.ts @@ -1,6 +1,6 @@ import {AbsoluteCellRange} from '../AbsoluteCellRange' -import {IMatrix, Matrix, NotComputedMatrix} from '../Matrix' import {CellError, CellValue, SimpleCellAddress} from '../Cell' +import {IMatrix, Matrix, NotComputedMatrix} from '../Matrix' import {Ast} from '../parser' export class MatrixVertex { diff --git a/src/DependencyGraph/RangeMapping.ts b/src/DependencyGraph/RangeMapping.ts index 05fb1d82e7..8bffc0cabc 100644 --- a/src/DependencyGraph/RangeMapping.ts +++ b/src/DependencyGraph/RangeMapping.ts @@ -1,6 +1,6 @@ +import {AbsoluteCellRange} from '../AbsoluteCellRange' import {SimpleCellAddress} from '../Cell' import {RangeVertex} from './' -import {AbsoluteCellRange} from "../AbsoluteCellRange"; /** * Mapping from address ranges to range vertices diff --git a/src/DependencyGraph/RangeVertex.ts b/src/DependencyGraph/RangeVertex.ts index e5706794da..36568be0db 100644 --- a/src/DependencyGraph/RangeVertex.ts +++ b/src/DependencyGraph/RangeVertex.ts @@ -10,7 +10,7 @@ export type CriterionCache = Map /** * Represents vertex bound to range */ - export class RangeVertex { +export class RangeVertex { /** Cache for associative aggregate functions. */ private functionCache: Map diff --git a/src/DependencyGraph/ValueCellVertex.ts b/src/DependencyGraph/ValueCellVertex.ts index 0caa77d4a0..10a7ae52a5 100644 --- a/src/DependencyGraph/ValueCellVertex.ts +++ b/src/DependencyGraph/ValueCellVertex.ts @@ -1,4 +1,4 @@ -import {CellError, CellValue} from '../Cell' +import {CellError} from '../Cell' type ValueCellVertexValue = number | boolean | string | CellError diff --git a/src/DependencyGraph/Vertex.ts b/src/DependencyGraph/Vertex.ts index ba94837366..11644d7311 100644 --- a/src/DependencyGraph/Vertex.ts +++ b/src/DependencyGraph/Vertex.ts @@ -1,4 +1,4 @@ -import {FormulaCellVertex, EmptyCellVertex, MatrixVertex, ValueCellVertex, RangeVertex} from './' +import {EmptyCellVertex, FormulaCellVertex, MatrixVertex, RangeVertex, ValueCellVertex} from './' /** * Represents vertex which keeps values of one or more cells diff --git a/src/GraphBuilder.ts b/src/GraphBuilder.ts index 6fb1ca0af4..b44562721a 100644 --- a/src/GraphBuilder.ts +++ b/src/GraphBuilder.ts @@ -1,14 +1,7 @@ - import {CellError, ErrorType, simpleCellAddress, SimpleCellAddress} from './Cell' import {CellDependency} from './CellDependency' import {Config} from './Config' -import {DependencyGraph} from './DependencyGraph' -import { - FormulaCellVertex, - MatrixVertex, - ValueCellVertex, - Vertex, -} from './DependencyGraph' +import {DependencyGraph, FormulaCellVertex, MatrixVertex, ValueCellVertex, Vertex} from './DependencyGraph' import {GraphBuilderMatrixHeuristic} from './GraphBuilderMatrixHeuristic' import {checkMatrixSize, MatrixSizeCheck} from './Matrix' import {isFormula, isMatrix, ParserWithCaching, ProcedureAst} from './parser' diff --git a/src/HandsOnEngine.ts b/src/HandsOnEngine.ts index e714a3a128..8515e912da 100644 --- a/src/HandsOnEngine.ts +++ b/src/HandsOnEngine.ts @@ -1,3 +1,4 @@ +import {AbsoluteCellRange} from './AbsoluteCellRange' import {CellValue, simpleCellAddress, SimpleCellAddress} from './Cell' import {Config} from './Config' import { @@ -13,19 +14,17 @@ import { Vertex, } from './DependencyGraph' import {MatrixMapping} from './DependencyGraph/MatrixMapping' +import {AddColumnsDependencyTransformer} from './dependencyTransformers/addColumns' +import {AddRowsDependencyTransformer} from './dependencyTransformers/addRows' +import {MoveCellsDependencyTransformer} from './dependencyTransformers/moveCells' +import {RemoveColumnsDependencyTransformer} from './dependencyTransformers/removeColumns' +import {RemoveRowsDependencyTransformer} from './dependencyTransformers/removeRows' import {Evaluator} from './Evaluator' import {buildMatrixVertex, GraphBuilder, Sheet, Sheets} from './GraphBuilder' -import {cellAddressFromString, isFormula, isMatrix, ParserWithCaching, ProcedureAst,} from './parser' +import {cellAddressFromString, isFormula, isMatrix, ParserWithCaching, ProcedureAst} from './parser' import {CellAddress} from './parser/CellAddress' import {SingleThreadEvaluator} from './SingleThreadEvaluator' import {Statistics, StatType} from './statistics/Statistics' -import {AbsoluteCellRange} from "./AbsoluteCellRange"; -import {AddRowsDependencyTransformer} from "./dependencyTransformers/addRows"; -import {RemoveRowsDependencyTransformer} from "./dependencyTransformers/removeRows"; -import {AddColumnsDependencyTransformer} from "./dependencyTransformers/addColumns"; -import {RemoveColumnsDependencyTransformer} from "./dependencyTransformers/removeColumns"; -import {MoveCellsDependencyTransformer} from "./dependencyTransformers/moveCells"; - /** * Engine for one sheet diff --git a/src/Matrix.ts b/src/Matrix.ts index 958e84264d..a53f83e5bd 100644 --- a/src/Matrix.ts +++ b/src/Matrix.ts @@ -1,5 +1,5 @@ import {AbsoluteCellRange} from './AbsoluteCellRange' -import { SimpleCellAddress} from './Cell' +import {SimpleCellAddress} from './Cell' import {Ast, AstNodeType} from './parser' export interface Size { width: number, height: number } diff --git a/src/SingleThreadEvaluator.ts b/src/SingleThreadEvaluator.ts index 9d24d511db..4b33925363 100644 --- a/src/SingleThreadEvaluator.ts +++ b/src/SingleThreadEvaluator.ts @@ -1,12 +1,6 @@ import {CellError, ErrorType} from './Cell' import {Config} from './Config' -import { - DependencyGraph, - FormulaCellVertex, - MatrixVertex, - RangeVertex, - Vertex, -} from './DependencyGraph' +import {DependencyGraph, FormulaCellVertex, MatrixVertex, RangeVertex, Vertex} from './DependencyGraph' import {Evaluator} from './Evaluator' import {Interpreter} from './interpreter/Interpreter' import {Ast} from './parser' diff --git a/src/csv.ts b/src/csv.ts index 6792b1e51a..eb9528ac53 100644 --- a/src/csv.ts +++ b/src/csv.ts @@ -1,6 +1,6 @@ import parse from 'csv-parse/lib/sync' import stringify from 'csv-stringify/lib/sync' -import {Config, HandsOnEngine, Sheets, CellValue, EmptyValue, CellError} from './' +import {CellError, CellValue, Config, EmptyValue, HandsOnEngine, Sheets} from './' export type CsvSheets = Record diff --git a/src/dependencyTransformers/addColumns.ts b/src/dependencyTransformers/addColumns.ts index f3bb5967d5..f7eb00dc8e 100644 --- a/src/dependencyTransformers/addColumns.ts +++ b/src/dependencyTransformers/addColumns.ts @@ -1,7 +1,7 @@ -import {fixFormulaVertexColumn, transformAddressesInFormula, TransformCellAddressFunction} from "./common"; -import {DependencyGraph} from "../DependencyGraph"; -import {CellAddress, ParserWithCaching} from "../parser"; -import {SimpleCellAddress} from "../Cell"; +import {SimpleCellAddress} from '../Cell' +import {DependencyGraph} from '../DependencyGraph' +import {CellAddress, ParserWithCaching} from '../parser' +import {fixFormulaVertexColumn, transformAddressesInFormula, TransformCellAddressFunction} from './common' export namespace AddColumnsDependencyTransformer { export function transform(sheet: number, col: number, numberOfCols: number, graph: DependencyGraph, parser: ParserWithCaching) { diff --git a/src/dependencyTransformers/addRows.ts b/src/dependencyTransformers/addRows.ts index 5a4a3cd369..8c44c0622d 100644 --- a/src/dependencyTransformers/addRows.ts +++ b/src/dependencyTransformers/addRows.ts @@ -1,7 +1,7 @@ -import {CellAddress, ParserWithCaching} from "../parser"; -import {SimpleCellAddress} from "../Cell"; -import {DependencyGraph, FormulaCellVertex} from "../DependencyGraph"; -import {fixFormulaVertexRow, transformAddressesInFormula, TransformCellAddressFunction} from "./common"; +import {SimpleCellAddress} from '../Cell' +import {DependencyGraph} from '../DependencyGraph' +import {CellAddress, ParserWithCaching} from '../parser' +import {fixFormulaVertexRow, transformAddressesInFormula, TransformCellAddressFunction} from './common' export namespace AddRowsDependencyTransformer { export function transform(sheet: number, row: number, numberOfRowsToAdd: number, graph: DependencyGraph, parser: ParserWithCaching) { diff --git a/src/dependencyTransformers/common.ts b/src/dependencyTransformers/common.ts index 2706222733..b4d4e19e24 100644 --- a/src/dependencyTransformers/common.ts +++ b/src/dependencyTransformers/common.ts @@ -1,6 +1,6 @@ -import {Ast, AstNodeType, buildCellErrorAst, CellAddress} from "../parser"; -import {CellError, ErrorType, SimpleCellAddress} from "../Cell"; -import {FormulaCellVertex} from "../DependencyGraph"; +import {CellError, ErrorType, SimpleCellAddress} from '../Cell' +import {FormulaCellVertex} from '../DependencyGraph' +import {Ast, AstNodeType, buildCellErrorAst, CellAddress} from '../parser' export type TransformCellAddressFunction = (dependencyAddress: CellAddress, formulaAddress: SimpleCellAddress) => CellAddress | ErrorType.REF | false @@ -73,7 +73,6 @@ export function fixFormulaVertexRow(node: FormulaCellVertex, row: number, number } } - export function fixFormulaVertexColumn(node: FormulaCellVertex, column: number, numberOfColumns: number) { const nodeAddress = node.getAddress() if (column <= nodeAddress.col) { diff --git a/src/dependencyTransformers/moveCells.ts b/src/dependencyTransformers/moveCells.ts index 1d7b67fcc2..8ad2d55554 100644 --- a/src/dependencyTransformers/moveCells.ts +++ b/src/dependencyTransformers/moveCells.ts @@ -1,8 +1,8 @@ -import {transformAddressesInFormula, TransformCellAddressFunction} from "./common"; -import {Ast, AstNodeType, CellAddress, ParserWithCaching} from "../parser"; -import {SimpleCellAddress} from "../Cell"; -import {AbsoluteCellRange} from "../AbsoluteCellRange"; -import {DependencyGraph} from "../DependencyGraph"; +import {AbsoluteCellRange} from '../AbsoluteCellRange' +import {SimpleCellAddress} from '../Cell' +import {DependencyGraph} from '../DependencyGraph' +import {Ast, AstNodeType, CellAddress, ParserWithCaching} from '../parser' +import {transformAddressesInFormula, TransformCellAddressFunction} from './common' export namespace MoveCellsDependencyTransformer { export function transformDependentFormulas(sourceRange: AbsoluteCellRange, toRight: number, toBottom: number, toSheet: number, graph: DependencyGraph, parser: ParserWithCaching) { @@ -13,7 +13,7 @@ export namespace MoveCellsDependencyTransformer { sourceRange, toRight, toBottom, - toSheet + toSheet, ) const cachedAst = parser.rememberNewAst(newAst) node.setFormula(cachedAst) @@ -25,14 +25,14 @@ export namespace MoveCellsDependencyTransformer { const newAst = transformAddressesInFormula( node.getFormula(), node.getAddress(), - fixDependenciesInMovedCells(-toRight, -toBottom) + fixDependenciesInMovedCells(-toRight, -toBottom), ) const cachedAst = parser.rememberNewAst(newAst) node.setFormula(cachedAst) node.setAddress({ sheet: node.address.sheet, col: node.address.col + toRight, - row: node.address.row + toBottom + row: node.address.row + toBottom, }) } } @@ -88,17 +88,16 @@ export namespace MoveCellsDependencyTransformer { return { type: ast.type, procedureName: ast.procedureName, - args: ast.args.map((arg) => transformAddressesInMovedFormula(arg, address, sourceRange, toRight, toBottom, toSheet)) + args: ast.args.map((arg) => transformAddressesInMovedFormula(arg, address, sourceRange, toRight, toBottom, toSheet)), } } default: { return { type: ast.type, left: transformAddressesInMovedFormula(ast.left, address, sourceRange, toRight, toBottom, toSheet), - right: transformAddressesInMovedFormula(ast.right, address, sourceRange, toRight, toBottom, toSheet) + right: transformAddressesInMovedFormula(ast.right, address, sourceRange, toRight, toBottom, toSheet), } as Ast } } } } - diff --git a/src/dependencyTransformers/removeColumns.ts b/src/dependencyTransformers/removeColumns.ts index cba3cf9061..61d1af0de2 100644 --- a/src/dependencyTransformers/removeColumns.ts +++ b/src/dependencyTransformers/removeColumns.ts @@ -1,7 +1,7 @@ -import {fixFormulaVertexColumn, transformAddressesInFormula, TransformCellAddressFunction} from "./common"; -import {DependencyGraph} from "../DependencyGraph"; -import {CellAddress, ParserWithCaching} from "../parser"; -import {ErrorType, SimpleCellAddress} from "../Cell"; +import {ErrorType, SimpleCellAddress} from '../Cell' +import {DependencyGraph} from '../DependencyGraph' +import {CellAddress, ParserWithCaching} from '../parser' +import {fixFormulaVertexColumn, transformAddressesInFormula, TransformCellAddressFunction} from './common' export namespace RemoveColumnsDependencyTransformer { export function transform(sheet: number, columnStart: number, columnEnd: number, graph: DependencyGraph, parser: ParserWithCaching) { diff --git a/src/dependencyTransformers/removeRows.ts b/src/dependencyTransformers/removeRows.ts index 33bb819bd7..48022a4f11 100644 --- a/src/dependencyTransformers/removeRows.ts +++ b/src/dependencyTransformers/removeRows.ts @@ -1,7 +1,7 @@ -import {DependencyGraph, FormulaCellVertex} from "../DependencyGraph"; -import {fixFormulaVertexRow, transformAddressesInFormula, TransformCellAddressFunction} from "./common"; -import {CellAddress, ParserWithCaching} from "../parser"; -import {ErrorType, SimpleCellAddress} from "../Cell"; +import {ErrorType, SimpleCellAddress} from '../Cell' +import {DependencyGraph} from '../DependencyGraph' +import {CellAddress, ParserWithCaching} from '../parser' +import {fixFormulaVertexRow, transformAddressesInFormula, TransformCellAddressFunction} from './common' export namespace RemoveRowsDependencyTransformer { export function transform(sheet: number, rowStart: number, rowEnd: number, graph: DependencyGraph, parser: ParserWithCaching) { diff --git a/src/generatorUtils.ts b/src/generatorUtils.ts index 28c33ea2f2..9682f04616 100644 --- a/src/generatorUtils.ts +++ b/src/generatorUtils.ts @@ -26,7 +26,7 @@ export function * map(fn: ((x: T) => R), iterable: IterableIterator): I if (asSplit.hasOwnProperty('value')) { const value = asSplit.value as T - + yield fn(value) yield * map(fn, asSplit.rest) } diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 10bce54220..38d99eba6c 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -1,6 +1,6 @@ export type TranslationSet = Record -export {plPL} from "./plPL" -export {enGB} from "./enGB" +export {plPL} from './plPL' +export {enGB} from './enGB' export interface TranslationPackage { functions: TranslationSet, @@ -8,6 +8,6 @@ export interface TranslationPackage { export const extendFunctions = (pkg: TranslationPackage, additionalFunctionTranslations: TranslationSet): TranslationPackage => { return { - functions: Object.assign({}, pkg.functions, additionalFunctionTranslations) + functions: Object.assign({}, pkg.functions, additionalFunctionTranslations), } } diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 5db7bfd1b0..6ad1d2b463 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -14,11 +14,11 @@ import {InformationPlugin} from './plugin/InformationPlugin' import {MatrixPlugin} from './plugin/MatrixPlugin' import {MedianPlugin} from './plugin/MedianPlugin' import {NumericAggregationPlugin} from './plugin/NumericAggregationPlugin' +import {RandomPlugin} from './plugin/RandomPlugin' import {SumifPlugin} from './plugin/SumifPlugin' import {SumprodPlugin} from './plugin/SumprodPlugin' import {TextPlugin} from './plugin/TextPlugin' import {TrigonometryPlugin} from './plugin/TrigonometryPlugin' -import {RandomPlugin} from './plugin/RandomPlugin' import {addStrict} from './scalar' import {concatenate} from './text' diff --git a/src/interpreter/plugin/CountUniquePlugin.ts b/src/interpreter/plugin/CountUniquePlugin.ts index 5443c40b42..7a252713b5 100644 --- a/src/interpreter/plugin/CountUniquePlugin.ts +++ b/src/interpreter/plugin/CountUniquePlugin.ts @@ -1,5 +1,5 @@ import {CellError, CellValue, ErrorType, SimpleCellAddress} from '../../Cell' -import { ProcedureAst} from '../../parser/Ast' +import {ProcedureAst} from '../../parser/Ast' import {FunctionPlugin} from './FunctionPlugin' /** diff --git a/src/interpreter/plugin/FunctionPlugin.ts b/src/interpreter/plugin/FunctionPlugin.ts index 3d7003baf3..7bff2afddf 100644 --- a/src/interpreter/plugin/FunctionPlugin.ts +++ b/src/interpreter/plugin/FunctionPlugin.ts @@ -1,7 +1,7 @@ import {AbsoluteCellRange} from '../../AbsoluteCellRange' import {CellError, CellValue, ErrorType, SimpleCellAddress} from '../../Cell' import {Config} from '../../Config' -import { DependencyGraph} from '../../DependencyGraph' +import {DependencyGraph} from '../../DependencyGraph' import {Matrix} from '../../Matrix' import {Ast, AstNodeType, ProcedureAst} from '../../parser/Ast' import {Interpreter} from '../Interpreter' diff --git a/src/interpreter/plugin/MedianPlugin.ts b/src/interpreter/plugin/MedianPlugin.ts index 8dce99535a..957d5d8619 100644 --- a/src/interpreter/plugin/MedianPlugin.ts +++ b/src/interpreter/plugin/MedianPlugin.ts @@ -1,5 +1,5 @@ import {CellError, CellValue, ErrorType, SimpleCellAddress} from '../../Cell' -import { ProcedureAst} from '../../parser/Ast' +import {ProcedureAst} from '../../parser/Ast' import {FunctionPlugin} from './FunctionPlugin' /** diff --git a/src/interpreter/plugin/RandomPlugin.ts b/src/interpreter/plugin/RandomPlugin.ts index e2d1f57b4b..e90a7214c6 100644 --- a/src/interpreter/plugin/RandomPlugin.ts +++ b/src/interpreter/plugin/RandomPlugin.ts @@ -25,4 +25,3 @@ export class RandomPlugin extends FunctionPlugin { } } } - diff --git a/src/interpreter/plugin/SumifPlugin.ts b/src/interpreter/plugin/SumifPlugin.ts index 5a5b2ebc3b..0162d949ab 100644 --- a/src/interpreter/plugin/SumifPlugin.ts +++ b/src/interpreter/plugin/SumifPlugin.ts @@ -1,13 +1,7 @@ import assert from 'assert' import {AbsoluteCellRange} from '../../AbsoluteCellRange' -import { - CellError, - CellValue, - ErrorType, - simpleCellAddress, - SimpleCellAddress, -} from '../../Cell' -import { CriterionCache, DependencyGraph, RangeVertex} from '../../DependencyGraph' +import {CellError, CellValue, ErrorType, simpleCellAddress, SimpleCellAddress} from '../../Cell' +import {CriterionCache, DependencyGraph, RangeVertex} from '../../DependencyGraph' import {count, split} from '../../generatorUtils' import {AstNodeType, CellReferenceAst, ProcedureAst} from '../../parser/Ast' import {buildCriterionLambda, Criterion, CriterionLambda, parseCriterion} from '../Criterion' diff --git a/src/parser/Cache.ts b/src/parser/Cache.ts index 4f552ec054..88d0ba92e6 100644 --- a/src/parser/Cache.ts +++ b/src/parser/Cache.ts @@ -16,7 +16,7 @@ export class Cache { public set(hash: string, ast: Ast): CacheEntry { const astRelativeDependencies: RelativeDependency[] = [] collectDependencies(ast, astRelativeDependencies) - const cacheEntry = buildCacheEntry(ast, astRelativeDependencies, doesContainFunctions(ast, new Set(["RAND"]))) + const cacheEntry = buildCacheEntry(ast, astRelativeDependencies, doesContainFunctions(ast, new Set(['RAND']))) this.cache.set(hash, cacheEntry) return cacheEntry } diff --git a/src/parser/FormulaParser.ts b/src/parser/FormulaParser.ts index 9b8976d825..75e3c6064a 100644 --- a/src/parser/FormulaParser.ts +++ b/src/parser/FormulaParser.ts @@ -1,9 +1,10 @@ import {IAnyOrAlt, ILexingResult, Lexer, OrMethodOpts, Parser, tokenMatcher} from 'chevrotain' -import {SimpleCellAddress, ErrorType, CellError} from '../Cell' +import {CellError, ErrorType, SimpleCellAddress} from '../Cell' import { Ast, AstNodeType, + buildCellErrorAst, buildCellRangeAst, buildCellReferenceAst, buildConcatenateOpAst, @@ -25,7 +26,6 @@ import { buildTimesOpAst, CellReferenceAst, ParsingErrorType, - buildCellErrorAst, } from './Ast' import {CellAddress, CellReferenceType} from './CellAddress' import {cellAddressFromString, SheetMappingFn} from './cellAddressFromString' @@ -36,6 +36,7 @@ import { ConcatenateOp, DivOp, EqualsOp, + ErrorLiteral, GreaterThanOp, GreaterThanOrEqualOp, ILexerConfig, @@ -53,12 +54,11 @@ import { RangeSeparator, RParen, StringLiteral, - ErrorLiteral, TimesOp, } from './LexerConfig' const errors: Record = { - 'REF': ErrorType.REF, + REF: ErrorType.REF, } /** @@ -271,8 +271,8 @@ export class FormulaParser extends Parser { } else { return buildErrorAst([]) } - } - } + }, + }, ])) }) diff --git a/test/address-mapping.spec.ts b/test/address-mapping.spec.ts index ea870706c4..9ee1f3b16d 100644 --- a/test/address-mapping.spec.ts +++ b/test/address-mapping.spec.ts @@ -1,7 +1,5 @@ - import {simpleCellAddress} from '../src/Cell' -import {AddressMapping, DenseStrategy, EmptyCellVertex, SparseStrategy} from '../src/DependencyGraph' -import { ValueCellVertex} from '../src/DependencyGraph' +import {AddressMapping, DenseStrategy, EmptyCellVertex, SparseStrategy, ValueCellVertex} from '../src/DependencyGraph' const sharedExamples = (builder: (width: number, height: number) => AddressMapping) => { it('simple set', () => { diff --git a/test/change-cell-content.spec.ts b/test/change-cell-content.spec.ts index 31a5dc55bb..abf26f6fe9 100644 --- a/test/change-cell-content.spec.ts +++ b/test/change-cell-content.spec.ts @@ -56,18 +56,18 @@ describe('changing cell content', () => { it('update vertex without adjacent nodes to empty cell', () => { const engine = HandsOnEngine.buildFromArray([ - ['1'] + ['1'], ]) engine.setCellContent(simpleCellAddress(0, 0, 0), '') expect(engine.addressMapping!.getCell(simpleCellAddress(0, 0, 0))).toBe(null) - expect(engine.getCellValue("A1")).toBe(EmptyValue) + expect(engine.getCellValue('A1')).toBe(EmptyValue) }) it('set vertex with edge to empty cell', () => { const engine = HandsOnEngine.buildFromArray([ - ['1', '=A1'] + ['1', '=A1'], ]) engine.setCellContent(simpleCellAddress(0, 0, 0), '') @@ -76,7 +76,7 @@ describe('changing cell content', () => { const a2 = engine.addressMapping!.fetchCell(simpleCellAddress(0, 1, 0)) expect(a1).toEqual(new EmptyCellVertex()) expect(engine.graph.existsEdge(a1, a2)).toBe(true) - expect(engine.getCellValue("A1")).toBe(EmptyValue) + expect(engine.getCellValue('A1')).toBe(EmptyValue) }) it('update formula to empty cell', () => { @@ -313,11 +313,11 @@ describe('changing cell content', () => { it('should not be possible to edit part of a Matrix', () => { const engine = HandsOnEngine.buildFromArray([ ['1', '2'], - ['', '{=TRANSPOSE(A1:B1)}'] + ['', '{=TRANSPOSE(A1:B1)}'], ]) expect(() => { - engine.setCellContent(simpleCellAddress(0, 0, 1), "{=TRANSPOSE(C1:C2)}") + engine.setCellContent(simpleCellAddress(0, 0, 1), '{=TRANSPOSE(C1:C2)}') }).toThrow('You cannot modify only part of an array') }) }) diff --git a/test/compute-hash.spec.ts b/test/compute-hash.spec.ts index a849fa5563..9a9059f16f 100644 --- a/test/compute-hash.spec.ts +++ b/test/compute-hash.spec.ts @@ -1,7 +1,7 @@ -import { Config } from '../src/Config' -import { SheetMapping } from '../src/DependencyGraph' -import { buildLexerConfig, FormulaLexer, ParserWithCaching } from '../src/parser' -import { CellAddress } from '../src/parser/CellAddress' +import {Config} from '../src/Config' +import {SheetMapping} from '../src/DependencyGraph' +import {buildLexerConfig, FormulaLexer, ParserWithCaching} from '../src/parser' +import {CellAddress} from '../src/parser/CellAddress' describe('computeHash', () => { const computeFunc = (code: string, address: CellAddress): string => { diff --git a/test/csv/exporting.spec.ts b/test/csv/exporting.spec.ts index 1cac0eb571..7326580d6f 100644 --- a/test/csv/exporting.spec.ts +++ b/test/csv/exporting.spec.ts @@ -1,4 +1,3 @@ - import {CsvExporter, CsvImporter} from '../../src/csv' import '../testConfig.ts' diff --git a/test/csv/importing.spec.ts b/test/csv/importing.spec.ts index d70023f095..123ed3fd68 100644 --- a/test/csv/importing.spec.ts +++ b/test/csv/importing.spec.ts @@ -1,4 +1,3 @@ - import {CsvImporter} from '../../src/csv' import '../testConfig.ts' diff --git a/test/date.spec.ts b/test/date.spec.ts index 419a3a5ad3..94e6ce2b1c 100644 --- a/test/date.spec.ts +++ b/test/date.spec.ts @@ -1,5 +1,5 @@ import {Config} from '../src/Config' -import { dateNumberToMonthNumber, dateNumberToString, toDateNumber } from '../src/Date' +import {dateNumberToMonthNumber, dateNumberToString, toDateNumber} from '../src/Date' describe('Date helpers', () => { it('#toDateNumber should return number representation of a date', () => { diff --git a/test/extending-plugins.spec.ts b/test/extending-plugins.spec.ts index 6eec9f2933..13603dcc10 100644 --- a/test/extending-plugins.spec.ts +++ b/test/extending-plugins.spec.ts @@ -1,7 +1,7 @@ import {HandsOnEngine} from '../src' import {Config} from '../src/Config' -import {FunctionPlugin, PluginFunctionType} from '../src/interpreter/plugin/FunctionPlugin' import {enGB, extendFunctions} from '../src/i18n' +import {FunctionPlugin, PluginFunctionType} from '../src/interpreter/plugin/FunctionPlugin' import './testConfig.ts' class FooPlugin extends FunctionPlugin { diff --git a/test/generatorUtils.spec.ts b/test/generatorUtils.spec.ts index e54fdb8614..0bd041c5cd 100644 --- a/test/generatorUtils.spec.ts +++ b/test/generatorUtils.spec.ts @@ -1,4 +1,4 @@ -import { count, empty, filterWith, first, split, zip } from '../src/generatorUtils' +import {count, empty, filterWith, first, split, zip} from '../src/generatorUtils' describe('empty', () => { it('works', () => { diff --git a/test/graph-builder.spec.ts b/test/graph-builder.spec.ts index f2799e6aba..19e03cf104 100644 --- a/test/graph-builder.spec.ts +++ b/test/graph-builder.spec.ts @@ -1,13 +1,19 @@ import {simpleCellAddress} from '../src/Cell' import {Config} from '../src/Config' -import {RangeMapping} from '../src/DependencyGraph' -import {AddressMapping, DependencyGraph} from '../src/DependencyGraph' -import {SheetMapping} from '../src/DependencyGraph' -import {Graph} from '../src/DependencyGraph' -import {EmptyCellVertex, MatrixVertex, ValueCellVertex, Vertex} from '../src/DependencyGraph' +import { + AddressMapping, + DependencyGraph, + EmptyCellVertex, + Graph, + MatrixVertex, + RangeMapping, + SheetMapping, + ValueCellVertex, + Vertex, +} from '../src/DependencyGraph' import {MatrixMapping} from '../src/DependencyGraph/MatrixMapping' import {GraphBuilder} from '../src/GraphBuilder' -import { ParserWithCaching} from '../src/parser' +import {ParserWithCaching} from '../src/parser' import './testConfig.ts' describe('GraphBuilder', () => { @@ -105,7 +111,7 @@ describe('GraphBuilder', () => { expect(graph.nodesCount()).toBe( 6 + // for cells above - 1 // for range vertex + 1, // for range vertex ) const nodesA1 = graph.adjacentNodes(addressMapping.fetchCell(simpleCellAddress(0, 0, 0))!)! const nodesA2 = graph.adjacentNodes(addressMapping.fetchCell(simpleCellAddress(0, 0, 1))!)! @@ -140,7 +146,7 @@ describe('GraphBuilder', () => { expect(graph.nodesCount()).toBe( 9 + // for cells above - 1 // for both ranges (reuse same ranges) + 1, // for both ranges (reuse same ranges) ) }) @@ -185,7 +191,7 @@ describe('GraphBuilder', () => { expect(graph.nodesCount()).toBe( 3 + // for cells above 1 + // for range vertex - 2 // for 2 EmptyCellVertex instances + 2, // for 2 EmptyCellVertex instances ) expect(graph.edgesCount()).toBe( 2 + // from cells to range vertex diff --git a/test/graph-vertex.spec.ts b/test/graph-vertex.spec.ts index 0717a7ca00..8d4767e5e5 100644 --- a/test/graph-vertex.spec.ts +++ b/test/graph-vertex.spec.ts @@ -1,5 +1,4 @@ -import {Graph} from '../src/DependencyGraph' -import {ValueCellVertex, Vertex} from '../src/DependencyGraph' +import {Graph, ValueCellVertex, Vertex} from '../src/DependencyGraph' describe('Graph with Vertex', () => { it('#addNode works correctly with Vertex instances', () => { diff --git a/test/graphComparator.ts b/test/graphComparator.ts index 5ba3989bea..99fa825020 100644 --- a/test/graphComparator.ts +++ b/test/graphComparator.ts @@ -1,14 +1,15 @@ +import {deepStrictEqual, strictEqual} from 'assert' +import {HandsOnEngine} from '../src' +import {AbsoluteCellRange} from '../src/AbsoluteCellRange' +import {SimpleCellAddress, simpleCellAddress} from '../src/Cell' import { - AddressMapping, CellVertex, DependencyGraph, EmptyCellVertex, FormulaCellVertex, - MatrixVertex, RangeVertex, - ValueCellVertex, Vertex -} from "../src/DependencyGraph"; -import {SimpleCellAddress, simpleCellAddress} from "../src/Cell"; -import {deepStrictEqual, strictEqual} from "assert"; -import {HandsOnEngine} from "../src"; -import {AbsoluteCellRange} from "../src/AbsoluteCellRange"; + MatrixVertex, + RangeVertex, + ValueCellVertex, + Vertex, +} from '../src/DependencyGraph' export class EngineComparator { @@ -42,16 +43,16 @@ export class EngineComparator { continue } else if (expectedVertex instanceof FormulaCellVertex && actualVertex instanceof FormulaCellVertex) { deepStrictEqual(expectedVertex.address, actualVertex.address, `Different addresses in formulas. expected: ${expectedVertex.address}, actual: ${actualVertex.address}`) - deepStrictEqual(expectedVertex.getFormula(), actualVertex.getFormula(), "Different AST in formulas") + deepStrictEqual(expectedVertex.getFormula(), actualVertex.getFormula(), 'Different AST in formulas') strictEqual(expectedVertex.getCellValue(), actualVertex.getCellValue(), `Different values of formulas. expected: ${expectedVertex.getCellValue().toString()}, actual: ${actualVertex.getCellValue().toString()}`) } else if (expectedVertex instanceof ValueCellVertex && actualVertex instanceof ValueCellVertex) { strictEqual(expectedVertex.getCellValue(), actualVertex.getCellValue(), `Different values. expected: ${expectedVertex.getCellValue().toString()}, actual: ${actualVertex.getCellValue().toString()}`) } else if (expectedVertex instanceof EmptyCellVertex && actualVertex instanceof EmptyCellVertex) { continue } else if (expectedVertex instanceof MatrixVertex && actualVertex instanceof MatrixVertex) { - throw Error("Not implemented yet.") + throw Error('Not implemented yet.') } else { - throw Error("Different vertex types") + throw Error('Different vertex types') } const expectedAdjacentAddresses = new Set() @@ -63,7 +64,7 @@ export class EngineComparator { for (const adjacentNode of actualGraph.adjacentNodes(actualVertex)) { actualAdjacentAddresses.add(this.getAddressOfVertex(this.actual, adjacentNode, sheet)) } - deepStrictEqual(expectedAdjacentAddresses, actualAdjacentAddresses, "Dependent vertices are not same") + deepStrictEqual(expectedAdjacentAddresses, actualAdjacentAddresses, 'Dependent vertices are not same') } } } @@ -77,6 +78,6 @@ export class EngineComparator { return address } } - throw Error("No such vertex in address mapping: ") + throw Error('No such vertex in address mapping: ') } } diff --git a/test/interpreter/function-sum.spec.ts b/test/interpreter/function-sum.spec.ts index 30c7dcecba..a7fd718fad 100644 --- a/test/interpreter/function-sum.spec.ts +++ b/test/interpreter/function-sum.spec.ts @@ -63,7 +63,7 @@ describe('SUM', () => { ['1'], ['2'], ['=MAX(A1:A2)'], - ['=SUM(A1:A3)'], + ['=SUM(A1:A3)'], ]) expect(engine.getCellValue('A4')).toEqual(5) }) diff --git a/test/interpreter/matrix-plugin.spec.ts b/test/interpreter/matrix-plugin.spec.ts index 099ddd3896..639955b9cb 100644 --- a/test/interpreter/matrix-plugin.spec.ts +++ b/test/interpreter/matrix-plugin.spec.ts @@ -1,4 +1,4 @@ -import {HandsOnEngine, EmptyValue} from '../../src' +import {EmptyValue, HandsOnEngine} from '../../src' import {CellError, ErrorType} from '../../src/Cell' import {Config} from '../../src/Config' import {MatrixPlugin} from '../../src/interpreter/plugin/MatrixPlugin' diff --git a/test/matrix.spec.ts b/test/matrix.spec.ts index 72195c2973..d0bb20cb42 100644 --- a/test/matrix.spec.ts +++ b/test/matrix.spec.ts @@ -1,4 +1,3 @@ - import {Matrix} from '../src/Matrix' describe('Matrix', () => { diff --git a/test/move-cells.spec.ts b/test/move-cells.spec.ts index bd1b70c8aa..1ae306f6c4 100644 --- a/test/move-cells.spec.ts +++ b/test/move-cells.spec.ts @@ -1,13 +1,13 @@ -import {EmptyValue, HandsOnEngine} from "../src"; -import {simpleCellAddress} from "../src/Cell"; -import {extractRange, extractReference} from "./testUtils"; -import {CellAddress} from "../src/parser"; +import {EmptyValue, HandsOnEngine} from '../src' +import {AbsoluteCellRange} from '../src/AbsoluteCellRange' +import {simpleCellAddress} from '../src/Cell' +import {EmptyCellVertex} from '../src/DependencyGraph' +import {CellAddress} from '../src/parser' +import {EngineComparator} from './graphComparator' import './testConfig.ts' -import {EmptyCellVertex} from "../src/DependencyGraph"; -import {AbsoluteCellRange} from "../src/AbsoluteCellRange"; -import {EngineComparator} from "./graphComparator"; +import {extractRange, extractReference} from './testUtils' -describe("Move cells", () => { +describe('Move cells', () => { it('should move static content', () => { const engine = HandsOnEngine.buildFromArray([ ['foo'], @@ -16,12 +16,12 @@ describe("Move cells", () => { engine.moveCells(simpleCellAddress(0, 0, 0), 1, 1, simpleCellAddress(0, 0, 1)) - expect(engine.getCellValue("A2")).toEqual('foo') - }); + expect(engine.getCellValue('A2')).toEqual('foo') + }) it('should update reference of moved formula', () => { const engine = HandsOnEngine.buildFromArray([ - ['foo', /* =A1 */], + ['foo' /* =A1 */], ['=A1'], ]) @@ -29,7 +29,7 @@ describe("Move cells", () => { const reference = extractReference(engine, simpleCellAddress(0, 1, 0)) expect(reference).toEqual(CellAddress.relative(0, -1, 0)) - }); + }) it('should update reference of moved formula - different types of reference', () => { const engine = HandsOnEngine.buildFromArray([ @@ -46,28 +46,27 @@ describe("Move cells", () => { expect(extractReference(engine, simpleCellAddress(0, 1, 1))).toEqual(CellAddress.absoluteCol(0, 0, -1)) expect(extractReference(engine, simpleCellAddress(0, 1, 2))).toEqual(CellAddress.absoluteRow(0, -1, 0)) expect(extractReference(engine, simpleCellAddress(0, 1, 3))).toEqual(CellAddress.absolute(0, 0, 0)) - }); - + }) it('should update reference of moved formula when moving to other sheet', () => { const engine = HandsOnEngine.buildFromSheets({ - "Sheet1": [ + Sheet1: [ ['foo'], ['=A1'], ], - "Sheet2": [ - ['', /* =A1 */] - ] + Sheet2: [ + ['' /* =A1 */], + ], }) engine.moveCells(simpleCellAddress(0, 0, 1), 1, 1, simpleCellAddress(1, 1, 0)) expect(extractReference(engine, simpleCellAddress(1, 1, 0))).toEqual(CellAddress.relative(0, -1, 0)) - }); + }) it('should update reference', () => { const engine = HandsOnEngine.buildFromArray([ - ['foo', /* foo */], + ['foo' /* foo */], ['=A1'], ['=$A1'], ['=A$1'], @@ -80,11 +79,11 @@ describe("Move cells", () => { expect(extractReference(engine, simpleCellAddress(0, 0, 2))).toEqual(CellAddress.absoluteCol(0, 1, -2)) expect(extractReference(engine, simpleCellAddress(0, 0, 3))).toEqual(CellAddress.absoluteRow(0, 1, 0)) expect(extractReference(engine, simpleCellAddress(0, 0, 4))).toEqual(CellAddress.absolute(0, 1, 0)) - }); + }) it('value moved has appropriate edges', () => { const engine = HandsOnEngine.buildFromArray([ - ['foo', /* foo */], + ['foo' /* foo */], ['=A1'], ]) @@ -96,18 +95,18 @@ describe("Move cells", () => { it('should update reference when moving to different sheet', () => { const engine = HandsOnEngine.buildFromSheets({ - "Sheet1": [ + Sheet1: [ ['foo'], ['=A1'], ], - "Sheet2": [] + Sheet2: [], }) engine.moveCells(simpleCellAddress(0, 0, 0), 1, 1, simpleCellAddress(1, 1, 0)) const reference = extractReference(engine, simpleCellAddress(0, 0, 1)) expect(reference).toEqual(CellAddress.relative(1, 1, -1)) - }); + }) it('should override and remove formula', () => { const engine = HandsOnEngine.buildFromArray([ @@ -119,8 +118,8 @@ describe("Move cells", () => { expect(engine.graph.edgesCount()).toBe(0) expect(engine.graph.nodesCount()).toBe(1) - expect(engine.getCellValue("A1")).toBe(EmptyValue) - expect(engine.getCellValue("A2")).toBe(1) + expect(engine.getCellValue('A1')).toBe(EmptyValue) + expect(engine.getCellValue('A2')).toBe(1) }) it('moving empty vertex', () => { @@ -137,18 +136,17 @@ describe("Move cells", () => { it('replacing formula dependency with null one', () => { const engine = HandsOnEngine.buildFromArray([ ['', '42'], - ['=B1'] + ['=B1'], ]) engine.moveCells(simpleCellAddress(0, 0, 0), 1, 1, simpleCellAddress(0, 1, 0)) new EngineComparator(HandsOnEngine.buildFromArray([ ['', ''], - ['=B1'] + ['=B1'], ]), engine).compare(0) }) - it('moving empty vertex to empty vertex', () => { const engine = HandsOnEngine.buildFromArray([ ['', ''], @@ -174,27 +172,26 @@ describe("Move cells", () => { const target = engine.addressMapping!.fetchCell(simpleCellAddress(0, 0, 1)) expect(engine.graph.edgesCount()).toBe( - 2 // A2 -> B1, A2 -> B2 + 2, // A2 -> B1, A2 -> B2 ) expect(engine.graph.nodesCount()).toBe( + 2 // formulas - + 1 // A2 + + 1, // A2 ) expect(source).toBe(null) expect(engine.graph.existsEdge(target, b2)).toBe(true) expect(engine.graph.existsEdge(target, b1)).toBe(true) - expect(engine.getCellValue("A2")).toBe(1) + expect(engine.getCellValue('A2')).toBe(1) }) }) - describe('moving ranges', () => { it('should not update range when only part of it is moved', () => { const engine = HandsOnEngine.buildFromArray([ - ['1', /* 1 */], - ['2',], - ['=SUM(A1:A2)'] + ['1' /* 1 */], + ['2'], + ['=SUM(A1:A2)'], ]) engine.moveCells(simpleCellAddress(0, 0, 0), 1, 1, simpleCellAddress(0, 1, 0)) @@ -202,7 +199,7 @@ describe('moving ranges', () => { const range = extractRange(engine, simpleCellAddress(0, 0, 2)) expect(range.start).toEqual(simpleCellAddress(0, 0, 0)) expect(range.end).toEqual(simpleCellAddress(0, 0, 1)) - expect(engine.getCellValue("A3")).toEqual(2) + expect(engine.getCellValue('A3')).toEqual(2) const a1 = engine.addressMapping!.fetchCell(simpleCellAddress(0, 0, 0)) const a2 = engine.addressMapping!.fetchCell(simpleCellAddress(0, 0, 1)) @@ -213,16 +210,16 @@ describe('moving ranges', () => { new EngineComparator(HandsOnEngine.buildFromArray([ ['' , '1'], - ['2', ], - ['=SUM(A1:A2)'] + ['2' ], + ['=SUM(A1:A2)'], ]), engine).compare() }) it('should update moved range', () => { const engine = HandsOnEngine.buildFromArray([ - ['1', /* 1 */], - ['2', /* 2 */], - ['=SUM(A1:A2)'] + ['1' /* 1 */], + ['2' /* 2 */], + ['=SUM(A1:A2)'], ]) engine.moveCells(simpleCellAddress(0, 0, 0), 1, 2, simpleCellAddress(0, 1, 0)) @@ -232,7 +229,7 @@ describe('moving ranges', () => { const range = extractRange(engine, simpleCellAddress(0, 0, 2)) expect(range.start).toEqual(simpleCellAddress(0, 1, 0)) expect(range.end).toEqual(simpleCellAddress(0, 1, 1)) - expect(engine.getCellValue("A3")).toEqual(3) + expect(engine.getCellValue('A3')).toEqual(3) expect(engine.addressMapping!.getCell(simpleCellAddress(0, 0, 0))).toBe(null) expect(engine.addressMapping!.getCell(simpleCellAddress(0, 0, 1))).toBe(null) @@ -240,7 +237,7 @@ describe('moving ranges', () => { new EngineComparator(HandsOnEngine.buildFromArray([ ['', '1'], ['', '2'], - ['=SUM(B1:B2)'] + ['=SUM(B1:B2)'], ]), engine).compare() }) @@ -252,7 +249,7 @@ describe('moving ranges', () => { expect(() => { engine.moveCells(simpleCellAddress(0, 0, 1), 2, 2, simpleCellAddress(0, 2, 0)) - }).toThrow("It is not possible to move / replace cells with matrix") + }).toThrow('It is not possible to move / replace cells with matrix') }) it('should not be possible to move cells to area with matrix', () => { @@ -263,7 +260,7 @@ describe('moving ranges', () => { expect(() => { engine.moveCells(simpleCellAddress(0, 0, 0), 2, 1, simpleCellAddress(0, 0, 1)) - }).toThrow("It is not possible to move / replace cells with matrix") + }).toThrow('It is not possible to move / replace cells with matrix') }) it('should adjust edges when moving part of range', () => { @@ -286,18 +283,18 @@ describe('moving ranges', () => { + 2 // formulas + 1 // A2 + 1 // A1 (Empty) - + 1 // A1:A2 range + + 1, // A1:A2 range ) expect(engine.graph.edgesCount()).toBe( + 2 // A1 (Empty) -> A1:A2, A2 -> A1:A2 + 1 // A1:A2 -> B1 - + 1 // A2 -> B2 + + 1, // A2 -> B2 ) expect(engine.graph.existsEdge(target, b2)).toBe(true) expect(engine.graph.existsEdge(source, range)).toBe(true) expect(engine.graph.existsEdge(target, range)).toBe(true) expect(engine.graph.existsEdge(range, b1)).toBe(true) - expect(engine.getCellValue("A2")).toBe(1) + expect(engine.getCellValue('A2')).toBe(1) new EngineComparator(HandsOnEngine.buildFromArray([ ['' , '=SUM(A1:A2)'], @@ -327,12 +324,12 @@ describe('moving ranges', () => { expect(engine.graph.nodesCount()).toBe( + 2 // formulas + 2 // C1, C2 - + 1 // C1:C2 range + + 1, // C1:C2 range ) expect(engine.graph.edgesCount()).toBe( + 2 // C1 -> C1:C2, C2 -> C1:C2 + 1 // C1:C2 -> B1 - + 1 // C2 -> B2 + + 1, // C2 -> B2 ) expect(engine.graph.existsEdge(c1, range)).toBe(true) @@ -347,8 +344,8 @@ describe('moving ranges', () => { it('should adjust edges when moving smaller range', () => { const engine = HandsOnEngine.buildFromArray([ - ['1', '', /* 1 */], - ['2', '=SUM(A1:A2)', /* 2 */], + ['1', '' /* 1 */], + ['2', '=SUM(A1:A2)' /* 2 */], ['3', '=SUM(A1:A3)' ], ]) @@ -379,14 +376,14 @@ describe('moving ranges', () => { new EngineComparator(HandsOnEngine.buildFromArray([ ['' , '' , '1'], ['' , '=SUM(C1:C2)', '2'], - ['3', '=SUM(A1:A3)', ], + ['3', '=SUM(A1:A3)' ], ]), engine).compare() }) it('should adjust edges when moving smaller ranges - more complex', () => { const engine = HandsOnEngine.buildFromArray([ - ['1', '', /* 1 */], - ['2', '=SUM(A1:A2)', /* 2 */], + ['1', '' /* 1 */], + ['2', '=SUM(A1:A2)' /* 2 */], ['3', '=SUM(A1:A3)' /* 3 */], ['4', '=SUM(A1:A4)' ], ]) @@ -416,9 +413,9 @@ describe('moving ranges', () => { expect(engine.graph.existsEdge(c3, c1c3)).toBe(true) new EngineComparator(HandsOnEngine.buildFromArray([ - ['' , '' ,'1'], - ['' , '=SUM(C1:C2)' ,'2'], - ['' , '=SUM(C1:C3)' ,'3'], + ['' , '' , '1'], + ['' , '=SUM(C1:C2)' , '2'], + ['' , '=SUM(C1:C3)' , '3'], ['4', '=SUM(A1:A4)' ], ]), engine).compare(0) }) @@ -428,7 +425,7 @@ describe('moving ranges', () => { ['1', '2'], ['3', '4'], ['5', '6'], - ['=SUM(A1:B1)', '=SUM(A1:B2)', '=SUM(A1:B3)'] + ['=SUM(A1:B1)', '=SUM(A1:B2)', '=SUM(A1:B3)'], ]) engine.moveCells(simpleCellAddress(0, 0, 0), 2, 2, simpleCellAddress(0, 2, 0)) @@ -437,7 +434,7 @@ describe('moving ranges', () => { ['', '', '1', '2'], ['', '', '3', '4'], ['5', '6'], - ['=SUM(C1:D1)', '=SUM(C1:D2)', '=SUM(A1:B3)'] + ['=SUM(C1:D1)', '=SUM(C1:D2)', '=SUM(A1:B3)'], ]), engine).compare(0) }) }) diff --git a/test/parser/boolean-operators.spec.ts b/test/parser/boolean-operators.spec.ts index 61a61cd0f1..33445f4c05 100644 --- a/test/parser/boolean-operators.spec.ts +++ b/test/parser/boolean-operators.spec.ts @@ -6,7 +6,8 @@ import { GreaterThanOpAst, GreaterThanOrEqualOpAst, LessThanOpAst, - LessThanOrEqualOpAst, NotEqualOpAst, + LessThanOrEqualOpAst, + NotEqualOpAst, ParserWithCaching, } from '../../src/parser' import {CellAddress} from '../../src/parser/CellAddress' diff --git a/test/parser/offset-translation.spec.ts b/test/parser/offset-translation.spec.ts index 66cb716e54..979bb17778 100644 --- a/test/parser/offset-translation.spec.ts +++ b/test/parser/offset-translation.spec.ts @@ -1,12 +1,6 @@ import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' -import { - AstNodeType, - CellRangeAst, - CellReferenceAst, - ErrorAst, - ParserWithCaching, -} from '../../src/parser' +import {AstNodeType, CellRangeAst, CellReferenceAst, ErrorAst, ParserWithCaching} from '../../src/parser' import {CellAddress} from '../../src/parser/CellAddress' describe('Parser - OFFSET to reference translation', () => { diff --git a/test/parser/parser-with-caching.spec.ts b/test/parser/parser-with-caching.spec.ts index 37c9cd3a74..a688c23e9d 100644 --- a/test/parser/parser-with-caching.spec.ts +++ b/test/parser/parser-with-caching.spec.ts @@ -1,6 +1,6 @@ +import {CellError, ErrorType} from '../../src/Cell' import {Config} from '../../src/Config' import {SheetMapping} from '../../src/DependencyGraph' -import {ErrorType, CellError} from '../../src/Cell' import { AstNodeType, CellRangeAst, @@ -9,7 +9,8 @@ import { MinusOpAst, MinusUnaryOpAst, NumberAst, - ParserWithCaching, ParsingErrorType, + ParserWithCaching, + ParsingErrorType, PlusOpAst, PowerOpAst, ProcedureAst, diff --git a/test/range-mapping.spec.ts b/test/range-mapping.spec.ts index c11b2d63d6..4502e21019 100644 --- a/test/range-mapping.spec.ts +++ b/test/range-mapping.spec.ts @@ -1,7 +1,6 @@ import {AbsoluteCellRange} from '../src/AbsoluteCellRange' import {simpleCellAddress} from '../src/Cell' -import {RangeMapping} from '../src/DependencyGraph' -import {RangeVertex} from '../src/DependencyGraph' +import {RangeMapping, RangeVertex} from '../src/DependencyGraph' describe('RangeMapping', () => { it('range mapping when there is none', () => { diff --git a/test/removing-columns.spec.ts b/test/removing-columns.spec.ts index 109bede06e..e449986ab6 100644 --- a/test/removing-columns.spec.ts +++ b/test/removing-columns.spec.ts @@ -1,6 +1,6 @@ import {Config, HandsOnEngine} from '../src' -import { simpleCellAddress} from '../src/Cell' -import { MatrixVertex, RangeVertex} from '../src/DependencyGraph' +import {simpleCellAddress} from '../src/Cell' +import {MatrixVertex, RangeVertex} from '../src/DependencyGraph' import {CellAddress} from '../src/parser/CellAddress' import './testConfig.ts' import {expect_function_to_have_ref_error, expect_reference_to_have_ref_error, extractReference} from './testUtils' diff --git a/test/square-plugin-example.spec.ts b/test/square-plugin-example.spec.ts index afbc050e6f..9e3cf76de8 100644 --- a/test/square-plugin-example.spec.ts +++ b/test/square-plugin-example.spec.ts @@ -1,8 +1,8 @@ import {HandsOnEngine} from '../src' import {CellError, ErrorType, SimpleCellAddress} from '../src/Cell' import {Config} from '../src/Config' -import {FunctionPlugin} from '../src/interpreter/plugin/FunctionPlugin' import {enGB, extendFunctions} from '../src/i18n' +import {FunctionPlugin} from '../src/interpreter/plugin/FunctionPlugin' import {ProcedureAst} from '../src/parser' import './testConfig.ts' diff --git a/test/testUtils.ts b/test/testUtils.ts index c76b359657..f82a41cd89 100644 --- a/test/testUtils.ts +++ b/test/testUtils.ts @@ -1,4 +1,5 @@ import {HandsOnEngine} from '../src' +import {AbsoluteCellRange} from '../src/AbsoluteCellRange' import {CellError, ErrorType, SimpleCellAddress} from '../src/Cell' import {FormulaCellVertex} from '../src/DependencyGraph' import { @@ -9,9 +10,8 @@ import { CellRangeAst, CellReferenceAst, ProcedureAst, - Unparser + Unparser, } from '../src/parser' -import {AbsoluteCellRange} from "../src/AbsoluteCellRange"; export const extractReference = (engine: HandsOnEngine, address: SimpleCellAddress): CellAddress => { return ((engine.addressMapping!.fetchCell(address) as FormulaCellVertex).getFormula() as CellReferenceAst).reference diff --git a/test/unparse.spec.ts b/test/unparse.spec.ts index ca9c7af8eb..64da85819c 100644 --- a/test/unparse.spec.ts +++ b/test/unparse.spec.ts @@ -1,7 +1,7 @@ import {Config} from '../src' import {simpleCellAddress} from '../src/Cell' import {SheetMapping} from '../src/DependencyGraph' -import { ParserWithCaching} from '../src/parser' +import {ParserWithCaching} from '../src/parser' import {CellAddress} from '../src/parser/CellAddress' import {Unparser} from '../src/parser/Unparser'