Skip to content

Commit 18fde32

Browse files
authored
fix exceljs#1598 lint violations (exceljs#1599)
* fix lint errors and warnings
1 parent 4a65a32 commit 18fde32

15 files changed

+43
-46
lines changed

.eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"default-case": ["off"],
2020
"func-names": ["off", "never"],
2121
"global-require": ["off"],
22-
"max-len": ["error", {"code": 100, "ignoreComments": true, "ignoreStrings": true}],
22+
"max-len": ["error", {"code": 120, "ignoreComments": true, "ignoreStrings": true}],
2323
"no-console": ["error", { "allow": ["warn"] }],
2424
"no-continue": ["off"],
2525
"no-mixed-operators": ["error", {"allowSamePrecedence": true}],
@@ -31,7 +31,7 @@
3131
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"],
3232
"no-return-assign": ["off"],
3333
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
34-
"no-underscore-dangle": ["error", { "allowAfterThis": true, "allowAfterSuper": true }],
34+
"no-underscore-dangle": ["off", { "allowAfterThis": true, "allowAfterSuper": true }],
3535
"no-unused-vars": ["error", {"vars": "all", "args": "none", "ignoreRestSiblings": true}],
3636
"no-use-before-define": ["error", { "variables": false, "classes": false, "functions": false }],
3737
"node/no-unsupported-features/es-syntax": ["error", {"version": ">=10.0.0","ignores": []}],

lib/doc/anchor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Anchor {
3838
}
3939

4040
get col() {
41-
return this.nativeCol + Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth;
41+
return this.nativeCol + (Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth);
4242
}
4343

