chore: Upgrade Prettier 1.8 -> 2.0 (#1436)

This commit is contained in:
Tom Moor
2020-08-08 18:53:11 -07:00
committed by GitHub
parent 68dcb4de5f
commit e312b264a6
218 changed files with 1156 additions and 1169 deletions

View File

@ -46,18 +46,18 @@ const createRevision = (doc, options = {}) => {
);
};
const createUrlId = doc => {
const createUrlId = (doc) => {
return (doc.urlId = doc.urlId || randomstring.generate(10));
};
const beforeCreate = async doc => {
const beforeCreate = async (doc) => {
if (doc.version === undefined) {
doc.version = DOCUMENT_VERSION;
}
return beforeSave(doc);
};
const beforeSave = async doc => {
const beforeSave = async (doc) => {
const { emoji } = parseTitle(doc.text);
// emoji in the title is split out for easier display
@ -123,7 +123,7 @@ const Document = sequelize.define(
afterUpdate: createRevision,
},
getterMethods: {
url: function() {
url: function () {
const slugifiedTitle = slugify(this.title);
return `/doc/${slugifiedTitle}-${this.urlId}`;
},
@ -133,7 +133,7 @@ const Document = sequelize.define(
// Class methods
Document.associate = models => {
Document.associate = (models) => {
Document.belongsTo(models.Collection, {
as: "collection",
foreignKey: "collectionId",
@ -185,7 +185,7 @@ Document.associate = models => {
},
},
});
Document.addScope("withCollection", userId => {
Document.addScope("withCollection", (userId) => {
if (userId) {
return {
include: [
@ -209,19 +209,19 @@ Document.associate = models => {
{ model: models.User, as: "updatedBy", paranoid: false },
],
});
Document.addScope("withViews", userId => ({
Document.addScope("withViews", (userId) => ({
include: [
{ model: models.View, as: "views", where: { userId }, required: false },
],
}));
Document.addScope("withStarred", userId => ({
Document.addScope("withStarred", (userId) => ({
include: [
{ model: models.Star, as: "starred", where: { userId }, required: false },
],
}));
};
Document.findByPk = async function(id, options = {}) {
Document.findByPk = async function (id, options = {}) {
// allow default preloading of collection membership if `userId` is passed in find options
// almost every endpoint needs the collection membership to determine policy permissions.
const scope = this.scope("withUnpublished", {
@ -322,7 +322,7 @@ Document.searchForTeam = async (
],
});
return map(results, result => ({
return map(results, (result) => ({
ranking: result.searchRanking,
context: removeMarkdown(unescape(result.searchContext), {
stripHTML: false,
@ -424,7 +424,7 @@ Document.searchForUser = async (
],
});
return map(results, result => ({
return map(results, (result) => ({
ranking: result.searchRanking,
context: removeMarkdown(unescape(result.searchContext), {
stripHTML: false,
@ -435,7 +435,7 @@ Document.searchForUser = async (
// Hooks
Document.addHook("beforeSave", async model => {
Document.addHook("beforeSave", async (model) => {
if (!model.publishedAt || model.template) {
return;
}
@ -449,7 +449,7 @@ Document.addHook("beforeSave", async model => {
model.collection = collection;
});
Document.addHook("afterCreate", async model => {
Document.addHook("afterCreate", async (model) => {
if (!model.publishedAt || model.template) {
return;
}
@ -467,7 +467,7 @@ Document.addHook("afterCreate", async model => {
// Instance methods
Document.prototype.toMarkdown = function() {
Document.prototype.toMarkdown = function () {
const text = unescape(this.text);
if (this.version) {
@ -477,7 +477,7 @@ Document.prototype.toMarkdown = function() {
return text;
};
Document.prototype.migrateVersion = function() {
Document.prototype.migrateVersion = function () {
let migrated = false;
// migrate from document version 0 -> 1
@ -505,13 +505,13 @@ Document.prototype.migrateVersion = function() {
// Note: This method marks the document and it's children as deleted
// in the database, it does not permanently delete them OR remove
// from the collection structure.
Document.prototype.deleteWithChildren = async function(options) {
Document.prototype.deleteWithChildren = async function (options) {
// Helper to destroy all child documents for a document
const loopChildren = async (documentId, opts) => {
const childDocuments = await Document.findAll({
where: { parentDocumentId: documentId },
});
childDocuments.forEach(async child => {
childDocuments.forEach(async (child) => {
await loopChildren(child.id, opts);
await child.destroy(opts);
});
@ -521,15 +521,15 @@ Document.prototype.deleteWithChildren = async function(options) {
await this.destroy(options);
};
Document.prototype.archiveWithChildren = async function(userId, options) {
Document.prototype.archiveWithChildren = async function (userId, options) {
const archivedAt = new Date();
// Helper to archive all child documents for a document
const archiveChildren = async parentDocumentId => {
const archiveChildren = async (parentDocumentId) => {
const childDocuments = await Document.findAll({
where: { parentDocumentId },
});
childDocuments.forEach(async child => {
childDocuments.forEach(async (child) => {
await archiveChildren(child.id);
child.archivedAt = archivedAt;
@ -544,7 +544,7 @@ Document.prototype.archiveWithChildren = async function(userId, options) {
return this.save(options);
};
Document.prototype.publish = async function(options) {
Document.prototype.publish = async function (options) {
if (this.publishedAt) return this.save(options);
const collection = await Collection.findByPk(this.collectionId);
@ -560,7 +560,7 @@ Document.prototype.publish = async function(options) {
// Moves a document from being visible to the team within a collection
// to the archived area, where it can be subsequently restored.
Document.prototype.archive = async function(userId) {
Document.prototype.archive = async function (userId) {
// archive any children and remove from the document structure
const collection = await this.getCollection();
await collection.removeDocumentInStructure(this);
@ -572,7 +572,7 @@ Document.prototype.archive = async function(userId) {
};
// Restore an archived document back to being visible to the team
Document.prototype.unarchive = async function(userId) {
Document.prototype.unarchive = async function (userId) {
const collection = await this.getCollection();
// check to see if the documents parent hasn't been archived also
@ -604,7 +604,7 @@ Document.prototype.unarchive = async function(userId) {
};
// Delete a document, archived or otherwise.
Document.prototype.delete = function(options) {
Document.prototype.delete = function (options) {
return sequelize.transaction(async (transaction: Transaction): Promise<*> => {
if (!this.archivedAt) {
// delete any children and remove from the document structure
@ -623,11 +623,11 @@ Document.prototype.delete = function(options) {
});
};
Document.prototype.getTimestamp = function() {
Document.prototype.getTimestamp = function () {
return Math.round(new Date(this.updatedAt).getTime() / 1000);
};
Document.prototype.getSummary = function() {
Document.prototype.getSummary = function () {
const plain = removeMarkdown(unescape(this.text), {
stripHTML: false,
});
@ -641,7 +641,7 @@ Document.prototype.getSummary = function() {
return notEmpty ? lines[1] : "";
};
Document.prototype.toJSON = function() {
Document.prototype.toJSON = function () {
// Warning: only use for new documents as order of children is
// handled in the collection's documentStructure
return {