Skip to content

Commit

Permalink
no-underescore-dangle
Browse files Browse the repository at this point in the history
  • Loading branch information
guyonroche committed May 17, 2017
1 parent d077ef4 commit e4b676b
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 151 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions lib/csv/line-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/doc/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions lib/doc/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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() {
Expand Down
9 changes: 3 additions & 6 deletions lib/doc/defined-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ DefinedNames.prototype = {
},

getRanges: function(name, matrix) {
var self = this;
matrix = matrix || this.matrixMap[name];

if (!matrix) {
Expand All @@ -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
Expand Down
31 changes: 14 additions & 17 deletions lib/doc/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -62,15 +62,15 @@ 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 {
col = colCache.l2n(col);
}
}
return this._cells[col - 1] ||
this._getCell({
this.getCellEx({
address: colCache.encodeAddress(this._number, col),
row: this._number,
col: col
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
}
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions lib/doc/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -166,8 +166,6 @@ Workbook.prototype = {
};
},
set model(value) {
var self = this;

this.creator = value.creator;
this.lastModifiedBy = value.lastModifiedBy;
this.lastPrinted = value.lastPrinted;
Expand All @@ -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;
Expand Down
45 changes: 28 additions & 17 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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;
});
},
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
},

// =========================================================================
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/stream/xlsx/sheet-rels-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e4b676b

Please sign in to comment.