Skip to content

Commit

Permalink
eslint formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrosinger committed Feb 18, 2021
1 parent 7aceb21 commit 05e08b5
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 78 deletions.
12 changes: 6 additions & 6 deletions src/calc/algebraic_operation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Table } from '..';
import { err, ok, Result } from '../neverthrow/neverthrow';
import { Cell, checkChildLength, checkType, ValueProvider } from './ast_utils';
import { Source } from './calc';
import { Constant } from './constant';
import { Value } from './results';
import { IToken } from 'ebnf';
import { map } from 'lodash';
import { Cell, checkChildLength, checkType, ValueProvider } from './ast_utils';
import { Constant } from './constant';

export class AlgebraicOperation implements ValueProvider {
private readonly leftSource: ValueProvider;
Expand Down Expand Up @@ -66,11 +66,11 @@ export class AlgebraicOperation implements ValueProvider {
canHaveRightRange: boolean,
fn: (left: number, right: number) => number,
): Result<Value, Error> => {
let leftValue = this.leftSource.getValue(table, cell);
const leftValue = this.leftSource.getValue(table, cell);
if (leftValue.isErr()) {
return err(leftValue.error);
}
let rightValue = this.rightSource.getValue(table, cell);
const rightValue = this.rightSource.getValue(table, cell);
if (rightValue.isErr()) {
return err(rightValue.error);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AlgebraicOperation implements ValueProvider {
}),
);
return ok(new Value(result));
} else {
}
const leftCellValue = leftValue.value.getAsFloat(0, 0);

const result: string[][] = map(
Expand All @@ -122,7 +122,7 @@ export class AlgebraicOperation implements ValueProvider {
}),
);
return ok(new Value(result));
}

};

