From e4b676b5aa2665352c31b1a3797ebaaf24dbc2e6 Mon Sep 17 00:00:00 2001 From: guyonroche Date: Wed, 17 May 2017 17:53:52 +0100 Subject: [PATCH] no-underescore-dangle --- .eslintrc | 4 +- lib/csv/line-buffer.js | 4 +- lib/doc/cell.js | 4 +- lib/doc/column.js | 13 +++--- lib/doc/defined-names.js | 9 ++-- lib/doc/row.js | 31 ++++++------- lib/doc/workbook.js | 10 ++--- lib/doc/worksheet.js | 45 ++++++++++++------- lib/stream/xlsx/sheet-rels-writer.js | 1 + lib/stream/xlsx/workbook-reader.js | 21 +++++---- lib/stream/xlsx/workbook-writer.js | 14 +++--- lib/stream/xlsx/worksheet-reader.js | 28 ++++++------ lib/stream/xlsx/worksheet-writer.js | 25 +++++------ lib/utils/flow-control.js | 41 +++++++---------- lib/utils/stream-base64.js | 2 +- lib/utils/stream-buf.js | 12 +++-- lib/utils/string-buf.js | 1 + lib/utils/stuttered-pipe.js | 19 ++++---- lib/utils/utils.js | 1 + spec/.eslintrc | 3 +- .../workbook-xlsx-writer.spec.js | 1 - 21 files changed, 138 insertions(+), 151 deletions(-) diff --git a/.eslintrc b/.eslintrc index 058dc7b24..dbe7df3a9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,6 +10,8 @@ "no-mixed-operators": ["error", {"allowSamePrecedence": true}], "linebreak-style": ["off"], "no-use-before-define": ["error", { "variables": false, "classes": false, "functions": false }], + "no-plusplus": ["off"], + "no-underscore-dangle": ["error", { "allowAfterThis": true, "allowAfterSuper": true }], "no-var": ["off"], "dot-notation": ["off"], @@ -18,7 +20,6 @@ "no-prototype-builtins": ["off"], "arrow-parens": ["off"], "quote-props": ["off"], - "no-underscore-dangle": ["off"], "vars-on-top": ["off"], "no-param-reassign": ["off"], "prefer-arrow-callback": ["off"], @@ -30,7 +31,6 @@ "object-shorthand": ["off"], "prefer-template": ["off"], "object-curly-spacing": ["off"], - "no-plusplus": ["off"], "no-unused-expressions": ["off"], "global-require": ["off"], "no-path-concat": ["off"], diff --git a/lib/csv/line-buffer.js b/lib/csv/line-buffer.js index 466c3f717..f3423619b 100644 --- a/lib/csv/line-buffer.js +++ b/lib/csv/line-buffer.js @@ -27,7 +27,7 @@ utils.inherits(LineBuffer, events.EventEmitter, { // line: here is a line // done: all lines emitted - write: function(chunk, encoding) { + write: function(chunk) { // find line or lines in chunk and emit them if not corked // or queue them if corked var data = this.buffer ? this.buffer + chunk : chunk; @@ -59,7 +59,7 @@ utils.inherits(LineBuffer, events.EventEmitter, { setDefaultEncoding: function() { // ? }, - end: function(chunk, encoding) { + end: function(chunk) { if (this.buffer) { this.emit('line', this.buffer); this.buffer = null; diff --git a/lib/doc/cell.js b/lib/doc/cell.js index de40a51c1..d355f1e56 100644 --- a/lib/doc/cell.js +++ b/lib/doc/cell.js @@ -209,7 +209,7 @@ Cell.prototype = { // if this cell is a string, turn it into a Hyperlink if (this.type === Cell.Types.String) { this._value = Value.create(Cell.Types.Hyperlink, this, { - text: this._value._value, + text: this._value.value, hyperlink: hyperlink }); } @@ -692,7 +692,7 @@ FormulaValue.prototype = { }, _getTranslatedFormula() { if (!this._translatedFormula && this.model.sharedFormula) { - var worksheet = this.cell._row.worksheet; + var worksheet = this.cell.worksheet; var master = worksheet.findCell(this.model.sharedFormula); this._translatedFormula = master && slideFormula(master.formula, master.address, this.model.address); diff --git a/lib/doc/column.js b/lib/doc/column.js index dcc4b3ff9..8a5af92dc 100644 --- a/lib/doc/column.js +++ b/lib/doc/column.js @@ -74,10 +74,9 @@ Column.prototype = { }, set header(value) { if (value !== undefined) { - var self = this; this._header = value; - this.headers.forEach(function(text, index) { - self._worksheet.getCell(index + 1, self.number).value = text; + this.headers.forEach((text, index) => { + this._worksheet.getCell(index + 1, this.number).value = text; }); } else { this._header = []; @@ -87,12 +86,14 @@ Column.prototype = { return this._key; }, set key(value) { - if (this._key && (this._worksheet._keys[this._key] === this)) { - delete this._worksheet._keys[this._key]; + const column = this._key && this._worksheet.getColumnKey(this._key); + if (column === this) { + this._worksheet.deleteColumnKey(this._key); } + this._key = value; if (value) { - this._worksheet._keys[this._key] = this; + this._worksheet.setColumnKey(this._key, this); } }, get hidden() { diff --git a/lib/doc/defined-names.js b/lib/doc/defined-names.js index 69fbae2b7..6aedcbdf4 100644 --- a/lib/doc/defined-names.js +++ b/lib/doc/defined-names.js @@ -122,7 +122,6 @@ DefinedNames.prototype = { }, getRanges: function(name, matrix) { - var self = this; matrix = matrix || this.matrixMap[name]; if (!matrix) { @@ -131,11 +130,9 @@ DefinedNames.prototype = { // mark and sweep! matrix.forEach(function(cell) { cell.mark = true; }); - var ranges = matrix.map(function(cell) { - return cell.mark && self._explore(matrix, cell); - }) - .filter(function(range) { return range; }) - .map(function(range) { return range.$shortRange; }); + var ranges = matrix.map(cell => cell.mark && this._explore(matrix, cell)) + .filter(Boolean) + .map(range => range.$shortRange); return { name: name, ranges: ranges diff --git a/lib/doc/row.js b/lib/doc/row.js index c10b414f9..0b62d49cb 100644 --- a/lib/doc/row.js +++ b/lib/doc/row.js @@ -33,7 +33,7 @@ Row.prototype = { // Inform Streaming Writer that this row (and all rows before it) are complete // and ready to write. Has no effect on Worksheet document commit: function() { - this._worksheet._commitRow(this); + this._worksheet._commitRow(this); // eslint-disable-line no-underscore-dangle }, // helps GC by breaking cyclic references @@ -48,7 +48,7 @@ Row.prototype = { }, // given {address, row, col}, find or create new cell - _getCell: function(address) { + getCellEx: function(address) { var cell = this._cells[address.col - 1]; if (!cell) { var column = this._worksheet.getColumn(address.col); @@ -62,7 +62,7 @@ Row.prototype = { getCell: function(col) { if (typeof col === 'string') { // is it a key? - var column = this._worksheet._keys[col]; + var column = this._worksheet.getColumnKey(col); if (column) { col = column.number; } else { @@ -70,7 +70,7 @@ Row.prototype = { } } return this._cells[col - 1] || - this._getCell({ + this.getCellEx({ address: colCache.encodeAddress(this._number, col), row: this._number, col: col @@ -149,8 +149,6 @@ Row.prototype = { // set the values by contiguous or sparse array, or by key'd object literal set values(value) { - var self = this; - // this operation is not additive - any prior cells are removed this._cells = []; if (!value) { @@ -161,22 +159,22 @@ Row.prototype = { // contiguous array - start at column 1 offset = 1; } - value.forEach(function(item, index) { + value.forEach((item, index) => { if (item !== undefined) { - self._getCell({ - address: colCache.encodeAddress(self._number, index + offset), - row: self._number, + this.getCellEx({ + address: colCache.encodeAddress(this._number, index + offset), + row: this._number, col: index + offset }).value = item; } }); } else { // assume object with column keys - _.each(this._worksheet._keys, function(column, key) { + this._worksheet.eachColumnKey((column, key) => { if (value[key] !== undefined) { - self._getCell({ - address: colCache.encodeAddress(self._number, column.number), - row: self._number, + this.getCellEx({ + address: colCache.encodeAddress(this._number, column.number), + row: this._number, col: column.number }).value = value[key]; } @@ -316,15 +314,14 @@ Row.prototype = { if (value.number !== this._number) { throw new Error('Invalid row number in model'); } - var self = this; this._cells = []; - value.cells.forEach(function(cellModel) { + value.cells.forEach(cellModel => { switch (cellModel.type) { case Cell.Types.Merge: // special case - don't add this types break; default: - var cell = self._getCell(colCache.decodeAddress(cellModel.address)); + var cell = this.getCellEx(colCache.decodeAddress(cellModel.address)); cell.model = cellModel; break; } diff --git a/lib/doc/workbook.js b/lib/doc/workbook.js index 9015bbc44..c3e8ee9c5 100644 --- a/lib/doc/workbook.js +++ b/lib/doc/workbook.js @@ -80,7 +80,7 @@ Workbook.prototype = { this._worksheets[id] = worksheet; return worksheet; }, - _removeWorksheet: function(worksheet) { + removeWorksheetEx: function(worksheet) { delete this._worksheets[worksheet.id]; }, removeWorksheet: function(id) { @@ -166,8 +166,6 @@ Workbook.prototype = { }; }, set model(value) { - var self = this; - this.creator = value.creator; this.lastModifiedBy = value.lastModifiedBy; this.lastPrinted = value.lastPrinted; @@ -186,13 +184,13 @@ Workbook.prototype = { this.properties = value.properties; this._worksheets = []; - value.worksheets.forEach(function(worksheetModel) { + value.worksheets.forEach(worksheetModel => { var id = worksheetModel.id; var name = worksheetModel.name; - var worksheet = self._worksheets[id] = new Worksheet({ + var worksheet = this._worksheets[id] = new Worksheet({ id: id, name: name, - workbook: self + workbook: this }); worksheet.model = worksheetModel; diff --git a/lib/doc/worksheet.js b/lib/doc/worksheet.js index 4ff158a21..d99672e07 100644 --- a/lib/doc/worksheet.js +++ b/lib/doc/worksheet.js @@ -97,7 +97,7 @@ Worksheet.prototype = { // when you're done with this worksheet, call this to remove from workbook destroy: function() { - this._workbook._removeWorksheet(this); + this._workbook.removeWorksheetEx(this); }, // Get the bounding range of the cells in this worksheet @@ -122,6 +122,19 @@ Worksheet.prototype = { return this._columns; }, + getColumnKey(key) { + return this._keys[key]; + }, + setColumnKey(key, value) { + this._keys[key] = value; + }, + deleteColumnKey(key) { + delete this._keys[key]; + }, + eachColumnKey(f) { + _.each(this._keys, f); + }, + // set the columns from an array of column definitions. // Note: any headers defined will overwrite existing values. set columns(value) { @@ -138,10 +151,10 @@ Worksheet.prototype = { // construct Column objects var count = 1; - var _columns = this._columns = []; + var columns = this._columns = []; value.forEach(function(defn) { var column = new Column(self, count++, false); - _columns.push(column); + columns.push(column); column.defn = defn; }); }, @@ -169,8 +182,8 @@ Worksheet.prototype = { // each member of inserts is a column of data. var i; var inserts = Array.prototype.slice.call(arguments, 2); - var _rows = this._rows; - var nRows = _rows.length; + var rows = this._rows; + var nRows = rows.length; if (inserts.length > 0) { // must iterate over all rows whether they exist yet or not for (i = 0; i < nRows; i++) { @@ -243,9 +256,9 @@ Worksheet.prototype = { get _lastRowNumber() { // need to cope with results of splice - var _rows = this._rows; - var n = _rows.length; - while ((n > 0) && (_rows[n - 1] === undefined)) { + var rows = this._rows; + var n = rows.length; + while ((n > 0) && (rows[n - 1] === undefined)) { n--; } return n; @@ -377,7 +390,7 @@ Worksheet.prototype = { getCell: function(r, c) { var address = colCache.getAddress(r, c); var row = this.getRow(address.row); - return row._getCell(address); + return row.getCellEx(address); }, // ========================================================================= @@ -422,7 +435,7 @@ Worksheet.prototype = { }, get hasMerges() { - return _.some(this._merges, function(merge) { + return _.some(this._merges, function() { // TODO: this doesn't look right return true; }); @@ -575,18 +588,16 @@ Worksheet.prototype = { return model; }, _parseRows: function(model) { - var self = this; this._rows = []; - model.rows.forEach(function(rowModel) { - var row = new Row(self, rowModel.number); - self._rows[row.number - 1] = row; + model.rows.forEach(rowModel => { + var row = new Row(this, rowModel.number); + this._rows[row.number - 1] = row; row.model = rowModel; }); }, _parseMergeCells: function(model) { - var self = this; - _.each(model.mergeCells, function(merge) { - self.mergeCells(merge); + _.each(model.mergeCells, merge => { + this.mergeCells(merge); }); }, set model(value) { diff --git a/lib/stream/xlsx/sheet-rels-writer.js b/lib/stream/xlsx/sheet-rels-writer.js index e68bbe727..a017326e4 100644 --- a/lib/stream/xlsx/sheet-rels-writer.js +++ b/lib/stream/xlsx/sheet-rels-writer.js @@ -34,6 +34,7 @@ SheetRelsWriter.prototype = { get stream() { if (!this._stream) { + // eslint-disable-next-line no-underscore-dangle this._stream = this._workbook._openStream('/xl/worksheets/_rels/sheet' + this.id + '.xml.rels'); } return this._stream; diff --git a/lib/stream/xlsx/workbook-reader.js b/lib/stream/xlsx/workbook-reader.js index 7bfb5acf5..58eaf9957 100644 --- a/lib/stream/xlsx/workbook-reader.js +++ b/lib/stream/xlsx/workbook-reader.js @@ -66,11 +66,10 @@ utils.inherits(WorkbookReader, events.EventEmitter, { worksheets: ['emit'] }, read: function(input, options) { - var self = this; var stream = this.stream = this._getStream(input); var zip = this.zip = unzip.Parse(); - zip.on('entry', function(entry) { + zip.on('entry', entry => { var match, sheetNo; switch (entry.path) { case '_rels/.rels': @@ -79,20 +78,20 @@ utils.inherits(WorkbookReader, events.EventEmitter, { entry.autodrain(); break; case 'xl/sharedStrings.xml': - self._parseSharedStrings(entry, options); + this._parseSharedStrings(entry, options); break; case 'xl/styles.xml': - self._parseStyles(entry, options); + this._parseStyles(entry, options); break; default: if (entry.path.match(/xl\/worksheets\/sheet\d+[.]xml/)) { match = entry.path.match(/xl\/worksheets\/sheet(\d+)[.]xml/); sheetNo = match[1]; - self._parseWorksheet(entry, sheetNo, options); + this._parseWorksheet(entry, sheetNo, options); } else if (entry.path.match(/xl\/worksheets\/_rels\/sheet\d+[.]xml.rels/)) { match = entry.path.match(/xl\/worksheets\/_rels\/sheet(\d+)[.]xml.rels/); sheetNo = match[1]; - self._parseHyperlinks(entry, sheetNo, options); + this._parseHyperlinks(entry, sheetNo, options); } else { entry.autodrain(); } @@ -100,11 +99,11 @@ utils.inherits(WorkbookReader, events.EventEmitter, { } }); - zip.on('close', function() { - self.emit('end'); - self.atEnd = true; - if (!self.readers) { - self.emit('finished'); + zip.on('close', () => { + this.emit('end'); + this.atEnd = true; + if (!this.readers) { + this.emit('finished'); } }); diff --git a/lib/stream/xlsx/workbook-writer.js b/lib/stream/xlsx/workbook-writer.js index 5de37ca93..eeb315cc3 100644 --- a/lib/stream/xlsx/workbook-writer.js +++ b/lib/stream/xlsx/workbook-writer.js @@ -200,26 +200,24 @@ WorkbookWriter.prototype = { }, addContentTypes: function() { - var self = this; - return new PromishLib.Promish(function(resolve) { + return new PromishLib.Promish(resolve => { var model = { - worksheets: self._worksheets.filter(Boolean) + worksheets: this._worksheets.filter(Boolean) }; var xform = new ContentTypesXform(); var xml = xform.toXml(model); - self.zip.append(xml, {name: '[Content_Types].xml'}); + this.zip.append(xml, {name: '[Content_Types].xml'}); resolve(); }); }, addApp: function() { - var self = this; - return new PromishLib.Promish(function(resolve) { + return new PromishLib.Promish(resolve => { var model = { - worksheets: self._worksheets.filter(Boolean) + worksheets: this._worksheets.filter(Boolean) }; var xform = new AppXform(); var xml = xform.toXml(model); - self.zip.append(xml, {name: 'docProps/app.xml'}); + this.zip.append(xml, {name: 'docProps/app.xml'}); resolve(); }); }, diff --git a/lib/stream/xlsx/worksheet-reader.js b/lib/stream/xlsx/worksheet-reader.js index 06650a9f5..17b0c33f9 100644 --- a/lib/stream/xlsx/worksheet-reader.js +++ b/lib/stream/xlsx/worksheet-reader.js @@ -81,8 +81,6 @@ utils.inherits(WorksheetReader, events.EventEmitter, { }, read: function(entry, options) { - var self = this; - var emitSheet = false; var emitHyperlinks = false; var hyperlinks = null; @@ -126,7 +124,7 @@ utils.inherits(WorksheetReader, events.EventEmitter, { var current = null; var parser = Sax.createStream(true, {}); - parser.on('opentag', function(node) { + parser.on('opentag', node => { if (emitSheet) { switch (node.name) { case 'cols': @@ -151,7 +149,7 @@ utils.inherits(WorksheetReader, events.EventEmitter, { case 'row': if (inRows) { var r = parseInt(node.attributes.r, 10); - row = new Row(self, r); + row = new Row(this, r); if (node.attributes.ht) { row.height = parseFloat(node.attributes.ht); } @@ -202,7 +200,7 @@ utils.inherits(WorksheetReader, events.EventEmitter, { rId: node.attributes['r:id'] }; if (emitHyperlinks) { - self.emit('hyperlink', hyperlink); + this.emit('hyperlink', hyperlink); } else { hyperlinks[hyperlink.ref] = hyperlink; } @@ -215,7 +213,7 @@ utils.inherits(WorksheetReader, events.EventEmitter, { }); // only text data is for sheet values - parser.on('text', function(text) { + parser.on('text', text => { if (emitSheet) { if (current) { current.text += text; @@ -223,20 +221,20 @@ utils.inherits(WorksheetReader, events.EventEmitter, { } }); - parser.on('closetag', function(name) { + parser.on('closetag', name => { if (emitSheet) { switch (name) { case 'cols': inCols = false; - self._columns = Column.fromModel(cols); + this._columns = Column.fromModel(cols); break; case 'sheetData': inRows = false; break; case 'row': - self._dimensions.expandRow(row); - self._emitRow(row); + this._dimensions.expandRow(row); + this._emitRow(row); row = null; break; @@ -245,7 +243,7 @@ utils.inherits(WorksheetReader, events.EventEmitter, { var address = colCache.decodeAddress(c.ref); var cell = row.getCell(address.col); if (c.s) { - cell.style = self.workbook.styles.getStyleModel(c.s); + cell.style = this.workbook.styles.getStyleModel(c.s); } if (c.f) { @@ -301,11 +299,11 @@ utils.inherits(WorksheetReader, events.EventEmitter, { } } }); - parser.on('error', function(error) { - self.emit('error', error); + parser.on('error', error => { + this.emit('error', error); }); - parser.on('end', function() { - self.emit('finished'); + parser.on('end', () => { + this.emit('finished'); }); // create a down-stream flow-control to regulate the stream diff --git a/lib/stream/xlsx/worksheet-writer.js b/lib/stream/xlsx/worksheet-writer.js index a28f15cbb..13421ef5e 100644 --- a/lib/stream/xlsx/worksheet-writer.js +++ b/lib/stream/xlsx/worksheet-writer.js @@ -162,6 +162,7 @@ WorksheetWriter.prototype = { get stream() { if (!this._stream) { + // eslint-disable-next-line no-underscore-dangle this._stream = this._workbook._openStream('/xl/worksheets/sheet' + this.id + '.xml'); // pause stream to prevent 'data' events @@ -180,12 +181,11 @@ WorksheetWriter.prototype = { if (this.committed) { return; } - var self = this; // commit all rows - this._rows.forEach(function(cRow) { + this._rows.forEach(cRow => { if (cRow) { // write the row to the stream - self._writeRow(cRow); + this._writeRow(cRow); } }); @@ -238,10 +238,8 @@ WorksheetWriter.prototype = { // set the columns from an array of column definitions. // Note: any headers defined will overwrite existing values. set columns(value) { - var self = this; - // calculate max header row count - this._headerRowCount = value.reduce(function(pv, cv) { + this._headerRowCount = value.reduce((pv, cv) => { var headerCount = (cv.header && 1) || (cv.headers && cv.headers.length) || @@ -251,10 +249,10 @@ WorksheetWriter.prototype = { // construct Column objects var count = 1; - var _columns = this._columns = []; - value.forEach(function(defn) { - var column = new Column(self, count++, false); - _columns.push(column); + var columns = this._columns = []; + value.forEach(defn => { + var column = new Column(this, count++, false); + columns.push(column); column.defn = defn; }); }, @@ -369,7 +367,7 @@ WorksheetWriter.prototype = { getCell: function(r, c) { var address = colCache.getAddress(r, c); var row = this.getRow(address.row); - return row._getCell(address); + return row.getCellEx(address); }, mergeCells: function() { @@ -453,8 +451,6 @@ WorksheetWriter.prototype = { this._write(''); }, _writeRow: function(row) { - var self = this; - if (!this.startedData) { this._writeColumns(); this._writeOpenSheetData(); @@ -465,7 +461,7 @@ WorksheetWriter.prototype = { var model = row.model; var options = { styles: this._workbook.styles, - sharedStrings: self.useSharedStrings ? self._workbook.sharedStrings : undefined, + sharedStrings: this.useSharedStrings ? this._workbook.sharedStrings : undefined, hyperlinks: this._sheetRelsWriter.hyperlinksProxy, merges: this._merges, formulae: this._formulae, @@ -491,6 +487,7 @@ WorksheetWriter.prototype = { } }, _writeHyperlinks: function() { + // eslint-disable-next-line no-underscore-dangle this.stream.write(xform.hyperlinks.toXml(this._sheetRelsWriter._hyperlinks)); }, _writeDataValidations: function() { diff --git a/lib/utils/flow-control.js b/lib/utils/flow-control.js index 48b4f222a..f690bbf99 100644 --- a/lib/utils/flow-control.js +++ b/lib/utils/flow-control.js @@ -87,16 +87,14 @@ utils.inherits(FlowControl, events.EventEmitter, { }, _pipe: function(chunk) { - var self = this; - // Write chunk to all pipes. A chunk with no data is the end var promises = []; - this.pipes.forEach(function(pipe) { + this.pipes.forEach(pipe => { if (chunk.data) { if (pipe.sync) { pipe.stream.write(chunk.data, chunk.encoding); } else { - promises.push(self._write(pipe.stream, chunk.data, chunk.encoding)); + promises.push(this._write(pipe.stream, chunk.data, chunk.encoding)); } } else { pipe.stream.end(); @@ -139,26 +137,22 @@ utils.inherits(FlowControl, events.EventEmitter, { _flush: function() { // If/while not corked and we have buffers to send, send them - var self = this; - if (this.queue && !this.flushing && !this.corked) { if (this.queue.length) { this.flushing = true; - self._delay() - .then(function() { - return self._pipe(self.queue.shift()); - }) - .then(function() { - setImmediate(function() { - self.flushing = false; - self._flush(); + this._delay() + .then(() => this._pipe(this.queue.shift())) + .then(() => { + setImmediate(() => { + this.flushing = false; + this._flush(); }); }); } if (!this.stem) { // Signal up-stream that we're ready for more data - self.emit('drain'); + this.emit('drain'); } } }, @@ -189,7 +183,7 @@ utils.inherits(FlowControl, events.EventEmitter, { return !stemFlow; }, - end: function(chunk, encoding) { + end: function(chunk) { // Signal from up-stream this.queue.push({ callback: () => { @@ -219,22 +213,19 @@ utils.inherits(FlowControl, events.EventEmitter, { createChild: function() { // Create a down-stream flow-control - var self = this; var options = Object.assign({parent: this}, this.options); var child = new FlowControl(options); this.children.push(child); - child.on('drain', function() { + child.on('drain', () => { // a child is ready for more - self._flush(); + this._flush(); }); - child.on('finish', function() { - // One child has finished it's stream. Remove it and continue - self.children = self.children.filter(function(item) { - return item !== child; - }); - self._flush(); + child.on('finish', () => { + // One child has finished its stream. Remove it and continue + this.children = this.children.filter(item => item !== child); + this._flush(); }); return child; diff --git a/lib/utils/stream-base64.js b/lib/utils/stream-base64.js index 075aeb54e..e0f7c5811 100644 --- a/lib/utils/stream-base64.js +++ b/lib/utils/stream-base64.js @@ -47,7 +47,7 @@ utils.inherits(StreamBuf, Stream.Duplex, { }, isPaused: function() { }, - pipe: function(/* destination, options */) { + pipe: function(destination) { // add destination to pipe list & write current buffer this.pipes.push(destination); }, diff --git a/lib/utils/stream-buf.js b/lib/utils/stream-buf.js index 2627c1a58..a46e3b66e 100644 --- a/lib/utils/stream-buf.js +++ b/lib/utils/stream-buf.js @@ -43,6 +43,7 @@ StringBufChunk.prototype = { }, // copy to target buffer copy: function(target, targetOffset, offset, length) { + // eslint-disable-next-line no-underscore-dangle return this._data._buf.copy(target, targetOffset, offset, length); }, toBuffer: function() { @@ -271,16 +272,13 @@ utils.inherits(StreamBuf, Stream.Duplex, { this._flush(); }, end: function(chunk, encoding, callback) { - var self = this; - var writeComplete = function(error) { + var writeComplete = error => { if (error) { callback(error); } else { - self._flush(); - self.pipes.forEach(function(pipe) { - pipe.end(); - }); - self.emit('finish'); + this._flush(); + this.pipes.forEach(pipe => { pipe.end(); }); + this.emit('finish'); } }; if (chunk) { diff --git a/lib/utils/string-buf.js b/lib/utils/string-buf.js index ef5c7d672..3c44e1245 100644 --- a/lib/utils/string-buf.js +++ b/lib/utils/string-buf.js @@ -77,6 +77,7 @@ StringBuf.prototype = { if (this.length + inBuf.length > this.capacity) { this._grow(this.length + inBuf.length); } + // eslint-disable-next-line no-underscore-dangle inBuf._buf.copy(this._buf, this._inPos, 0, inBuf.length); this._inPos += inBuf.length; } diff --git a/lib/utils/stuttered-pipe.js b/lib/utils/stuttered-pipe.js index 2871e594a..b59c89cea 100644 --- a/lib/utils/stuttered-pipe.js +++ b/lib/utils/stuttered-pipe.js @@ -53,19 +53,18 @@ utils.inherits(StutteredPipe, events.EventEmitter, { } }, _schedule: function() { - var self = this; - this.scheduled = setImmediate(function() { - self.scheduled = null; - if (!self.eod && !self.paused) { - var data = self.readable.read(self.bufSize); + this.scheduled = setImmediate(() => { + this.scheduled = null; + if (!this.eod && !this.paused) { + var data = this.readable.read(this.bufSize); if (data && data.length) { - self.writable.write(data); + this.writable.write(data); - if (!self.paused && !self.autoPause) { - self._schedule(); + if (!this.paused && !this.autoPause) { + this._schedule(); } - } else if (!self.paused) { - self._schedule(); + } else if (!this.paused) { + this._schedule(); } } }); diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 81e024d10..4f966a832 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -11,6 +11,7 @@ var PromishLib = require('./promish'); // useful stuff var inherits = function(cls, superCtor, statics, prototype) { + // eslint-disable-next-line no-underscore-dangle cls.super_ = superCtor; if (!prototype) { diff --git a/spec/.eslintrc b/spec/.eslintrc index d2ca8bbc9..7e0550c2b 100644 --- a/spec/.eslintrc +++ b/spec/.eslintrc @@ -6,7 +6,8 @@ "brace-style": ["off"], "array-bracket-spacing": ["off"], "no-sparse-arrays": ["off"], - "object-property-newline": ["off"] + "object-property-newline": ["off"], + "no-underscore-dangle": ["off"] }, "globals": { "describe": true, diff --git a/spec/integration/workbook-xlsx-writer/workbook-xlsx-writer.spec.js b/spec/integration/workbook-xlsx-writer/workbook-xlsx-writer.spec.js index ccc5d2efd..93088a869 100644 --- a/spec/integration/workbook-xlsx-writer/workbook-xlsx-writer.spec.js +++ b/spec/integration/workbook-xlsx-writer/workbook-xlsx-writer.spec.js @@ -1,7 +1,6 @@ 'use strict'; var fs = require('fs'); -var Promish = require('promish'); var expect = require('chai').expect; var verquire = require('../../utils/verquire'); var testUtils = require('../../utils/index');