4444
set col(v) {
@@ -47,7 +47,7 @@ class Anchor {
4747
}
4848

4949
get row() {
50-
return this.nativeRow + Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight;
50+
return this.nativeRow + (Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight);
5151
}
5252

5353
set row(v) {

lib/doc/worksheet.js

+5-14
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,7 @@ class Worksheet {
477477
if (cell._value.constructor.name === 'MergeValue') {
478478
const cellToBeMerged = this.getRow(cell._row._number + nInserts).getCell(colNumber);
479479
const prevMaster = cell._value._master;
480-
const newMaster = this
481-
.getRow(prevMaster._row._number + nInserts)
482-
.getCell(prevMaster._column._number)
480+
const newMaster = this.getRow(prevMaster._row._number + nInserts).getCell(prevMaster._column._number);
483481
cellToBeMerged.merge(newMaster);
484482
}
485483
});
@@ -712,15 +710,12 @@ class Worksheet {
712710
};
713711
if (options && 'spinCount' in options) {
714712
// force spinCount to be integer >= 0
715-
options.spinCount = Number.isFinite(options.spinCount)
716-
? Math.round(Math.max(0, options.spinCount))
717-
: 100000;
713+
options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000;
718714
}
719715
if (password) {
720716
this.sheetProtection.algorithmName = 'SHA-512';
721717
this.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64');
722-
this.sheetProtection.spinCount =
723-
options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
718+
this.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
724719
this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(
725720
password,
726721
'SHA512',
@@ -782,17 +777,13 @@ class Worksheet {
782777
// Deprecated
783778
get tabColor() {
784779
// eslint-disable-next-line no-console
785-
console.trace(
786-
'worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor'
787-
);
780+
console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
788781
return this.properties.tabColor;
789782
}
790783

791784
set tabColor(value) {
792785
// eslint-disable-next-line no-console
793-
console.trace(
794-
'worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor'
795-
);
786+
console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
796787
this.properties.tabColor = value;
797788
}
798789

lib/stream/xlsx/worksheet-writer.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class WorksheetWriter {
184184

185185
// worksheet protection
186186
this.sheetProtection = null;
187-
187+
188188
// start writing to stream now
189189
this._writeOpenWorksheet();
190190

@@ -492,13 +492,18 @@ class WorksheetWriter {
492492
};
493493
if (options && 'spinCount' in options) {
494494
// force spinCount to be integer >= 0
495-
options.spinCount = isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000;
495+
options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000;
496496
}
497497
if (password) {
498498
this.sheetProtection.algorithmName = 'SHA-512';
499499
this.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64');
500500
this.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
501-
this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(password, 'SHA512', this.sheetProtection.saltValue, this.sheetProtection.spinCount);
501+
this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(
502+
password,
503+
'SHA512',
504+
this.sheetProtection.saltValue,
505+
this.sheetProtection.spinCount
506+
);
502507
}
503508
if (options) {
504509
this.sheetProtection = Object.assign(this.sheetProtection, options);
@@ -513,7 +518,7 @@ class WorksheetWriter {
513518
unprotect() {
514519
this.sheetProtection = null;
515520
}
516-
521+
517522
// ================================================================================
518523

519524
_write(text) {

lib/utils/under-dash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const _ = {
9999
case '&':
100100
escape = '&';
101101
break;
102-
case "'":
102+
case '\'':
103103
escape = ''';
104104
break;
105105
case '<':

lib/utils/utils.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ const utils = {
5353
},
5454
inherits,
5555
dateToExcel(d, date1904) {
56-
return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0);
56+
return 25569 + ( d.getTime() / (24 * 3600 * 1000) ) - (date1904 ? 1462 : 0);
5757
},
5858
excelToDate(v, date1904) {
59-
const millisecondSinceEpoch = Math.round(
60-
(v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000
61-
);
59+
const millisecondSinceEpoch = Math.round((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000);
6260
return new Date(millisecondSinceEpoch);
6361
},
6462
parsePath(filepath) {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"prettier-eslint": "^11.0.0",
143143
"prettier-eslint-cli": "^5.0.0",
144144
"regenerator-runtime": "^0.13.7",
145+
"sax": "^1.2.4",
145146
"ts-node": "^8.10.2",
146147
"typescript": "^3.9.7"
147148
}

spec/unit/doc/worksheet.merge.spec.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ describe('Worksheet', () => {
217217
const wb = new Excel.Workbook();
218218
const ws = wb.addWorksheet('testMergeAfterInsert');
219219

220-
ws.addRow([1,2]);
221-
ws.addRow([3,4]);
220+
ws.addRow([1, 2]);
221+
ws.addRow([3, 4]);
222222
ws.mergeCells('A1:B2');
223223
ws.insertRow(1, ['Inserted Row Text']);
224224

225225
const r2 = ws.getRow(2);
226226
const r3 = ws.getRow(3);
227227

228-
let cellVals = [];
228+
const cellVals = [];
229229
for (const r of [r2, r3]) {
230230
for (const cell of r._cells) {
231231
cellVals.push(cell._value);
@@ -234,15 +234,15 @@ describe('Worksheet', () => {
234234

235235
let nNumberVals = 0;
236236
let nMergeVals = 0;
237-
for (let cellVal of cellVals) {
238-
const name = cellVal.constructor.name;
239-
if (name === 'NumberValue') nNumberVals += 1;
240-
if (name === 'MergeValue' && cellVal.model.master === "A2") {
241-
nMergeVals += 1;
242-
}
237+
for (const cellVal of cellVals) {
238+
const {name} = cellVal.constructor;
239+
if (name === 'NumberValue') nNumberVals += 1;
240+
if (name === 'MergeValue' && cellVal.model.master === 'A2') {
241+
nMergeVals += 1;
242+
}
243243
}
244244
expect(nNumberVals).to.deep.equal(1);
245245
expect(nMergeVals).to.deep.equal(3);
246-
})
246+
});
247247
});
248248
});

test/regression/utils/hr-stopwatch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ HrStopwatch.prototype = {
2828

2929
get _span() {
3030
const hrNow = process.hrtime();
31-
const start = this.hrStart[0] + this.hrStart[1] / 1e9;
32-
const finish = hrNow[0] + hrNow[1] / 1e9;
31+
const start = this.hrStart[0] + (this.hrStart[1] / 1e9);
32+
const finish = hrNow[0] + (hrNow[1] / 1e9);
3333
return finish - start;
3434
},
3535

test/test-cf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function addDateTable(ws, ref) {
3939
const now = Date.now();
4040
const today = now - (now % DAY);
4141
let dt = new Date(today);
42-
const sow = today - (dt.getDay() - 1) * DAY;
43-
const som = sow - 28 * DAY;
42+
const sow = today - ( (dt.getDay() - 1) * DAY );
43+
const som = sow - (28 * DAY);
4444
dt = new Date(som);
4545

4646
for (let i = 1; i <= 9; i++) {

test/test-chart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const today = now - (now % 86400000);
1212
const getRows = () => {
1313
const rows = [];
1414
for (let i = 0; i < 20; i++) {
15-
rows.push([new Date(today + 86400000 * i), Math.random() * 10]);
15+
rows.push([new Date(today + (86400000 * i)), Math.random() * 10]);
1616
}
1717
return rows;
1818
};

test/test-protection-spinCount.js

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async function save() {
3737
31415.9265,
3838
];
3939

40+
/*eslint-disable no-await-in-loop*/
4041
for (let index = 0; index < values.length; index += 1) {
4142
const value = values[index];
4243

@@ -49,6 +50,7 @@ async function save() {
4950

5051
await wb.xlsx.writeFile(`${index + 2}-${filename}`);
5152
}
53+
/*eslint-enable no-await-in-loop*/
5254
}
5355

5456
save().catch(error => {

test/test-table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ws.addTable({
5454
style: {font: {bold: true, name: 'Comic Sans MS'}},
5555
},
5656
],
57-
rows: words.map((word, i) => [new Date(+today + 86400 * i), i, word]),
57+
rows: words.map((word, i) => [new Date(+today + (86400 * i)), i, word]),
5858
});
5959

6060
const stopwatch = new HrStopwatch();

test/testBigBookOut.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function addRow() {
9696
num1: utils.randomNum(10000),
9797
num2: utils.randomNum(100000),
9898
num3: utils.randomNum(1000000),
99-
date: new Date(today + iCount * 86400000),
99+
date: new Date(today + (iCount * 86400000)),
100100
num4: utils.randomNum(1000),
101101
});
102102
const lap = sw.span;

test/utils/hr-stopwatch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ HrStopwatch.prototype = {
2828

2929
get _span() {
3030
const hrNow = process.hrtime();
31-
const start = this.hrStart[0] + this.hrStart[1] / 1e9;
32-
const finish = hrNow[0] + hrNow[1] / 1e9;
31+
const start = this.hrStart[0] + (this.hrStart[1] / 1e9);
32+
const finish = hrNow[0] + (hrNow[1] / 1e9);
3333
return finish - start;
3434
},
3535

0 commit comments

Comments
 (0)