Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use arrow-parens only as-needed
  • Loading branch information
alubbe committed Sep 28, 2020
commit 51cfe072109082af2a344a3524c2e5870132024c
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"node": true
},
"rules": {
"arrow-parens": ["error", "as-needed"],
"class-methods-use-this": ["off"],
"comma-dangle": ["error", {"arrays": "always-multiline", "objects": "always-multiline", "imports": "always-multiline", "exports": "always-multiline", "functions": "never"}],
"default-case": ["off"],
Expand Down
3 changes: 2 additions & 1 deletion .prettier
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"bracketSpacing": false,
"printWidth": 160,
"trailingComma": "all",
"bracketSpacing": false
"bracketSpacing": true,
"arrowParens": "avoid"
}
4 changes: 2 additions & 2 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const runs = 3;

let worksheetCount = 0;
let rowCount = 0;
workbookReader.on('worksheet', (worksheet) => {
workbookReader.on('worksheet', worksheet => {
worksheetCount += 1;
console.log(`Reading worksheet ${worksheetCount}`);
worksheet.on('row', (row) => {
worksheet.on('row', row => {
rowCount += 1;
if (rowCount % 50000 === 0) console.log(`Reading row ${rowCount}`);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/csv/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CSV {

const csvStream = fastCsv
.parse(options.parserOptions)
.on('data', (data) => {
.on('data', data => {
worksheet.addRow(data.map(map));
})
.on('end', () => {
Expand Down Expand Up @@ -120,7 +120,7 @@ class CSV {
const {dateFormat, dateUTC} = options;
const map =
options.map ||
((value) => {
(value => {
if (value) {
if (value.text || value.hyperlink) {
return value.hyperlink || value.text || '';
Expand Down
2 changes: 1 addition & 1 deletion lib/csv/line-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LineBuffer extends EventEmitter {

_flush() {
if (!this.corked) {
this.queue.forEach((line) => {
this.queue.forEach(line => {
this.emit('line', line);
});
this.queue = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/csv/stream-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class StreamConverter {
on(type, callback) {
switch (type) {
case 'data':
this.inner.on('data', (chunk) => {
this.inner.on('data', chunk => {
callback(this.convertOutwards(chunk));
});
return this;
Expand Down
6 changes: 3 additions & 3 deletions lib/doc/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Cell {
set names(value) {
const {definedNames} = this.workbook;
definedNames.removeAllNames(this.fullAddress);
value.forEach((name) => {
value.forEach(name => {
definedNames.addEx(this.fullAddress, name);
});
}
Expand Down Expand Up @@ -509,7 +509,7 @@ class RichTextValue {
}

toString() {
return this.model.value.richText.map((t) => t.text).join('');
return this.model.value.richText.map(t => t.text).join('');
}

get type() {
Expand Down Expand Up @@ -748,7 +748,7 @@ class FormulaValue {

_copyModel(model) {
const copy = {};
const cp = (name) => {
const cp = name => {
const value = model[name];
if (value) {
copy[name] = value;
Expand Down
2 changes: 1 addition & 1 deletion lib/doc/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Column {
// styles
_applyStyle(name, value) {
this.style[name] = value;
this.eachCell((cell) => {
this.eachCell(cell => {
cell[name] = value;
});
return value;
Expand Down
20 changes: 10 additions & 10 deletions lib/doc/defined-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class DefinedNames {
}

removeAllNames(location) {
_.each(this.matrixMap, (matrix) => {
_.each(this.matrixMap, matrix => {
matrix.removeCellEx(location);
});
}

forEach(callback) {
_.each(this.matrixMap, (matrix, name) => {
matrix.forEach((cell) => {
matrix.forEach(cell => {
callback(name, cell);
});
});
Expand Down Expand Up @@ -128,13 +128,13 @@ class DefinedNames {
}

// mark and sweep!
matrix.forEach((cell) => {
matrix.forEach(cell => {
cell.mark = true;
});
const ranges = matrix
.map((cell) => cell.mark && this._explore(matrix, cell))
.map(cell => cell.mark && this._explore(matrix, cell))
.filter(Boolean)
.map((range) => range.$shortRange);
.map(range => range.$shortRange);

return {
name,
Expand All @@ -157,30 +157,30 @@ class DefinedNames {
}

spliceRows(sheetName, start, numDelete, numInsert) {
_.each(this.matrixMap, (matrix) => {
_.each(this.matrixMap, matrix => {
matrix.spliceRows(sheetName, start, numDelete, numInsert);
this.normaliseMatrix(matrix, sheetName);
});
}

spliceColumns(sheetName, start, numDelete, numInsert) {
_.each(this.matrixMap, (matrix) => {
_.each(this.matrixMap, matrix => {
matrix.spliceColumns(sheetName, start, numDelete, numInsert);
this.normaliseMatrix(matrix, sheetName);
});
}

get model() {
// To get names per cell - just iterate over all names finding cells if they exist
return _.map(this.matrixMap, (matrix, name) => this.getRanges(name, matrix)).filter((definedName) => definedName.ranges.length);
return _.map(this.matrixMap, (matrix, name) => this.getRanges(name, matrix)).filter(definedName => definedName.ranges.length);
}

set model(value) {
// value is [ { name, ranges }, ... ]
const matrixMap = (this.matrixMap = {});
value.forEach((definedName) => {
value.forEach(definedName => {
const matrix = (matrixMap[definedName.name] = new CellMatrix());
definedName.ranges.forEach((rangeStr) => {
definedName.ranges.forEach(rangeStr => {
if (rangeRegexp.test(rangeStr.split('!').pop() || '')) {
matrix.addCell(rangeStr);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/doc/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Row {
// return a sparse array of cell values
get values() {
const values = [];
this._cells.forEach((cell) => {
this._cells.forEach(cell => {
if (cell && cell.type !== Enums.ValueType.Null) {
values[cell.col] = cell.value;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ class Row {

// returns true if the row includes at least one cell with a value
get hasValues() {
return _.some(this._cells, (cell) => cell && cell.type !== Enums.ValueType.Null);
return _.some(this._cells, cell => cell && cell.type !== Enums.ValueType.Null);
}

get cellCount() {
Expand All @@ -229,7 +229,7 @@ class Row {
get dimensions() {
let min = 0;
let max = 0;
this._cells.forEach((cell) => {
this._cells.forEach(cell => {
if (cell && cell.type !== Enums.ValueType.Null) {
if (!min || min > cell.col) {
min = cell.col;
Expand All @@ -251,7 +251,7 @@ class Row {
// styles
_applyStyle(name, value) {
this.style[name] = value;
this._cells.forEach((cell) => {
this._cells.forEach(cell => {
if (cell) {
cell[name] = value;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ class Row {
const cells = [];
let min = 0;
let max = 0;
this._cells.forEach((cell) => {
this._cells.forEach(cell => {
if (cell) {
const cellModel = cell.model;
if (cellModel) {
Expand Down Expand Up @@ -368,7 +368,7 @@ class Row {
}
this._cells = [];
let previousAddress;
value.cells.forEach((cellModel) => {
value.cells.forEach(cellModel => {
switch (cellModel.type) {
case Cell.Types.Merge:
// special case - don't add this types
Expand Down
8 changes: 4 additions & 4 deletions lib/doc/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Table {
// the sheet...
const assignStyle = (cell, style) => {
if (style) {
Object.keys(style).forEach((key) => {
Object.keys(style).forEach(key => {
cell[key] = style[key];
});
}
Expand All @@ -200,7 +200,7 @@ class Table {
assignStyle(cell, style);
});
}
table.rows.forEach((data) => {
table.rows.forEach(data => {
const r = worksheet.getRow(row + count++);
data.forEach((value, j) => {
const cell = r.getCell(col + j);
Expand Down Expand Up @@ -245,7 +245,7 @@ class Table {
cell.value = column.name;
});
}
table.rows.forEach((data) => {
table.rows.forEach(data => {
const r = worksheet.getRow(row + count++);
data.forEach((value, j) => {
const cell = r.getCell(col + j);
Expand Down Expand Up @@ -379,7 +379,7 @@ class Table {
this.cacheState();

this.table.columns.splice(colIndex, count);
this.table.rows.forEach((row) => {
this.table.rows.forEach(row => {
row.splice(colIndex, count);
});
}
Expand Down
14 changes: 7 additions & 7 deletions lib/doc/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Workbook {
console.warn(`Worksheet name ${name} exceeds 31 chars. This will be truncated`);
}
name = (name || `sheet${id}`).substring(0, 31);
if (this._worksheets.find((ws) => ws && ws.name.toLowerCase() === name.toLowerCase())) {
if (this._worksheets.find(ws => ws && ws.name.toLowerCase() === name.toLowerCase())) {
throw new Error(`Worksheet name already exists: ${name}`);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ class Workbook {
return this._worksheets[id];
}
if (typeof id === 'string') {
return this._worksheets.find((worksheet) => worksheet && worksheet.name === id);
return this._worksheets.find(worksheet => worksheet && worksheet.name === id);
}
return undefined;
}
Expand All @@ -123,7 +123,7 @@ class Workbook {
}

eachSheet(iteratee) {
this.worksheets.forEach((sheet) => {
this.worksheets.forEach(sheet => {
iteratee(sheet, sheet.id);
});
}
Expand Down Expand Up @@ -156,8 +156,8 @@ class Workbook {
created: this.created,
modified: this.modified,
properties: this.properties,
worksheets: this.worksheets.map((worksheet) => worksheet.model),
sheets: this.worksheets.map((ws) => ws.model).filter(Boolean),
worksheets: this.worksheets.map(worksheet => worksheet.model),
sheets: this.worksheets.map(ws => ws.model).filter(Boolean),
definedNames: this._definedNames.model,
views: this.views,
company: this.company,
Expand Down Expand Up @@ -196,9 +196,9 @@ class Workbook {
this.properties = value.properties;
this.calcProperties = value.calcProperties;
this._worksheets = [];
value.worksheets.forEach((worksheetModel) => {
value.worksheets.forEach(worksheetModel => {
const {id, name, state} = worksheetModel;
const orderNo = value.sheets && value.sheets.findIndex((ws) => ws.id === id);
const orderNo = value.sheets && value.sheets.findIndex(ws => ws.id === id);
const worksheet = (this._worksheets[id] = new Worksheet({
id,
name,
Expand Down
Loading