mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add rules to eslint to better match our coding conventions.
Summary: We used tslint earlier, and on switching to eslint, some rules were not transfered. This moves more rules over, for consistent conventions or helpful warnings. - Name private members with a leading underscore. - Prefer interface over a type alias. - Use consistent spacing around ':' in type annotations. - Use consistent spacing around braces of code blocks. - Use semicolons consistently at the ends of statements. - Use braces around even one-liner blocks, like conditionals and loops. - Warn about shadowed variables. Test Plan: Fixed all new warnings. Should be no behavior changes in code. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2831
This commit is contained in:
@@ -188,11 +188,13 @@ export class ChecksummedExternalStorage implements ExternalStorage {
|
||||
if (!snapshotIds) {
|
||||
await this._options.latestVersion.save(key, DELETED_TOKEN);
|
||||
await this._options.sharedHash.save(key, DELETED_TOKEN);
|
||||
} else for (const snapshotId of snapshotIds) {
|
||||
// Removing snapshots breaks their partial immutability, so we mark them
|
||||
// as deleted in redis so that we don't get stale info from S3 if we check
|
||||
// for their existence. Nothing currently depends on this in practice.
|
||||
await this._options.sharedHash.save(this._keyWithSnapshot(key, snapshotId), DELETED_TOKEN);
|
||||
} else {
|
||||
for (const snapshotId of snapshotIds) {
|
||||
// Removing snapshots breaks their partial immutability, so we mark them
|
||||
// as deleted in redis so that we don't get stale info from S3 if we check
|
||||
// for their existence. Nothing currently depends on this in practice.
|
||||
await this._options.sharedHash.save(this._keyWithSnapshot(key, snapshotId), DELETED_TOKEN);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
log.error("ext %s delete: %s failure to remove, error %s", this.label, key, err.message);
|
||||
|
||||
@@ -907,7 +907,7 @@ export class FlexServer implements GristServer {
|
||||
this.tagChecker.requireTag
|
||||
];
|
||||
|
||||
this.addSupportPaths(docAccessMiddleware);
|
||||
this._addSupportPaths(docAccessMiddleware);
|
||||
|
||||
if (!isSingleUserMode()) {
|
||||
addDocApiRoutes(this.app, docWorker, this._docWorkerMap, docManager, this.dbManager, this);
|
||||
@@ -1081,8 +1081,8 @@ export class FlexServer implements GristServer {
|
||||
);
|
||||
const config = {errPage, errMessage: err.message || err};
|
||||
await this._sendAppPage(req, resp, {path: 'error.html', status: err.status || 400, config});
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
} catch (error) {
|
||||
return next(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1183,7 +1183,7 @@ export class FlexServer implements GristServer {
|
||||
}
|
||||
|
||||
// Adds endpoints that support imports and exports.
|
||||
private addSupportPaths(docAccessMiddleware: express.RequestHandler[]) {
|
||||
private _addSupportPaths(docAccessMiddleware: express.RequestHandler[]) {
|
||||
if (!this._docWorker) { throw new Error("need DocWorker"); }
|
||||
|
||||
this.app.get('/download', ...docAccessMiddleware, expressWrap(async (req, res) => {
|
||||
|
||||
@@ -598,7 +598,7 @@ export class GranularAccess implements GranularAccessForBundle {
|
||||
const message = { actionGroup, docActions };
|
||||
await this._docClients.broadcastDocMessage(client, 'docUserAction',
|
||||
message,
|
||||
(docSession) => this._filterDocUpdate(docSession, message));
|
||||
(_docSession) => this._filterDocUpdate(_docSession, message));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -786,21 +786,21 @@ export class GranularAccess implements GranularAccessForBundle {
|
||||
// If the column is not row dependent, we have nothing to do.
|
||||
if (access.getColumnAccess(tableId, colId).perms.read !== 'mixed') { continue; }
|
||||
// Check column accessibility before and after.
|
||||
const forbiddenBefores = new Set(await this._getForbiddenRows(cursor, rowsBefore, ids, colId));
|
||||
const forbiddenAfters = new Set(await this._getForbiddenRows(cursor, rowsAfter, ids, colId));
|
||||
const _forbiddenBefores = new Set(await this._getForbiddenRows(cursor, rowsBefore, ids, colId));
|
||||
const _forbiddenAfters = new Set(await this._getForbiddenRows(cursor, rowsAfter, ids, colId));
|
||||
// For any column that is in a visible row and for which accessibility has changed,
|
||||
// pull it into the doc actions. We don't censor cells yet, that happens later
|
||||
// (if that's what needs doing).
|
||||
const changedIds = orderedIds.filter(id => !forceRemoves.has(id) && !removals.has(id) &&
|
||||
(forbiddenBefores.has(id) !== forbiddenAfters.has(id)));
|
||||
(_forbiddenBefores.has(id) !== _forbiddenAfters.has(id)));
|
||||
if (changedIds.length > 0) {
|
||||
revisedDocActions.push(this._makeColumnUpdate(rowsAfter, colId, new Set(changedIds)));
|
||||
}
|
||||
}
|
||||
|
||||
// Return the results, also applying any cell-level access control.
|
||||
for (const action of revisedDocActions) {
|
||||
await this._filterRowsAndCells({...cursor, action}, rowsAfter, rowsAfter, readAccessCheck);
|
||||
for (const a of revisedDocActions) {
|
||||
await this._filterRowsAndCells({...cursor, action: a}, rowsAfter, rowsAfter, readAccessCheck);
|
||||
}
|
||||
return revisedDocActions;
|
||||
}
|
||||
@@ -1656,7 +1656,7 @@ export const accessChecks = {
|
||||
const readAccessCheck = accessChecks.check.read;
|
||||
|
||||
// This AccessCheck allows everything.
|
||||
const dummyAccessCheck = { get() { return 'allow'; } }
|
||||
const dummyAccessCheck = { get() { return 'allow'; } };
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -681,7 +681,7 @@ export class HostedStorageManager implements IDocStorageManager {
|
||||
lastModified: t,
|
||||
snapshotId: newSnapshotId,
|
||||
metadata
|
||||
}
|
||||
};
|
||||
await this._inventory.add(docId, snapshot, prevSnapshotId);
|
||||
await this._onInventoryChange(docId);
|
||||
} finally {
|
||||
|
||||
@@ -51,7 +51,7 @@ export class PluginManager {
|
||||
};
|
||||
}
|
||||
|
||||
public dirs(): PluginDirectories {return this._dirs; }
|
||||
public dirs(): PluginDirectories { return this._dirs; }
|
||||
|
||||
/**
|
||||
* Create tmp dir and load plugins.
|
||||
|
||||
@@ -27,7 +27,7 @@ export function getRelatedRows(docActions: DocAction[]): ReadonlyArray<readonly
|
||||
if (docAction[0] === 'RenameTable') {
|
||||
if (addedTables.has(currentTableId)) {
|
||||
addedTables.delete(currentTableId);
|
||||
addedTables.add(docAction[2])
|
||||
addedTables.add(docAction[2]);
|
||||
continue;
|
||||
}
|
||||
tableIds.delete(currentTableId);
|
||||
|
||||
@@ -118,7 +118,7 @@ export class Sharing {
|
||||
assert(this._hubQueue.isEmpty() && !this._pendingQueue.isEmpty());
|
||||
const userRequest: UserRequest = this._pendingQueue.shift()!;
|
||||
try {
|
||||
const ret = await this.doApplyUserActionBundle(userRequest.action, userRequest.docSession);
|
||||
const ret = await this._doApplyUserActionBundle(userRequest.action, userRequest.docSession);
|
||||
userRequest.resolve(ret);
|
||||
} catch (e) {
|
||||
log.warn("Unable to apply action...", e);
|
||||
@@ -130,7 +130,7 @@ export class Sharing {
|
||||
assert(!this._hubQueue.isEmpty() && !this._actionHistory.haveLocalActions());
|
||||
const action: ActionBundle = this._hubQueue.shift()!;
|
||||
try {
|
||||
await this.doApplySharedActionBundle(action);
|
||||
await this._doApplySharedActionBundle(action);
|
||||
} catch (e) {
|
||||
log.error("Unable to apply hub action... skipping");
|
||||
}
|
||||
@@ -155,15 +155,15 @@ export class Sharing {
|
||||
private async _rebaseLocalActions(): Promise<void> {
|
||||
const rebaseQueue: Deque<UserActionBundle> = new Deque<UserActionBundle>();
|
||||
try {
|
||||
this.createCheckpoint();
|
||||
this._createCheckpoint();
|
||||
const actions: LocalActionBundle[] = await this._actionHistory.fetchAllLocal();
|
||||
assert(actions.length > 0);
|
||||
await this.doApplyUserActionBundle(this._createUndo(actions), null);
|
||||
await this._doApplyUserActionBundle(this._createUndo(actions), null);
|
||||
rebaseQueue.push(...actions.map((a) => getUserActionBundle(a)));
|
||||
await this._actionHistory.clearLocalActions();
|
||||
} catch (e) {
|
||||
log.error("Can't undo local actions; sharing is off");
|
||||
this.rollbackToCheckpoint();
|
||||
this._rollbackToCheckpoint();
|
||||
// TODO this.disconnect();
|
||||
// TODO errorState = true;
|
||||
return;
|
||||
@@ -178,34 +178,34 @@ export class Sharing {
|
||||
const action: UserActionBundle = rebaseQueue.shift()!;
|
||||
const adjusted: UserActionBundle = this._mergeAdjust(action);
|
||||
try {
|
||||
await this.doApplyUserActionBundle(adjusted, null);
|
||||
await this._doApplyUserActionBundle(adjusted, null);
|
||||
} catch (e) {
|
||||
log.warn("Unable to apply rebased action...");
|
||||
rebaseFailures.push([action, adjusted]);
|
||||
}
|
||||
}
|
||||
if (rebaseFailures.length > 0) {
|
||||
this.createBackupAtCheckpoint();
|
||||
this._createBackupAtCheckpoint();
|
||||
// TODO we should notify the user too.
|
||||
log.error('Rebase failed to reapply some of your actions, backup of local at...');
|
||||
}
|
||||
this.releaseCheckpoint();
|
||||
this._releaseCheckpoint();
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
|
||||
private doApplySharedActionBundle(action: ActionBundle): Promise<UserResult> {
|
||||
private _doApplySharedActionBundle(action: ActionBundle): Promise<UserResult> {
|
||||
const userActions: UserAction[] = [
|
||||
['ApplyDocActions', action.stored.map(envContent => envContent[1])]
|
||||
];
|
||||
return this.doApplyUserActions(action.info[1], userActions, Branch.Shared, null);
|
||||
return this._doApplyUserActions(action.info[1], userActions, Branch.Shared, null);
|
||||
}
|
||||
|
||||
private doApplyUserActionBundle(action: UserActionBundle, docSession: OptDocSession|null): Promise<UserResult> {
|
||||
return this.doApplyUserActions(action.info, action.userActions, Branch.Local, docSession);
|
||||
private _doApplyUserActionBundle(action: UserActionBundle, docSession: OptDocSession|null): Promise<UserResult> {
|
||||
return this._doApplyUserActions(action.info, action.userActions, Branch.Local, docSession);
|
||||
}
|
||||
|
||||
private async doApplyUserActions(info: ActionInfo, userActions: UserAction[],
|
||||
private async _doApplyUserActions(info: ActionInfo, userActions: UserAction[],
|
||||
branch: Branch, docSession: OptDocSession|null): Promise<UserResult> {
|
||||
const client = docSession && docSession.client;
|
||||
|
||||
@@ -245,7 +245,7 @@ export class Sharing {
|
||||
actionHash: null, // Gets set below by _actionHistory.recordNext...
|
||||
parentActionHash: null, // Gets set below by _actionHistory.recordNext...
|
||||
};
|
||||
this._logActionBundle(`doApplyUserActions (${Branch[branch]})`, localActionBundle);
|
||||
this._logActionBundle(`_doApplyUserActions (${Branch[branch]})`, localActionBundle);
|
||||
|
||||
// TODO Note that the sandbox may produce actions which are not addressed to us (e.g. when we
|
||||
// have EDIT permission without VIEW). These are not sent to the browser or the database. But
|
||||
@@ -332,10 +332,10 @@ export class Sharing {
|
||||
}
|
||||
|
||||
// Our beautiful little checkpointing interface, used to handle errors during rebase.
|
||||
private createCheckpoint() { /* TODO */ }
|
||||
private releaseCheckpoint() { /* TODO */ }
|
||||
private rollbackToCheckpoint() { /* TODO */ }
|
||||
private createBackupAtCheckpoint() { /* TODO */ }
|
||||
private _createCheckpoint() { /* TODO */ }
|
||||
private _releaseCheckpoint() { /* TODO */ }
|
||||
private _rollbackToCheckpoint() { /* TODO */ }
|
||||
private _createBackupAtCheckpoint() { /* TODO */ }
|
||||
|
||||
/**
|
||||
* Reduces a LocalActionBundle down to only those actions addressed to ourselves.
|
||||
|
||||
@@ -61,7 +61,7 @@ function createSessionStoreFactory(sessionsDB: string): () => SessionStore {
|
||||
// Doesn't actually close, just unrefs stream so node becomes close-able.
|
||||
store.client.unref();
|
||||
}});
|
||||
}
|
||||
};
|
||||
} else {
|
||||
const SQLiteStore = require('@gristlabs/connect-sqlite3')(session);
|
||||
promisifyAll(SQLiteStore.prototype);
|
||||
@@ -72,7 +72,7 @@ function createSessionStoreFactory(sessionsDB: string): () => SessionStore {
|
||||
table: 'sessions'
|
||||
});
|
||||
return assignIn(store, { async close() {}});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ export function getAvailablePort(firstPort: number = 8000, optCount: number = 20
|
||||
export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: string,
|
||||
family?: number, allowHalfOpen?: boolean; }): Promise<net.Socket>;
|
||||
export function connect(port: number, host?: string): Promise<net.Socket>;
|
||||
export function connect(path: string): Promise<net.Socket>; // tslint:disable-line:unified-signatures
|
||||
export function connect(sockPath: string): Promise<net.Socket>;
|
||||
export function connect(arg: any, ...moreArgs: any[]): Promise<net.Socket> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const s = net.connect(arg, ...moreArgs, () => resolve(s));
|
||||
|
||||
Reference in New Issue
Block a user