diff --git a/.eslintrc b/.eslintrc index 69ebb7529..03557ea7a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ "default-case": ["off"], "func-names": ["off", "never"], "global-require": ["off"], - "max-len": ["error", {"code": 100, "ignoreComments": true, "ignoreStrings": true}], + "max-len": ["error", {"code": 120, "ignoreComments": true, "ignoreStrings": true}], "no-console": ["error", { "allow": ["warn"] }], "no-continue": ["off"], "no-mixed-operators": ["error", {"allowSamePrecedence": true}], @@ -31,7 +31,7 @@ "no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"], "no-return-assign": ["off"], "no-trailing-spaces": ["error", { "skipBlankLines": true }], - "no-underscore-dangle": ["error", { "allowAfterThis": true, "allowAfterSuper": true }], + "no-underscore-dangle": ["off", { "allowAfterThis": true, "allowAfterSuper": true }], "no-unused-vars": ["error", {"vars": "all", "args": "none", "ignoreRestSiblings": true}], "no-use-before-define": ["error", { "variables": false, "classes": false, "functions": false }], "node/no-unsupported-features/es-syntax": ["error", {"version": ">=10.0.0","ignores": []}], diff --git a/lib/doc/anchor.js b/lib/doc/anchor.js index a1f6cda98..9aa5f70e2 100644 --- a/lib/doc/anchor.js +++ b/lib/doc/anchor.js @@ -38,7 +38,7 @@ class Anchor { } get col() { - return this.nativeCol + Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth; + return this.nativeCol + (Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth); } set col(v) { @@ -47,7 +47,7 @@ class Anchor { } get row() { - return this.nativeRow + Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight; + return this.nativeRow + (Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight); } set row(v) { diff --git a/lib/doc/worksheet.js b/lib/doc/worksheet.js index f4b608881..ac2f4613b 100644 --- a/lib/doc/worksheet.js +++ b/lib/doc/worksheet.js @@ -477,9 +477,7 @@ class Worksheet { if (cell._value.constructor.name === 'MergeValue') { const cellToBeMerged = this.getRow(cell._row._number + nInserts).getCell(colNumber); const prevMaster = cell._value._master; - const newMaster = this - .getRow(prevMaster._row._number + nInserts) - .getCell(prevMaster._column._number) + const newMaster = this.getRow(prevMaster._row._number + nInserts).getCell(prevMaster._column._number); cellToBeMerged.merge(newMaster); } }); @@ -712,15 +710,12 @@ class Worksheet { }; if (options && 'spinCount' in options) { // force spinCount to be integer >= 0 - options.spinCount = Number.isFinite(options.spinCount) - ? Math.round(Math.max(0, options.spinCount)) - : 100000; + options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000; } if (password) { this.sheetProtection.algorithmName = 'SHA-512'; this.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64'); - this.sheetProtection.spinCount = - options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount + this.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount this.sheetProtection.hashValue = Encryptor.convertPasswordToHash( password, 'SHA512', @@ -782,17 +777,13 @@ class Worksheet { // Deprecated get tabColor() { // eslint-disable-next-line no-console - console.trace( - 'worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor' - ); + console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor'); return this.properties.tabColor; } set tabColor(value) { // eslint-disable-next-line no-console - console.trace( - 'worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor' - ); + console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor'); this.properties.tabColor = value; } diff --git a/lib/stream/xlsx/worksheet-writer.js b/lib/stream/xlsx/worksheet-writer.js index 522b6beb6..96705b7f0 100644 --- a/lib/stream/xlsx/worksheet-writer.js +++ b/lib/stream/xlsx/worksheet-writer.js @@ -184,7 +184,7 @@ class WorksheetWriter { // worksheet protection this.sheetProtection = null; - + // start writing to stream now this._writeOpenWorksheet(); @@ -492,13 +492,18 @@ class WorksheetWriter { }; if (options && 'spinCount' in options) { // force spinCount to be integer >= 0 - options.spinCount = isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000; + options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000; } if (password) { this.sheetProtection.algorithmName = 'SHA-512'; this.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64'); this.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount - this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(password, 'SHA512', this.sheetProtection.saltValue, this.sheetProtection.spinCount); + this.sheetProtection.hashValue = Encryptor.convertPasswordToHash( + password, + 'SHA512', + this.sheetProtection.saltValue, + this.sheetProtection.spinCount + ); } if (options) { this.sheetProtection = Object.assign(this.sheetProtection, options); @@ -513,7 +518,7 @@ class WorksheetWriter { unprotect() { this.sheetProtection = null; } - + // ================================================================================ _write(text) { diff --git a/lib/utils/under-dash.js b/lib/utils/under-dash.js index a7ed93183..65c931d22 100644 --- a/lib/utils/under-dash.js +++ b/lib/utils/under-dash.js @@ -99,7 +99,7 @@ const _ = { case '&': escape = '&'; break; - case "'": + case '\'': escape = '''; break; case '<': diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 5e68b839d..a85af676d 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -53,12 +53,10 @@ const utils = { }, inherits, dateToExcel(d, date1904) { - return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0); + return 25569 + ( d.getTime() / (24 * 3600 * 1000) ) - (date1904 ? 1462 : 0); }, excelToDate(v, date1904) { - const millisecondSinceEpoch = Math.round( - (v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000 - ); + const millisecondSinceEpoch = Math.round((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000); return new Date(millisecondSinceEpoch); }, parsePath(filepath) { diff --git a/package.json b/package.json index 5a75bfae8..33c1f7fde 100644 --- a/package.json +++ b/package.json @@ -142,6 +142,7 @@ "prettier-eslint": "^11.0.0", "prettier-eslint-cli": "^5.0.0", "regenerator-runtime": "^0.13.7", + "sax": "^1.2.4", "ts-node": "^8.10.2", "typescript": "^3.9.7" } diff --git a/spec/unit/doc/worksheet.merge.spec.js b/spec/unit/doc/worksheet.merge.spec.js index 765465f58..4c8c7b147 100644 --- a/spec/unit/doc/worksheet.merge.spec.js +++ b/spec/unit/doc/worksheet.merge.spec.js @@ -217,15 +217,15 @@ describe('Worksheet', () => { const wb = new Excel.Workbook(); const ws = wb.addWorksheet('testMergeAfterInsert'); - ws.addRow([1,2]); - ws.addRow([3,4]); + ws.addRow([1, 2]); + ws.addRow([3, 4]); ws.mergeCells('A1:B2'); ws.insertRow(1, ['Inserted Row Text']); const r2 = ws.getRow(2); const r3 = ws.getRow(3); - let cellVals = []; + const cellVals = []; for (const r of [r2, r3]) { for (const cell of r._cells) { cellVals.push(cell._value); @@ -234,15 +234,15 @@ describe('Worksheet', () => { let nNumberVals = 0; let nMergeVals = 0; - for (let cellVal of cellVals) { - const name = cellVal.constructor.name; - if (name === 'NumberValue') nNumberVals += 1; - if (name === 'MergeValue' && cellVal.model.master === "A2") { - nMergeVals += 1; - } + for (const cellVal of cellVals) { + const {name} = cellVal.constructor; + if (name === 'NumberValue') nNumberVals += 1; + if (name === 'MergeValue' && cellVal.model.master === 'A2') { + nMergeVals += 1; + } } expect(nNumberVals).to.deep.equal(1); expect(nMergeVals).to.deep.equal(3); - }) + }); }); }); diff --git a/test/regression/utils/hr-stopwatch.js b/test/regression/utils/hr-stopwatch.js index ac2640562..d95b14002 100644 --- a/test/regression/utils/hr-stopwatch.js +++ b/test/regression/utils/hr-stopwatch.js @@ -28,8 +28,8 @@ HrStopwatch.prototype = { get _span() { const hrNow = process.hrtime(); - const start = this.hrStart[0] + this.hrStart[1] / 1e9; - const finish = hrNow[0] + hrNow[1] / 1e9; + const start = this.hrStart[0] + (this.hrStart[1] / 1e9); + const finish = hrNow[0] + (hrNow[1] / 1e9); return finish - start; }, diff --git a/test/test-cf.js b/test/test-cf.js index a1e016161..69d0deddf 100644 --- a/test/test-cf.js +++ b/test/test-cf.js @@ -39,8 +39,8 @@ function addDateTable(ws, ref) { const now = Date.now(); const today = now - (now % DAY); let dt = new Date(today); - const sow = today - (dt.getDay() - 1) * DAY; - const som = sow - 28 * DAY; + const sow = today - ( (dt.getDay() - 1) * DAY ); + const som = sow - (28 * DAY); dt = new Date(som); for (let i = 1; i <= 9; i++) { diff --git a/test/test-chart.js b/test/test-chart.js index 43201e6ea..31548e452 100644 --- a/test/test-chart.js +++ b/test/test-chart.js @@ -12,7 +12,7 @@ const today = now - (now % 86400000); const getRows = () => { const rows = []; for (let i = 0; i < 20; i++) { - rows.push([new Date(today + 86400000 * i), Math.random() * 10]); + rows.push([new Date(today + (86400000 * i)), Math.random() * 10]); } return rows; }; diff --git a/test/test-protection-spinCount.js b/test/test-protection-spinCount.js index 39f84278a..5ec0d5936 100644 --- a/test/test-protection-spinCount.js +++ b/test/test-protection-spinCount.js @@ -37,6 +37,7 @@ async function save() { 31415.9265, ]; + /*eslint-disable no-await-in-loop*/ for (let index = 0; index < values.length; index += 1) { const value = values[index]; @@ -49,6 +50,7 @@ async function save() { await wb.xlsx.writeFile(`${index + 2}-${filename}`); } + /*eslint-enable no-await-in-loop*/ } save().catch(error => { diff --git a/test/test-table.js b/test/test-table.js index f0401552d..c85e6bdca 100644 --- a/test/test-table.js +++ b/test/test-table.js @@ -54,7 +54,7 @@ ws.addTable({ style: {font: {bold: true, name: 'Comic Sans MS'}}, }, ], - rows: words.map((word, i) => [new Date(+today + 86400 * i), i, word]), + rows: words.map((word, i) => [new Date(+today + (86400 * i)), i, word]), }); const stopwatch = new HrStopwatch(); diff --git a/test/testBigBookOut.js b/test/testBigBookOut.js index ed9a4b29c..c05c1f84f 100644 --- a/test/testBigBookOut.js +++ b/test/testBigBookOut.js @@ -96,7 +96,7 @@ function addRow() { num1: utils.randomNum(10000), num2: utils.randomNum(100000), num3: utils.randomNum(1000000), - date: new Date(today + iCount * 86400000), + date: new Date(today + (iCount * 86400000)), num4: utils.randomNum(1000), }); const lap = sw.span; diff --git a/test/utils/hr-stopwatch.js b/test/utils/hr-stopwatch.js index ac2640562..d95b14002 100644 --- a/test/utils/hr-stopwatch.js +++ b/test/utils/hr-stopwatch.js @@ -28,8 +28,8 @@ HrStopwatch.prototype = { get _span() { const hrNow = process.hrtime(); - const start = this.hrStart[0] + this.hrStart[1] / 1e9; - const finish = hrNow[0] + hrNow[1] / 1e9; + const start = this.hrStart[0] + (this.hrStart[1] / 1e9); + const finish = hrNow[0] + (hrNow[1] / 1e9); return finish - start; },