lint: Run eslint --fix on src/

This commit is contained in:
Richard Hansen 2020-11-23 13:24:19 -05:00 committed by John McLear
parent b8d07a42eb
commit 8e5fd19db2
109 changed files with 9061 additions and 10572 deletions

View file

@ -14,7 +14,7 @@
const OpenAPIBackend = require('openapi-backend').default;
const formidable = require('formidable');
const { promisify } = require('util');
const {promisify} = require('util');
const cloneDeep = require('lodash.clonedeep');
const createHTTPError = require('http-errors');
@ -57,12 +57,12 @@ const resources = {
create: {
operationId: 'createGroup',
summary: 'creates a new group',
responseSchema: { groupID: { type: 'string' } },
responseSchema: {groupID: {type: 'string'}},
},
createIfNotExistsFor: {
operationId: 'createGroupIfNotExistsFor',
summary: 'this functions helps you to map your application group ids to Etherpad group ids',
responseSchema: { groupID: { type: 'string' } },
responseSchema: {groupID: {type: 'string'}},
},
delete: {
operationId: 'deleteGroup',
@ -71,7 +71,7 @@ const resources = {
listPads: {
operationId: 'listPads',
summary: 'returns all pads of this group',
responseSchema: { padIDs: { type: 'array', items: { type: 'string' } } },
responseSchema: {padIDs: {type: 'array', items: {type: 'string'}}},
},
createPad: {
operationId: 'createGroupPad',
@ -80,12 +80,12 @@ const resources = {
listSessions: {
operationId: 'listSessionsOfGroup',
summary: '',
responseSchema: { sessions: { type: 'array', items: { $ref: '#/components/schemas/SessionInfo' } } },
responseSchema: {sessions: {type: 'array', items: {$ref: '#/components/schemas/SessionInfo'}}},
},
list: {
operationId: 'listAllGroups',
summary: '',
responseSchema: { groupIDs: { type: 'array', items: { type: 'string' } } },
responseSchema: {groupIDs: {type: 'array', items: {type: 'string'}}},
},
},
@ -94,28 +94,28 @@ const resources = {
create: {
operationId: 'createAuthor',
summary: 'creates a new author',
responseSchema: { authorID: { type: 'string' } },
responseSchema: {authorID: {type: 'string'}},
},
createIfNotExistsFor: {
operationId: 'createAuthorIfNotExistsFor',
summary: 'this functions helps you to map your application author ids to Etherpad author ids',
responseSchema: { authorID: { type: 'string' } },
responseSchema: {authorID: {type: 'string'}},
},
listPads: {
operationId: 'listPadsOfAuthor',
summary: 'returns an array of all pads this author contributed to',
responseSchema: { padIDs: { type: 'array', items: { type: 'string' } } },
responseSchema: {padIDs: {type: 'array', items: {type: 'string'}}},
},
listSessions: {
operationId: 'listSessionsOfAuthor',
summary: 'returns all sessions of an author',
responseSchema: { sessions: { type: 'array', items: { $ref: '#/components/schemas/SessionInfo' } } },
responseSchema: {sessions: {type: 'array', items: {$ref: '#/components/schemas/SessionInfo'}}},
},
// We need an operation that return a UserInfo so it can be picked up by the codegen :(
getName: {
operationId: 'getAuthorName',
summary: 'Returns the Author Name of the author',
responseSchema: { info: { $ref: '#/components/schemas/UserInfo' } },
responseSchema: {info: {$ref: '#/components/schemas/UserInfo'}},
},
},
@ -124,7 +124,7 @@ const resources = {
create: {
operationId: 'createSession',
summary: 'creates a new session. validUntil is an unix timestamp in seconds',
responseSchema: { sessionID: { type: 'string' } },
responseSchema: {sessionID: {type: 'string'}},
},
delete: {
operationId: 'deleteSession',
@ -134,7 +134,7 @@ const resources = {
info: {
operationId: 'getSessionInfo',
summary: 'returns informations about a session',
responseSchema: { info: { $ref: '#/components/schemas/SessionInfo' } },
responseSchema: {info: {$ref: '#/components/schemas/SessionInfo'}},
},
},
@ -143,7 +143,7 @@ const resources = {
listAll: {
operationId: 'listAllPads',
summary: 'list all the pads',
responseSchema: { padIDs: { type: 'array', items: { type: 'string' } } },
responseSchema: {padIDs: {type: 'array', items: {type: 'string'}}},
},
createDiffHTML: {
operationId: 'createDiffHTML',
@ -158,7 +158,7 @@ const resources = {
getText: {
operationId: 'getText',
summary: 'returns the text of a pad',
responseSchema: { text: { type: 'string' } },
responseSchema: {text: {type: 'string'}},
},
setText: {
operationId: 'setText',
@ -167,7 +167,7 @@ const resources = {
getHTML: {
operationId: 'getHTML',
summary: 'returns the text of a pad formatted as HTML',
responseSchema: { html: { type: 'string' } },
responseSchema: {html: {type: 'string'}},
},
setHTML: {
operationId: 'setHTML',
@ -176,12 +176,12 @@ const resources = {
getRevisionsCount: {
operationId: 'getRevisionsCount',
summary: 'returns the number of revisions of this pad',
responseSchema: { revisions: { type: 'integer' } },
responseSchema: {revisions: {type: 'integer'}},
},
getLastEdited: {
operationId: 'getLastEdited',
summary: 'returns the timestamp of the last revision of the pad',
responseSchema: { lastEdited: { type: 'integer' } },
responseSchema: {lastEdited: {type: 'integer'}},
},
delete: {
operationId: 'deletePad',
@ -190,7 +190,7 @@ const resources = {
getReadOnlyID: {
operationId: 'getReadOnlyID',
summary: 'returns the read only link of a pad',
responseSchema: { readOnlyID: { type: 'string' } },
responseSchema: {readOnlyID: {type: 'string'}},
},
setPublicStatus: {
operationId: 'setPublicStatus',
@ -199,22 +199,22 @@ const resources = {
getPublicStatus: {
operationId: 'getPublicStatus',
summary: 'return true of false',
responseSchema: { publicStatus: { type: 'boolean' } },
responseSchema: {publicStatus: {type: 'boolean'}},
},
authors: {
operationId: 'listAuthorsOfPad',
summary: 'returns an array of authors who contributed to this pad',
responseSchema: { authorIDs: { type: 'array', items: { type: 'string' } } },
responseSchema: {authorIDs: {type: 'array', items: {type: 'string'}}},
},
usersCount: {
operationId: 'padUsersCount',
summary: 'returns the number of user that are currently editing this pad',
responseSchema: { padUsersCount: { type: 'integer' } },
responseSchema: {padUsersCount: {type: 'integer'}},
},
users: {
operationId: 'padUsers',
summary: 'returns the list of users that are currently editing this pad',
responseSchema: { padUsers: { type: 'array', items: { $ref: '#/components/schemas/UserInfo' } } },
responseSchema: {padUsers: {type: 'array', items: {$ref: '#/components/schemas/UserInfo'}}},
},
sendClientsMessage: {
operationId: 'sendClientsMessage',
@ -227,13 +227,13 @@ const resources = {
getChatHistory: {
operationId: 'getChatHistory',
summary: 'returns the chat history',
responseSchema: { messages: { type: 'array', items: { $ref: '#/components/schemas/Message' } } },
responseSchema: {messages: {type: 'array', items: {$ref: '#/components/schemas/Message'}}},
},
// We need an operation that returns a Message so it can be picked up by the codegen :(
getChatHead: {
operationId: 'getChatHead',
summary: 'returns the chatHead (chat-message) of the pad',
responseSchema: { chatHead: { $ref: '#/components/schemas/Message' } },
responseSchema: {chatHead: {$ref: '#/components/schemas/Message'}},
},
appendChatMessage: {
operationId: 'appendChatMessage',
@ -384,10 +384,10 @@ const defaultResponseRefs = {
const operations = {};
for (const resource in resources) {
for (const action in resources[resource]) {
const { operationId, responseSchema, ...operation } = resources[resource][action];
const {operationId, responseSchema, ...operation} = resources[resource][action];
// add response objects
const responses = { ...defaultResponseRefs };
const responses = {...defaultResponseRefs};
if (responseSchema) {
responses[200] = cloneDeep(defaultResponses.Success);
responses[200].content['application/json'].schema.properties.data = {
@ -478,14 +478,14 @@ const generateDefinitionForVersion = (version, style = APIPathStyle.FLAT) => {
},
},
},
security: [{ ApiKey: [] }],
security: [{ApiKey: []}],
};
// build operations
for (const funcName in apiHandler.version[version]) {
let operation = {};
if (operations[funcName]) {
operation = { ...operations[funcName] };
operation = {...operations[funcName]};
} else {
// console.warn(`No operation found for function: ${funcName}`);
operation = {
@ -497,7 +497,7 @@ const generateDefinitionForVersion = (version, style = APIPathStyle.FLAT) => {
// set parameters
operation.parameters = operation.parameters || [];
for (const paramName of apiHandler.version[version][funcName]) {
operation.parameters.push({ $ref: `#/components/parameters/${paramName}` });
operation.parameters.push({$ref: `#/components/parameters/${paramName}`});
if (!definition.components.parameters[paramName]) {
definition.components.parameters[paramName] = {
name: paramName,
@ -533,7 +533,7 @@ const generateDefinitionForVersion = (version, style = APIPathStyle.FLAT) => {
};
exports.expressCreateServer = (hookName, args, cb) => {
const { app } = args;
const {app} = args;
// create openapi-backend handlers for each api version under /api/{version}/*
for (const version in apiHandler.version) {
@ -550,7 +550,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
app.get(`${apiRoot}/openapi.json`, (req, res) => {
// For openapi definitions, wide CORS is probably fine
res.header('Access-Control-Allow-Origin', '*');
res.json({ ...definition, servers: [generateServerForApiVersion(apiRoot, req)] });
res.json({...definition, servers: [generateServerForApiVersion(apiRoot, req)]});
});
// serve latest openapi definition file under /api/openapi.json
@ -558,7 +558,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
if (isLatestAPIVersion) {
app.get(`/${style}/openapi.json`, (req, res) => {
res.header('Access-Control-Allow-Origin', '*');
res.json({ ...definition, servers: [generateServerForApiVersion(apiRoot, req)] });
res.json({...definition, servers: [generateServerForApiVersion(apiRoot, req)]});
});
}
@ -586,7 +586,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
for (const funcName in apiHandler.version[version]) {
const handler = async (c, req, res) => {
// parse fields from request
const { header, params, query } = c.request;
const {header, params, query} = c.request;
// read form data if method was POST
let formData = {};
@ -602,7 +602,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
apiLogger.info(`REQUEST, v${version}:${funcName}, ${JSON.stringify(fields)}`);
// pass to api handler
let data = await apiHandler.handle(version, funcName, fields, req, res).catch((err) => {
const data = await apiHandler.handle(version, funcName, fields, req, res).catch((err) => {
// convert all errors to http errors
if (createHTTPError.isHttpError(err)) {
// pass http errors thrown by handler forward
@ -620,7 +620,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
});
// return in common format
let response = { code: 0, message: 'ok', data: data || null };
const response = {code: 0, message: 'ok', data: data || null};
// log response
apiLogger.info(`RESPONSE, ${funcName}, ${JSON.stringify(response)}`);
@ -654,24 +654,24 @@ exports.expressCreateServer = (hookName, args, cb) => {
// https://github.com/ether/etherpad-lite/tree/master/doc/api/http_api.md#response-format
switch (res.statusCode) {
case 403: // forbidden
response = { code: 4, message: err.message, data: null };
response = {code: 4, message: err.message, data: null};
break;
case 401: // unauthorized (no or wrong api key)
response = { code: 4, message: err.message, data: null };
response = {code: 4, message: err.message, data: null};
break;
case 404: // not found (no such function)
response = { code: 3, message: err.message, data: null };
response = {code: 3, message: err.message, data: null};
break;
case 500: // server error (internal error)
response = { code: 2, message: err.message, data: null };
response = {code: 2, message: err.message, data: null};
break;
case 400: // bad request (wrong parameters)
// respond with 200 OK to keep old behavior and pass tests
res.statusCode = 200; // @TODO: this is bad api design
response = { code: 1, message: err.message, data: null };
response = {code: 1, message: err.message, data: null};
break;
default:
response = { code: 1, message: err.message, data: null };
response = {code: 1, message: err.message, data: null};
break;
}
}