diff --git a/package.json b/package.json index 76e9b89..e34fe8f 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "build": "tsc", "format": "prettier --write \"src/**/*.ts\"", "lint": "tslint -p tsconfig.json", + "lint:fix": "tslint -p tsconfig.json --fix", "test": "mocha -r ts-node/register tests/**/*.test.ts", "coverageRaport": "nyc -r lcov -e .ts -x \"*.test.ts\" mocha -r ts-node/register tests/**/*.test.ts && nyc report", "prepublishOnly": "npm test && npm run lint && npm run build", diff --git a/src/CellTemplateDebugPool.ts b/src/CellTemplateDebugPool.ts index 5cee4f6..fc9e3b9 100644 --- a/src/CellTemplateDebugPool.ts +++ b/src/CellTemplateDebugPool.ts @@ -1,7 +1,7 @@ import { CellTemplatePool } from './CellTemplatePool'; import { Cell } from 'exceljs'; import { BaseCell } from './cell/BaseCell'; - +/* tslint:disable:no-console */ export class CellTemplateDebugPool extends CellTemplatePool { /** * do normal match and log in console result. diff --git a/src/cell/AverageCell.ts b/src/cell/AverageCell.ts index 3512512..867858e 100644 --- a/src/cell/AverageCell.ts +++ b/src/cell/AverageCell.ts @@ -1,8 +1,16 @@ import { BaseCell } from './BaseCell'; import { Scope } from '../Scope'; import { Cell, CellFormulaValue, ValueType } from 'exceljs'; - +/* tslint:disable:variable-name */ export class AverageCell extends BaseCell { + + public static match(cell: Cell): boolean { + return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 10) === '#! AVERAGE'; + } + + protected static getTargetParam(scope: Scope): string { + return scope.getCurrentTemplateValue()?.toString().split(' ')[2] || ''; + } public apply(scope: Scope): AverageCell { super.apply(scope); @@ -11,8 +19,8 @@ export class AverageCell extends BaseCell { const __endOutput = scope.vm[target] && scope.vm[target].__endOutput; if (__startOutput && __endOutput) { - const start = scope.output.worksheets[scope.outputCell.ws].getCell(__startOutput, scope.outputCell.c).address; //todo refactoring - const end = scope.output.worksheets[scope.outputCell.ws].getCell(__endOutput, scope.outputCell.c).address; //todo refactoring + const start = scope.output.worksheets[scope.outputCell.ws].getCell(__startOutput, scope.outputCell.c).address; // todo refactoring + const end = scope.output.worksheets[scope.outputCell.ws].getCell(__endOutput, scope.outputCell.c).address; // todo refactoring scope.setCurrentOutputValue({ formula: `average(${start}:${end})` } as CellFormulaValue); } @@ -21,12 +29,4 @@ export class AverageCell extends BaseCell { return this; } - - protected static getTargetParam(scope: Scope): string { - return scope.getCurrentTemplateValue()?.toString().split(' ')[2] || ''; - } - - public static match(cell: Cell): boolean { - return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 10) === '#! AVERAGE'; - } } \ No newline at end of file diff --git a/src/cell/DeleteCell.ts b/src/cell/DeleteCell.ts index cdb228d..963c886 100644 --- a/src/cell/DeleteCell.ts +++ b/src/cell/DeleteCell.ts @@ -10,9 +10,9 @@ export class DeleteCell extends BaseCell { public apply(scope: Scope): DeleteCell { super.apply(scope); - const target = scope.getCurrentTemplateValue()?.toString().split(' ')[2]; //todo make some function for scope.getCurrentTemplateValue()?.toString().split(' ') ; + const target = scope.getCurrentTemplateValue()?.toString().split(' ')[2]; // todo make some function for scope.getCurrentTemplateValue()?.toString().split(' ') ; - if (target == undefined) return this; //it's ok here + if (target === undefined) { return this; } // it's ok here scope.vm[target] = undefined; diff --git a/src/cell/DumpColsCell.ts b/src/cell/DumpColsCell.ts index a1a8167..97f1917 100644 --- a/src/cell/DumpColsCell.ts +++ b/src/cell/DumpColsCell.ts @@ -3,7 +3,7 @@ import { Cell, ValueType } from 'exceljs'; import { Scope } from '../Scope'; export class DumpColsCell extends BaseCell { - static match(cell: Cell): boolean { + public static match(cell: Cell): boolean { return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 12) === '#! DUMP_COLS'; } diff --git a/src/cell/EndLoopCell.ts b/src/cell/EndLoopCell.ts index 0088a68..5efad25 100644 --- a/src/cell/EndLoopCell.ts +++ b/src/cell/EndLoopCell.ts @@ -2,6 +2,7 @@ import { BaseCell } from './BaseCell'; import { Cell, ValueType } from 'exceljs'; import { Scope } from '../Scope'; +/* tslint:disable:variable-name */ export class EndLoopCell extends BaseCell { public static match(cell: Cell): boolean { return ( diff --git a/src/cell/FinishCell.ts b/src/cell/FinishCell.ts index 5422046..9a91d8c 100644 --- a/src/cell/FinishCell.ts +++ b/src/cell/FinishCell.ts @@ -2,6 +2,7 @@ import { BaseCell } from './BaseCell'; import { Cell, ValueType } from 'exceljs'; import { Scope } from '../Scope'; +/* tslint:disable:variable-name */ export class FinishCell extends BaseCell { public static match(cell: Cell): boolean { return ( @@ -18,12 +19,8 @@ export class FinishCell extends BaseCell { * * condition's path follow to undefined * * condition is true * In other way, the same template sheet should render next output sheet - as long as condition is false - * - * @param {Scope} scope - * @returns {boolean} - * @protected */ - private static _getCondition(scope: Scope): boolean { + protected static getCondition(scope: Scope): boolean { const args = scope .getCurrentTemplateValue() @@ -44,7 +41,7 @@ export class FinishCell extends BaseCell { let wst = scope.template.worksheets[scope.templateCell.ws]; - if (FinishCell._getCondition(scope)) { + if (FinishCell.getCondition(scope)) { // todo refactoring scope.iterateWorksheet const wstNext = scope.templateCell.ws + 1; diff --git a/src/cell/ForEachCell.ts b/src/cell/ForEachCell.ts index 846da6f..bb0be56 100644 --- a/src/cell/ForEachCell.ts +++ b/src/cell/ForEachCell.ts @@ -2,6 +2,7 @@ import { BaseCell } from './BaseCell'; import { Scope } from '../Scope'; import { Cell, ValueType } from 'exceljs'; +/* tslint:disable:variable-name */ /** * Pattern: `#! FOR_EACH [TARGET] [SOURCE]` * Iterate through `vm[SOURCE]` and store current item in readonly `vm[TARGET]`. @@ -25,16 +26,12 @@ export class ForEachCell extends BaseCell { return scope.getCurrentTemplateValue()?.toString().split(' ')[2] || ''; } - protected getSourceParam(scope: Scope): string { - return scope.getCurrentTemplateValue()?.toString().split(' ')[3] || ''; - } - public apply(scope: Scope): ForEachCell { const target = ForEachCell.getTargetParam(scope); const __from = this.getSourceParam(scope); - //todo refactoring + // todo refactoring const __index = (scope.vm[target] && scope.vm[target].__index || 0) + 1; if (__index === 1) { super.apply(scope); @@ -65,7 +62,7 @@ export class ForEachCell extends BaseCell { __insetRows = false; if (!scope.isFrozen()) { for (let i = __end.r; i > __start.r; i--) { - scope.output.worksheets[scope.outputCell.ws].spliceRows( //todo refactoring + scope.output.worksheets[scope.outputCell.ws].spliceRows( // todo refactoring scope.outputCell.r + 1, 0, [], @@ -95,4 +92,8 @@ export class ForEachCell extends BaseCell { return this; } + + protected getSourceParam(scope: Scope): string { + return scope.getCurrentTemplateValue()?.toString().split(' ')[3] || ''; + } } diff --git a/src/cell/FormulaCell.ts b/src/cell/FormulaCell.ts index e7026a2..8f3378f 100644 --- a/src/cell/FormulaCell.ts +++ b/src/cell/FormulaCell.ts @@ -1,22 +1,12 @@ -import { BaseCell } from './BaseCell'; -import { Cell, CellFormulaValue, ValueType } from 'exceljs'; -import { Scope } from '../Scope'; +import {BaseCell} from './BaseCell'; +import {Cell, CellFormulaValue, ValueType} from 'exceljs'; +import {Scope} from '../Scope'; export class FormulaCell extends BaseCell { - /** - * @inheritDoc - * @param {Cell} cell - * @returns {boolean} - */ public static match(cell: Cell): boolean { return cell && cell.type === ValueType.Formula; } - /** - * @inheritDoc - * @param {Scope} scope - * @returns {FormulaCell} - */ public apply(scope: Scope): FormulaCell { super.apply(scope); @@ -26,16 +16,20 @@ export class FormulaCell extends BaseCell { const value = scope.getCurrentTemplateValue() as CellFormulaValue; let formula = value.formula; - //todo extract method match addresses - let matches; - let addresses = []; - while (matches = regex.exec(formula)) { + // todo extract method match addresses + const addresses = []; + while (true) { + const matches = regex.exec(formula); + if (matches === null) { + break; + } + addresses.push({index: matches.index, col: matches[1], row: +matches[2], len: matches[0].length}) } addresses.reverse(); - //todo extract method getShiftedFormula - let formulaChars = Array.from(formula); + // todo extract method getShiftedFormula + const formulaChars = Array.from(formula); addresses.forEach(a => formulaChars.splice(a.index, a.len, `${a.col}${a.row + shift}`)); formula = formulaChars.join(''); diff --git a/src/cell/HyperlinkCell.ts b/src/cell/HyperlinkCell.ts index b14d6d2..b9f07bc 100644 --- a/src/cell/HyperlinkCell.ts +++ b/src/cell/HyperlinkCell.ts @@ -23,7 +23,6 @@ export class HyperlinkCell extends BaseCell { const url = HyperlinkCell.getUrlParam(scope).split('.').reduce((p, c) => p[c] || {}, scope.vm); if (typeof url === 'string') { const label = HyperlinkCell.getLabelParam(scope).split('.').reduce((p, c) => p[c] || {}, scope.vm) || url; - console.log(label); scope.setCurrentOutputValue({ text: label, hyperlink: url }); } diff --git a/src/cell/SumCell.ts b/src/cell/SumCell.ts index 80b4d1d..3d93db2 100644 --- a/src/cell/SumCell.ts +++ b/src/cell/SumCell.ts @@ -2,6 +2,7 @@ import { BaseCell } from './BaseCell'; import { Scope } from '../Scope'; import { Cell, CellFormulaValue, ValueType } from 'exceljs'; +/* tslint:disable:variable-name */ export class SumCell extends BaseCell { public static match(cell: Cell): boolean { return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 6) === '#! SUM'; @@ -19,8 +20,8 @@ export class SumCell extends BaseCell { const __endOutput = scope.vm[target] && scope.vm[target].__endOutput; if (__startOutput && __endOutput) { - const start = scope.output.worksheets[scope.outputCell.ws].getCell(__startOutput, scope.outputCell.c).address; //todo refactoring - const end = scope.output.worksheets[scope.outputCell.ws].getCell(__endOutput, scope.outputCell.c).address; //todo refactoring + const start = scope.output.worksheets[scope.outputCell.ws].getCell(__startOutput, scope.outputCell.c).address; // todo refactoring + const end = scope.output.worksheets[scope.outputCell.ws].getCell(__endOutput, scope.outputCell.c).address; // todo refactoring scope.setCurrentOutputValue({ formula: `sum(${start}:${end})` } as CellFormulaValue); } diff --git a/src/cell/VariableCell.ts b/src/cell/VariableCell.ts index dff3f72..3f4ecef 100644 --- a/src/cell/VariableCell.ts +++ b/src/cell/VariableCell.ts @@ -25,6 +25,7 @@ export class VariableCell extends BaseCell { const value = path.reduce((p, c) => (typeof p === 'object' ? p[c] : p), scope.vm); if (value === undefined) { // todo do it better (use logger or somethink like that) + // tslint:disable-next-line:no-console console.warn( `WARN: ${path} is undefined for output: ${scope.outputCell} when template is:${scope.templateCell}`, ); diff --git a/src/example.ts b/src/example.ts index 48ccadb..64e9431 100644 --- a/src/example.ts +++ b/src/example.ts @@ -3,6 +3,7 @@ import { CellTemplateDebugPool } from './CellTemplateDebugPool'; import { CellTemplatePool } from './CellTemplatePool'; import { Workbook } from 'exceljs'; +// tslint:disable:comment-format //* const debug = true; /*/