private readonly add = (table: Table, cell: Cell): Result<Value, Error> =>
Expand Down
2 changes: 1 addition & 1 deletion src/calc/ast_utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IToken } from 'ebnf';
import { Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import { Value } from './results';
import { IToken } from 'ebnf';

export const errIndex0 = new Error('Index 0 used to create a reference');
export const errRelativeReferenceIndex = new Error(
Expand Down
24 changes: 10 additions & 14 deletions src/calc/calc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { err, ok, Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import { AlgebraicOperation } from './algebraic_operation';
import { Cell, checkChildLength, checkType, ValueProvider } from './ast_utils';
import { Reference } from './reference';
import { ConditionalFunctionCall } from './conditional_function';
import { Range } from './range';
import { Value } from './results';
import { SingleParamFunctionCall } from './single_param_function';
import { Grammars, IToken } from 'ebnf';
import { concat } from 'lodash';
import { Constant } from './constant';
import { Destination, newDestination } from './destination';
import {
DefaultFormatter,
DisplayDirective,
Formatter,
} from './display_directive';
import { Destination, newDestination } from './destination';
import { Constant } from './constant';
import { Range } from './range';
import { Reference } from './reference';
import { Value } from './results';
import { SingleParamFunctionCall } from './single_param_function';
import { Grammars, IToken } from 'ebnf';
import { concat } from 'lodash';

/**
* W3C grammar describing a valid formula at the bottom of a table.
Expand Down Expand Up @@ -82,9 +82,7 @@ export class Formula {
this.source = new Source(ast.children[1], table);
}

public merge = (table: Table): Result<Table, Error> => {
return this.destination.merge(this.source, table);
};
public merge = (table: Table): Result<Table, Error> => this.destination.merge(this.source, table);
}

export class Source {
Expand All @@ -109,9 +107,7 @@ export class Source {
/**
* getValue returns the evaluated value for this source recursively.
*/
public getValue = (table: Table, currentCell: Cell): Result<Value, Error> => {
return this.locationDescriptor.getValue(table, currentCell);
};
public getValue = (table: Table, currentCell: Cell): Result<Value, Error> => this.locationDescriptor.getValue(table, currentCell);
}

const newValueProvider = (
Expand Down
12 changes: 5 additions & 7 deletions src/calc/column.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IToken } from 'ebnf';
import { err, ok, Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import {
Expand All @@ -10,6 +9,7 @@ import {
ValueProvider,
} from './ast_utils';
import { Value } from './results';
import { IToken } from 'ebnf';

export const newColumn = (ast: IToken, table: Table): Result<Column, Error> => {
try {
Expand All @@ -22,7 +22,7 @@ export const newColumn = (ast: IToken, table: Table): Result<Column, Error> => {
return err(
new Error(
`Formula element '${ast.text}' is a ${ast.type} but expected an ` +
`relatve_column or absolute_column in this position.`,
'relatve_column or absolute_column in this position.',
),
);
}
Expand All @@ -45,7 +45,7 @@ export abstract class Column implements ValueProvider {
}

class RelativeColumn extends Column {
private offset: number;
private readonly offset: number;

constructor(ast: IToken, table: Table) {
super();
Expand All @@ -64,9 +64,7 @@ class RelativeColumn extends Column {
this.offset = multiplier * parseInt(ast.children[0].text);
}

public getIndex = (currentCell: Cell): number => {
return currentCell.column + this.offset;
};
public getIndex = (currentCell: Cell): number => currentCell.column + this.offset;

public getAbsoluteIndex = (): Result<number, Error> =>
err(errRelativeReferenceIndex);
Expand Down Expand Up @@ -95,7 +93,7 @@ export class AbsoluteColumn extends Column {
default:
throw new Error(
`Formula element '${ast.text}' is a ${ast.type} but expected ` +
`a 'absolute_column' in this position.`,
'a \'absolute_column\' in this position.',
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/calc/constant.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IToken } from 'ebnf';
import { ok, Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import { Cell, checkType, ValueProvider } from './ast_utils';
import { Value } from './results';
import { IToken } from 'ebnf';

export class Constant implements ValueProvider {
private value: number;
private readonly value: number;

constructor(ast: IToken, table: Table) {
const typeErr = checkType(ast, 'real');
Expand Down
32 changes: 14 additions & 18 deletions src/calc/destination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { IToken } from 'ebnf';
import { range } from 'lodash';
import { err, ok, Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import { Cell, checkChildLength, checkType, errIndex0 } from './ast_utils';
Expand All @@ -8,6 +6,8 @@ import { AbsoluteColumn } from './column';
import { Formatter } from './display_directive';
import { Range } from './range';
import { AbsoluteRow } from './row';
import { IToken } from 'ebnf';
import { range } from 'lodash';

export interface Destination {
merge(source: Source, table: Table): Result<Table, Error>;
Expand Down Expand Up @@ -58,8 +58,8 @@ export const newDestination = (
};

export class RowDestination implements Destination {
private row: AbsoluteRow;
private formatter: Formatter;
private readonly row: AbsoluteRow;
private readonly formatter: Formatter;

constructor(ast: IToken, table: Table, formatter: Formatter) {
this.formatter = formatter;
Expand All @@ -86,17 +86,15 @@ export class RowDestination implements Destination {
public merge = (source: Source, table: Table): Result<Table, Error> => {
// for cell in row...
const cells = range(0, table.getWidth()).map(
(columnNum): Cell => {
return { row: this.row.index, column: columnNum };
},
(columnNum): Cell => ({ row: this.row.index, column: columnNum }),
);
return mergeForCells(source, table, cells, this.formatter);
};
}

export class ColumnDestination implements Destination {
private column: AbsoluteColumn;
private formatter: Formatter;
private readonly column: AbsoluteColumn;
private readonly formatter: Formatter;

constructor(ast: IToken, table: Table, formatter: Formatter) {
this.formatter = formatter;
Expand All @@ -123,18 +121,16 @@ export class ColumnDestination implements Destination {
public merge = (source: Source, table: Table): Result<Table, Error> => {
// for cell in column (excluding header)...
const cells = range(2, table.getHeight()).map(
(rowNum): Cell => {
return { row: rowNum, column: this.column.index };
},
(rowNum): Cell => ({ row: rowNum, column: this.column.index }),
);
return mergeForCells(source, table, cells, this.formatter);
};
}

export class CellDestination implements Destination {
private row: AbsoluteRow;
private column: AbsoluteColumn;
private formatter: Formatter;
private readonly row: AbsoluteRow;
private readonly column: AbsoluteColumn;
private readonly formatter: Formatter;

constructor(ast: IToken, table: Table, formatter: Formatter) {
this.formatter = formatter;
Expand Down Expand Up @@ -169,13 +165,13 @@ export class CellDestination implements Destination {
}

export class RangeDestination implements Destination {
private range: Range;
private formatter: Formatter;
private readonly range: Range;
private readonly formatter: Formatter;

constructor(ast: IToken, table: Table, formatter: Formatter) {
this.formatter = formatter;

let typeErr = checkType(ast, 'range');
const typeErr = checkType(ast, 'range');
if (typeErr) {
throw typeErr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/calc/display_directive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IToken } from 'ebnf';
import { checkChildLength, checkType } from './ast_utils';
import { IToken } from 'ebnf';

export interface Formatter {
format(num: number | string): string;
Expand All @@ -15,7 +15,7 @@ export class DefaultFormatter {
}

export class DisplayDirective {
private decimalLength: number;
private readonly decimalLength: number;

constructor(ast: IToken) {
let typeError = checkType(ast, 'display_directive');
Expand Down
40 changes: 19 additions & 21 deletions src/calc/range.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { err, ok, Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import { Cell, checkChildLength, checkType, ValueProvider } from './ast_utils';
import { Column } from './column';
import { Reference } from './reference';
import { Value } from './results';
import { Row } from './row';
import { IToken } from 'ebnf';
import { flatMap, map, range } from 'lodash';
import { Row } from './row';
import { Column } from './column';

export class Range implements ValueProvider {
private startRow: Row | undefined;
private startColumn: Column | undefined;
private endRow: Row | undefined;
private endColumn: Column | undefined;
private readonly startRow: Row | undefined;
private readonly startColumn: Column | undefined;
private readonly endRow: Row | undefined;
private readonly endColumn: Column | undefined;

constructor(ast: IToken, table: Table) {
let typeErr = checkType(ast, 'range');
Expand Down Expand Up @@ -79,19 +79,19 @@ export class Range implements ValueProvider {
currentCell: Cell,
): Result<Value, Error> => {
// if no start column is provided, copy it from the currentCell
let startColumn = this.startColumn
const startColumn = this.startColumn
? this.startColumn.getIndex(currentCell)
: currentCell.column;

// if the column is provided in the first set, but not the second, copy it
let endColumn = this.endColumn
const endColumn = this.endColumn
? this.endColumn.getIndex(currentCell)
: startColumn;

let startRow = this.startRow
const startRow = this.startRow
? this.startRow.getIndex(currentCell)
: currentCell.row;
let endRow = this.endRow
const endRow = this.endRow
? this.endRow.getIndex(currentCell)
: currentCell.row;

Expand Down Expand Up @@ -124,10 +124,10 @@ export class Range implements ValueProvider {
endColumn = this.startColumn;
}

const startRowIndex = this.startRow.getAbsoluteIndex(),
endRowIndex = this.endRow.getAbsoluteIndex(),
startColumnIndex = this.startColumn.getAbsoluteIndex(),
endColumnIndex = endColumn.getAbsoluteIndex();
const startRowIndex = this.startRow.getAbsoluteIndex();
const endRowIndex = this.endRow.getAbsoluteIndex();
const startColumnIndex = this.startColumn.getAbsoluteIndex();
const endColumnIndex = endColumn.getAbsoluteIndex();

if (
startRowIndex.isErr() ||
Expand All @@ -140,17 +140,15 @@ export class Range implements ValueProvider {
);
}

const minRow = Math.min(startRowIndex.value, endRowIndex.value),
maxRow = Math.max(startRowIndex.value, endRowIndex.value),
minColumn = Math.min(startColumnIndex.value, endColumnIndex.value),
maxColumn = Math.max(startColumnIndex.value, endColumnIndex.value);
const minRow = Math.min(startRowIndex.value, endRowIndex.value);
const maxRow = Math.max(startRowIndex.value, endRowIndex.value);
const minColumn = Math.min(startColumnIndex.value, endColumnIndex.value);
const maxColumn = Math.max(startColumnIndex.value, endColumnIndex.value);

return ok(
flatMap(range(minRow, maxRow + 1), (rowNum): Cell[] =>
range(minColumn, maxColumn + 1).map(
(colNum): Cell => {
return { row: rowNum, column: colNum };
},
(colNum): Cell => ({ row: rowNum, column: colNum }),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions src/calc/reference.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ok, Result } from '../neverthrow/neverthrow';
import { Table } from '../table';
import { Cell, checkType, errIndex0 } from './ast_utils';
import { IToken } from 'ebnf';
import { Column, newColumn } from './column';
import { Value } from './results';
import { newRow, Row } from './row';
import { Column, newColumn } from './column';
import { IToken } from 'ebnf';

export class Reference {
row: Row | undefined;
Expand Down
Loading

0 comments on commit 05e08b5

Please sign in to comment.