Skip to content

Run linter with prettier 2 #1477

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 4 commits into from
Sep 29, 2020
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"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"],
"func-names": ["off", "never"],
"global-require": ["off"],
"max-len": ["error", {"code": 160, "ignoreComments": true, "ignoreStrings": true}],
"max-len": ["error", {"code": 100, "ignoreComments": true, "ignoreStrings": true}],
"no-console": ["error", { "allow": ["warn"] }],
"no-continue": ["off"],
"no-mixed-operators": ["error", {"allowSamePrecedence": true}],
Expand Down
5 changes: 3 additions & 2 deletions .prettier
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"bracketSpacing": false,
"printWidth": 160,
"printWidth": 100,
"trailingComma": "all",
"bracketSpacing": false
"bracketSpacing": false,
"arrowParens": "avoid"
}
34 changes: 27 additions & 7 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const runs = 3;
await runProfiling('huge xlsx file streams', () => {
return new Promise((resolve, reject) => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader('./spec/integration/data/huge.xlsx');
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(
'./spec/integration/data/huge.xlsx'
);
workbookReader.read();

let worksheetCount = 0;
Expand All @@ -32,7 +34,9 @@ const runs = 3;

await runProfiling('huge xlsx file async iteration', async () => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader('spec/integration/data/huge.xlsx');
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(
'spec/integration/data/huge.xlsx'
);
let worksheetCount = 0;
let rowCount = 0;
for await (const worksheetReader of workbookReader) {
Expand All @@ -55,13 +59,21 @@ const runs = 3;
async function runProfiling(name, run) {
console.log('');
console.log('####################################################');
console.log(`WARMUP: Current memory usage: ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(
`WARMUP: Current memory usage: ${currentMemoryUsage({runGarbageCollector: true})} MB`
);
console.log(`WARMUP: ${name} profiling started`);
const warmupStartTime = Date.now();
await run();
console.log(`WARMUP: ${name} profiling finished in ${Date.now() - warmupStartTime}ms`);
console.log(`WARMUP: Current memory usage (before GC): ${currentMemoryUsage({runGarbageCollector: false})} MB`);
console.log(`WARMUP: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(
`WARMUP: Current memory usage (before GC): ${currentMemoryUsage({
runGarbageCollector: false,
})} MB`
);
console.log(
`WARMUP: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`
);

for (let i = 1; i <= runs; i += 1) {
console.log('');
Expand All @@ -70,8 +82,16 @@ async function runProfiling(name, run) {
const startTime = Date.now();
await run(); // eslint-disable-line no-await-in-loop
console.log(`RUN ${i}: ${name} profiling finished in ${Date.now() - startTime}ms`);
console.log(`RUN ${i}: Current memory usage (before GC): ${currentMemoryUsage({runGarbageCollector: false})} MB`);
console.log(`RUN ${i}: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(
`RUN ${i}: Current memory usage (before GC): ${currentMemoryUsage({
runGarbageCollector: false,
})} MB`
);
console.log(
`RUN ${i}: Current memory usage (after GC): ${currentMemoryUsage({
runGarbageCollector: true,
})} MB`
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

if (parseInt(process.versions.node.split('.')[0], 10) < 10) {
throw new Error('For node versions older than 10, please use the ES5 Import: https://github.com/exceljs/exceljs#es5-imports');
throw new Error(
'For node versions older than 10, please use the ES5 Import: https://github.com/exceljs/exceljs#es5-imports'
);
}

module.exports = require('./lib/exceljs.nodejs.js');
15 changes: 10 additions & 5 deletions lib/csv/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const fs = require('fs');
const fastCsv = require('fast-csv');
const customParseFormat = require('dayjs/plugin/customParseFormat');
const utc = require('dayjs/plugin/utc');
const dayjs = require('dayjs')
.extend(customParseFormat)
.extend(utc);
const dayjs = require('dayjs').extend(customParseFormat).extend(utc);
const StreamBuf = require('../utils/stream-buf');

const {
Expand Down Expand Up @@ -48,7 +46,12 @@ class CSV {
return new Promise((resolve, reject) => {
const worksheet = this.workbook.addWorksheet(options.sheetName);

const dateFormats = options.dateFormats || ['YYYY-MM-DD[T]HH:mm:ssZ', 'YYYY-MM-DD[T]HH:mm:ss', 'MM-DD-YYYY', 'YYYY-MM-DD'];
const dateFormats = options.dateFormats || [
'YYYY-MM-DD[T]HH:mm:ssZ',
'YYYY-MM-DD[T]HH:mm:ss',
'MM-DD-YYYY',
'YYYY-MM-DD',
];
const map =
options.map ||
function(datum) {
Expand Down Expand Up @@ -132,7 +135,9 @@ class CSV {
}
if (value instanceof Date) {
if (dateFormat) {
return dateUTC ? dayjs.utc(value).format(dateFormat) : dayjs(value).format(dateFormat);
return dateUTC
? dayjs.utc(value).format(dateFormat)
: dayjs(value).format(dateFormat);
}
return dateUTC ? dayjs.utc(value).format() : dayjs(value).format();
}
Expand Down
6 changes: 5 additions & 1 deletion lib/csv/stream-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ class StreamConverter {
this.writeStarted = true;
}

this.inner.write(this.convertInwards(data), encoding ? this.innerEncoding : undefined, callback);
this.inner.write(
this.convertInwards(data),
encoding ? this.innerEncoding : undefined,
callback
);
}

read() {
Expand Down
8 changes: 6 additions & 2 deletions lib/doc/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ class Anchor {
}

get colWidth() {
return this.worksheet && this.worksheet.getColumn(this.nativeCol + 1) && this.worksheet.getColumn(this.nativeCol + 1).isCustomWidth
return this.worksheet &&
this.worksheet.getColumn(this.nativeCol + 1) &&
this.worksheet.getColumn(this.nativeCol + 1).isCustomWidth
? Math.floor(this.worksheet.getColumn(this.nativeCol + 1).width * 10000)
: 640000;
}

get rowHeight() {
return this.worksheet && this.worksheet.getRow(this.nativeRow + 1) && this.worksheet.getRow(this.nativeRow + 1).height
return this.worksheet &&
this.worksheet.getRow(this.nativeRow + 1) &&
this.worksheet.getRow(this.nativeRow + 1).height
? Math.floor(this.worksheet.getRow(this.nativeRow + 1).height * 10000)
: 180000;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/doc/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ class FormulaValue {
get dependencies() {
// find all the ranges and cells mentioned in the formula
const ranges = this.formula.match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g);
const cells = this.formula.replace(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g, '').match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}/g);
const cells = this.formula
.replace(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g, '')
.match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}/g);
return {
ranges,
cells,
Expand Down Expand Up @@ -860,7 +862,8 @@ class FormulaValue {
if (!this._translatedFormula && this.model.sharedFormula) {
const {worksheet} = this.cell;
const master = worksheet.findCell(this.model.sharedFormula);
this._translatedFormula = master && slideFormula(master.formula, master.address, this.model.address);
this._translatedFormula =
master && slideFormula(master.formula, master.address, this.model.address);
}
return this._translatedFormula;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/doc/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class Column {
}

get collapsed() {
return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
return !!(
this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol
);
}

toString() {
Expand All @@ -134,7 +136,12 @@ class Column {
}

equivalentTo(other) {
return this.width === other.width && this.hidden === other.hidden && this.outlineLevel === other.outlineLevel && _.isEqual(this.style, other.style);
return (
this.width === other.width &&
this.hidden === other.hidden &&
this.outlineLevel === other.outlineLevel &&
_.isEqual(this.style, other.style)
);
}

get isDefault() {
Expand Down
8 changes: 6 additions & 2 deletions lib/doc/defined-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class DefinedNames {
}

getNamesEx(address) {
return _.map(this.matrixMap, (matrix, name) => matrix.findCellEx(address) && name).filter(Boolean);
return _.map(this.matrixMap, (matrix, name) => matrix.findCellEx(address) && name).filter(
Boolean
);
}

_explore(matrix, cell) {
Expand Down Expand Up @@ -172,7 +174,9 @@ class DefinedNames {

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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/doc/modelcontainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const XLSX = require('./../xlsx/xlsx');
const XLSX = require('../xlsx/xlsx');

class ModelContainer {
constructor(model) {
Expand Down
9 changes: 7 additions & 2 deletions lib/doc/range.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const colCache = require('./../utils/col-cache');
const colCache = require('../utils/col-cache');

// used by worksheet to calculate sheet dimensions
class Range {
Expand Down Expand Up @@ -237,7 +237,12 @@ class Range {

containsEx(address) {
if (address.sheetName && this.sheetName && address.sheetName !== this.sheetName) return false;
return address.row >= this.top && address.row <= this.bottom && address.col >= this.left && address.col <= this.right;
return (
address.row >= this.top &&
address.row <= this.bottom &&
address.col >= this.left &&
address.col <= this.right
);
}

forEachAddress(cb) {
Expand Down
4 changes: 3 additions & 1 deletion lib/doc/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ class Row {
}

get collapsed() {
return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelRow);
return !!(
this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelRow
);
}

// =========================================================================
Expand Down
2 changes: 1 addition & 1 deletion lib/doc/table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-classes-per-file */
const colCache = require('./../utils/col-cache');
const colCache = require('../utils/col-cache');

class Column {
// wrapper around column model, allowing access and manipulation
Expand Down
13 changes: 10 additions & 3 deletions lib/doc/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ class Workbook {
if (options) {
if (typeof options === 'string') {
// eslint-disable-next-line no-console
console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }');
console.trace(
'tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }'
);
options = {
properties: {
tabColor: {argb: options},
},
};
} else if (options.argb || options.theme || options.indexed) {
// eslint-disable-next-line no-console
console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }');
console.trace(
'tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }'
);
options = {
properties: {
tabColor: options,
Expand All @@ -76,7 +80,10 @@ class Workbook {
}
}

const lastOrderNo = this._worksheets.reduce((acc, ws) => ((ws && ws.orderNo) > acc ? ws.orderNo : acc), 0);
const lastOrderNo = this._worksheets.reduce(
(acc, ws) => ((ws && ws.orderNo) > acc ? ws.orderNo : acc),
0
);
const worksheetOptions = Object.assign({}, options, {
id,
name,
Expand Down
28 changes: 22 additions & 6 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class Worksheet {
orientation: 'portrait',
horizontalDpi: 4294967295,
verticalDpi: 4294967295,
fitToPage: !!(options.pageSetup && (options.pageSetup.fitToWidth || options.pageSetup.fitToHeight) && !options.pageSetup.scale),
fitToPage: !!(
options.pageSetup &&
(options.pageSetup.fitToWidth || options.pageSetup.fitToHeight) &&
!options.pageSetup.scale
),
pageOrder: 'downThenOver',
blackAndWhite: false,
draft: false,
Expand Down Expand Up @@ -693,13 +697,21 @@ 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.hashValue = Encryptor.convertPasswordToHash(password, 'SHA512', this.sheetProtection.saltValue, this.sheetProtection.spinCount);
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
);
}
if (options) {
this.sheetProtection = Object.assign(this.sheetProtection, options);
Expand Down Expand Up @@ -755,13 +767,17 @@ 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
4 changes: 3 additions & 1 deletion lib/stream/xlsx/sheet-rels-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class SheetRelsWriter {
'/>'
);
} else {
this.stream.write(`<Relationship Id="${rId}" Type="${relationship.Type}" Target="${relationship.Target}"/>`);
this.stream.write(
`<Relationship Id="${rId}" Type="${relationship.Type}" Target="${relationship.Target}"/>`
);
}

return rId;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy