Skip to content

fix #1598 lint violations #1599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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}],
Expand All @@ -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": []}],
Expand Down
4 changes: 2 additions & 2 deletions lib/doc/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
19 changes: 5 additions & 14 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 9 additions & 4 deletions lib/stream/xlsx/worksheet-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class WorksheetWriter {

// worksheet protection
this.sheetProtection = null;

// start writing to stream now
this._writeOpenWorksheet();

Expand Down Expand Up @@ -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);
Expand All @@ -513,7 +518,7 @@ class WorksheetWriter {
unprotect() {
this.sheetProtection = null;
}

// ================================================================================

_write(text) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/under-dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const _ = {
case '&':
escape = '&';
break;
case "'":
case '\'':
escape = ''';
break;
case '<':
Expand Down
6 changes: 2 additions & 4 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
20 changes: 10 additions & 10 deletions spec/unit/doc/worksheet.merge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
})
});
});
});
4 changes: 2 additions & 2 deletions test/regression/utils/hr-stopwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down
4 changes: 2 additions & 2 deletions test/test-cf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions test/test-protection-spinCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

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

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

save().catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion test/test-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/testBigBookOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/utils/hr-stopwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down