Yuki Takei 7 лет назад
Родитель
Сommit
17b067b49b

+ 3 - 6
src/client/js/legacy/crowi.js

@@ -214,7 +214,7 @@ Crowi.findHashFromUrl = function(url) {
   if (match = url.match(/#(.+)$/)) {
     return `#${match[1]}`;
   }
-  /* eslint-enable */
+  /* eslint-enable no-cond-assign */
 
   return '';
 };
@@ -517,9 +517,8 @@ $(() => {
    */
   $('#view-list .page-list-ul-flat .page-list-link').each(function() {
     const $link = $(this);
-    /* eslint-disable no-unused-vars */
+    /* eslint-disable-next-line no-unused-vars */
     const text = $link.text();
-    /* eslint-enable */
     let path = decodeURIComponent($link.data('path'));
     const shortPath = decodeURIComponent($link.data('short-path')); // convert to string
 
@@ -550,9 +549,7 @@ $(() => {
         const id = $(this).attr('id');
         const revisionBody = `#${id} .revision-body`;
         const revisionBodyElem = document.querySelector(revisionBody);
-        /* eslint-disable no-unused-vars */
-        const revisionPath = `#${id} .revision-path`;
-        /* eslint-enable */
+        const revisionPath = `#${id} .revision-path`; // eslint-disable-line no-unused-vars
         const timelineElm = document.getElementById(id);
         const pageId = timelineElm.getAttribute('data-page-id');
         const pagePath = timelineElm.getAttribute('data-page-path');

+ 1 - 1
src/client/js/util/PostProcessor/CrowiTemplate.js

@@ -35,7 +35,7 @@ export default class CrowiTemplate {
           + `</button>`
           + `<pre><code id="${templateId}" class="lang-${lang}">${code}\n</code></pre>`
         + `</div>`
-        /* eslint-enable */
+        /* eslint-enable quotes */
       );
     });
   }

+ 1 - 3
src/client/js/util/interceptor/detach-code-blocks.js

@@ -43,9 +43,7 @@ export class DetachCodeBlockInterceptor extends BasicInterceptor {
 
     const context = Object.assign(args[0]); // clone
     const targetKey = this.getTargetKey(contextName);
-    /* eslint-disable no-unused-vars */
-    const currentPagePath = context.currentPagePath;
-    /* eslint-enable */
+    const currentPagePath = context.currentPagePath; // eslint-disable-line no-unused-vars
 
     context.dcbContextMap = {};
 

+ 0 - 2
src/lib/service/cdn-resources-downloader.js

@@ -128,7 +128,6 @@ class CdnResourcesDownloader {
     );
   }
 
-  /* eslint-disable class-methods-use-this */
   async downloadAndWriteToFS(url, outDir, fileName, replacestream) {
     // get
     const response = await axios.get(url, { responseType: 'stream' });
@@ -145,7 +144,6 @@ class CdnResourcesDownloader {
 
     return streamToPromise(stream);
   }
-  /* eslint-enable */
 }
 
 module.exports = CdnResourcesDownloader;

+ 0 - 4
src/lib/service/cdn-resources-service.js

@@ -73,7 +73,6 @@ class CdnResourcesService {
    * @param {Object} manifest
    * @param {boolean} noCdn
    */
-  /* eslint-disable class-methods-use-this */
   generateScriptTag(manifest, noCdn) {
     const attrs = [];
     const args = manifest.args || {};
@@ -92,7 +91,6 @@ class CdnResourcesService {
       : manifest.url;
     return `<script src="${url}" ${attrs.join(' ')}></script>`;
   }
-  /* eslint-enable */
 
   getScriptTagByName(name) {
     const manifest = this.getScriptManifestByName(name);
@@ -115,7 +113,6 @@ class CdnResourcesService {
    * @param {Object} manifest
    * @param {boolean} noCdn
    */
-  /* eslint-disable class-methods-use-this */
   generateStyleTag(manifest, noCdn) {
     const attrs = [];
     const args = manifest.args || {};
@@ -135,7 +132,6 @@ class CdnResourcesService {
 
     return `<link rel="stylesheet" href="${url}" ${attrs.join(' ')}>`;
   }
-  /* eslint-enable */
 
   getStyleTagByName(name) {
     const manifest = this.getStyleManifestByName(name);

+ 0 - 2
src/lib/service/interceptor-manager.js

@@ -86,7 +86,6 @@ class InterceptorManager {
     });
   }
 
-  /* eslint-disable class-methods-use-this */
   doProcess(interceptor, contextName, ...args) {
     return interceptor.process(contextName, ...args)
       .then((...results) => {
@@ -99,7 +98,6 @@ class InterceptorManager {
         return Promise.resolve(...args);
       });
   }
-  /* eslint-enable */
 }
 
 module.exports = InterceptorManager;

+ 2 - 2
src/migrations/20181019114028-abolish-page-group-relation.js

@@ -62,7 +62,7 @@ module.exports = {
       page.grantedGroup = userGroup;
       await page.save();
     }
-    /* eslint-enable */
+    /* eslint-enable no-await-in-loop */
 
     // drop collection
     await db.collection('pagegrouprelations').drop();
@@ -104,7 +104,7 @@ module.exports = {
       page.grantedGroup = undefined;
       await page.save();
     }
-    /* eslint-enable */
+    /* eslint-enable no-await-in-loop */
 
     await db.collection('pagegrouprelations').insertMany(insertDocs);
 

+ 1 - 1
src/server/crowi/index.js

@@ -197,7 +197,7 @@ Crowi.prototype.setupAppConfig = function() {
 Crowi.prototype.setupConfigManager = async function() {
   const ConfigManager = require('../service/config-manager');
   this.configManager = new ConfigManager(this.model('Config'));
-  return await this.configManager.loadConfigs();
+  return this.configManager.loadConfigs();
 };
 
 Crowi.prototype.setupModels = function() {

+ 3 - 0
src/server/models/GlobalNotificationSetting.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const mongoose = require('mongoose');
 const GlobalNotificationSetting = require('./GlobalNotificationSetting/index');
 

+ 3 - 0
src/server/models/attachment.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const debug = require('debug')('growi:models:attachment');
 const logger = require('@alias/logger')('growi:models:attachment');
 const path = require('path');

+ 3 - 0
src/server/models/bookmark.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 module.exports = function(crowi) {
   const debug = require('debug')('growi:models:bookmark');
   const mongoose = require('mongoose');

+ 3 - 0
src/server/models/comment.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 module.exports = function(crowi) {
   const debug = require('debug')('growi:models:comment');
   const mongoose = require('mongoose');

+ 4 - 1
src/server/models/config.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 module.exports = function(crowi) {
   const mongoose = require('mongoose');
   const debug = require('debug')('growi:models:config');
@@ -116,7 +119,7 @@ module.exports = function(crowi) {
       'importer:qiita:team_name': '',
       'importer:qiita:access_token': '',
     };
-    /* eslint-enable */
+    /* eslint-enable key-spacing */
   }
 
   function getDefaultMarkdownConfigs() {

+ 3 - 0
src/server/models/external-account.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const debug = require('debug')('growi:models:external-account');
 const mongoose = require('mongoose');
 const mongoosePaginate = require('mongoose-paginate');

+ 14 - 18
src/server/models/page-group-relation.js

@@ -1,8 +1,11 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const debug = require('debug')('growi:models:pageGroupRelation');
 const mongoose = require('mongoose');
 const mongoosePaginate = require('mongoose-paginate');
-const ObjectId = mongoose.Schema.Types.ObjectId;
 
+const ObjectId = mongoose.Schema.Types.ObjectId;
 
 /*
  * define schema
@@ -13,7 +16,7 @@ const schema = new mongoose.Schema({
   createdAt: { type: Date, default: Date.now },
 }, {
   toJSON: { getters: true },
-  toObject: { getters: true }
+  toObject: { getters: true },
 });
 // apply plugins
 schema.plugin(mongoosePaginate);
@@ -25,7 +28,6 @@ schema.plugin(mongoosePaginate);
  * @class PageGroupRelation
  */
 class PageGroupRelation {
-
   /**
    * limit items num for pagination
    *
@@ -54,15 +56,15 @@ class PageGroupRelation {
    */
   static removeAllInvalidRelations() {
     return this.findAllRelation()
-      .then(relations => {
+      .then((relations) => {
         // filter invalid documents
-        return relations.filter(relation => {
+        return relations.filter((relation) => {
           return relation.targetPage == null || relation.relatedGroup == null;
         });
       })
-      .then(invalidRelations => {
-        const ids = invalidRelations.map(relation => relation._id);
-        return this.deleteMany({ _id: { $in: ids }});
+      .then((invalidRelations) => {
+        const ids = invalidRelations.map((relation) => { return relation._id });
+        return this.deleteMany({ _id: { $in: ids } });
       });
   }
 
@@ -74,7 +76,6 @@ class PageGroupRelation {
    * @memberof PageGroupRelation
    */
   static findAllRelation() {
-
     return this
       .find()
       .populate('targetPage')
@@ -139,12 +140,11 @@ class PageGroupRelation {
       .count(query)
       .then((count) => {
         // return (0 < count);
-        if (0 < count) {
+        if (count > 0) {
           return this.find(query).exec();
         }
-        else {
-          return this.createRelation(userGroup, page);
-        }
+
+        return this.createRelation(userGroup, page);
       });
   }
 
@@ -157,7 +157,6 @@ class PageGroupRelation {
    * @memberof PageGroupRelation
    */
   static findByPage(page) {
-
     if (page == null) {
       return null;
     }
@@ -223,9 +222,8 @@ class PageGroupRelation {
    * @memberof PageGroupRelation
    */
   static removeAllByPage(page) {
-
     return this.findByPage(page)
-      .then(relation => {
+      .then((relation) => {
         if (relation != null) {
           relation.remove();
         }
@@ -241,7 +239,6 @@ class PageGroupRelation {
    * @memberof PageGroupRelation
    */
   static removeById(id) {
-
     return this.findById(id)
       .then((relationData) => {
         if (relationData == null) {
@@ -252,7 +249,6 @@ class PageGroupRelation {
         }
       });
   }
-
 }
 
 module.exports = function(crowi) {

+ 6 - 2
src/server/models/page-tag-relation.js

@@ -1,5 +1,9 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const mongoose = require('mongoose');
 const mongoosePaginate = require('mongoose-paginate');
+
 const ObjectId = mongoose.Schema.Types.ObjectId;
 
 
@@ -10,12 +14,12 @@ const schema = new mongoose.Schema({
   relatedPage: {
     type: ObjectId,
     ref: 'Page',
-    required: true
+    required: true,
   },
   relatedTag: {
     type: ObjectId,
     ref: 'Tag',
-    required: true
+    required: true,
   },
 });
 schema.plugin(mongoosePaginate);

+ 129 - 128
src/server/models/page.js

@@ -1,28 +1,31 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const debug = require('debug')('growi:models:page');
 const nodePath = require('path');
 const mongoose = require('mongoose');
 const uniqueValidator = require('mongoose-unique-validator');
-const ObjectId = mongoose.Schema.Types.ObjectId;
 
+const ObjectId = mongoose.Schema.Types.ObjectId;
 const escapeStringRegexp = require('escape-string-regexp');
-
 const templateChecker = require('@commons/util/template-checker');
 
 /*
  * define schema
  */
-const GRANT_PUBLIC = 1
-  , GRANT_RESTRICTED = 2
-  , GRANT_SPECIFIED = 3
-  , GRANT_OWNER = 4
-  , GRANT_USER_GROUP = 5
-  , PAGE_GRANT_ERROR = 1
-
-  , STATUS_PUBLISHED  = 'published'
-  , STATUS_DELETED    = 'deleted'
-;
+const GRANT_PUBLIC = 1;
+const GRANT_RESTRICTED = 2;
+const GRANT_SPECIFIED = 3;
+const GRANT_OWNER = 4;
+const GRANT_USER_GROUP = 5;
+const PAGE_GRANT_ERROR = 1;
+const STATUS_PUBLISHED = 'published';
+const STATUS_DELETED = 'deleted';
+
 const pageSchema = new mongoose.Schema({
-  path: { type: String, required: true, index: true, unique: true },
+  path: {
+    type: String, required: true, index: true, unique: true,
+  },
   revision: { type: ObjectId, ref: 'Revision' },
   redirectTo: { type: String, index: true },
   status: { type: String, default: STATUS_PUBLISHED, index: true },
@@ -37,7 +40,7 @@ const pageSchema = new mongoose.Schema({
   extended: {
     type: String,
     default: '{}',
-    get: function(data) {
+    get(data) {
       try {
         return JSON.parse(data);
       }
@@ -45,18 +48,18 @@ const pageSchema = new mongoose.Schema({
         return data;
       }
     },
-    set: function(data) {
+    set(data) {
       return JSON.stringify(data);
-    }
+    },
   },
   pageIdOnHackmd: String,
-  revisionHackmdSynced: { type: ObjectId, ref: 'Revision' },  // the revision that is synced to HackMD
-  hasDraftOnHackmd: { type: Boolean },                        // set true if revision and revisionHackmdSynced are same but HackMD document has modified
+  revisionHackmdSynced: { type: ObjectId, ref: 'Revision' }, // the revision that is synced to HackMD
+  hasDraftOnHackmd: { type: Boolean }, // set true if revision and revisionHackmdSynced are same but HackMD document has modified
   createdAt: { type: Date, default: Date.now() },
   updatedAt: { type: Date, default: Date.now() },
 }, {
-  toJSON: {getters: true},
-  toObject: {getters: true}
+  toJSON: { getters: true },
+  toObject: { getters: true },
 });
 // apply plugins
 pageSchema.plugin(uniqueValidator);
@@ -96,6 +99,7 @@ const addSlashOfEnd = (path) => {
  * @param {any} page Query or Document
  * @param {string} userPublicFields string to set to select
  */
+/* eslint-disable object-curly-newline, object-property-newline */
 const populateDataToShowRevision = (page, userPublicFields, imagePopulation) => {
   return page
     .populate([
@@ -103,10 +107,11 @@ const populateDataToShowRevision = (page, userPublicFields, imagePopulation) =>
       { path: 'creator', model: 'User', select: userPublicFields, populate: imagePopulation },
       { path: 'grantedGroup', model: 'UserGroup' },
       { path: 'revision', model: 'Revision', populate: {
-        path: 'author', model: 'User', select: userPublicFields, populate: imagePopulation
-      }}
+        path: 'author', model: 'User', select: userPublicFields, populate: imagePopulation,
+      } },
     ]);
 };
+/* eslint-enable object-curly-newline, object-property-newline */
 
 
 class PageQueryBuilder {
@@ -118,9 +123,9 @@ class PageQueryBuilder {
     this.query = this.query
       .and({
         $or: [
-          {status: null},
-          {status: STATUS_PUBLISHED},
-        ]
+          { status: null },
+          { status: STATUS_PUBLISHED },
+        ],
       });
 
     return this;
@@ -139,7 +144,7 @@ class PageQueryBuilder {
     path = addSlashOfEnd(path);
 
     // add option to escape the regex strings
-    const combinedOption = Object.assign({isRegExpEscapedFromPath: true}, option);
+    const combinedOption = Object.assign({ isRegExpEscapedFromPath: true }, option);
 
     this.addConditionToListByStartWith(path, combinedOption);
 
@@ -168,23 +173,23 @@ class PageQueryBuilder {
      */
     let pathSlashOmitted = path;
     if (path.match(/\/$/)) {
-      pathSlashOmitted = path.substr(0, path.length -1);
-      pathCondition.push({path: pathSlashOmitted});
+      pathSlashOmitted = path.substr(0, path.length - 1);
+      pathCondition.push({ path: pathSlashOmitted });
     }
 
     /*
      * 2. add decendants
      */
     const pattern = (isRegExpEscapedFromPath)
-      ? escapeStringRegexp(path)  // escape
+      ? escapeStringRegexp(path) // escape
       : pathSlashOmitted;
 
-    const queryReg = new RegExp('^' + pattern);
-    pathCondition.push({path: queryReg});
+    const queryReg = new RegExp(`^${pattern}`);
+    pathCondition.push({ path: queryReg });
 
     this.query = this.query
       .and({
-        $or: pathCondition
+        $or: pathCondition,
       });
 
     return this;
@@ -192,41 +197,41 @@ class PageQueryBuilder {
 
   addConditionToFilteringByViewer(user, userGroups, showAnyoneKnowsLink, showPagesRestrictedByOwner, showPagesRestrictedByGroup) {
     const grantConditions = [
-      {grant: null},
-      {grant: GRANT_PUBLIC},
+      { grant: null },
+      { grant: GRANT_PUBLIC },
     ];
 
     if (showAnyoneKnowsLink) {
-      grantConditions.push({grant: GRANT_RESTRICTED});
+      grantConditions.push({ grant: GRANT_RESTRICTED });
     }
 
     if (showPagesRestrictedByOwner) {
       grantConditions.push(
-        {grant: GRANT_SPECIFIED},
-        {grant: GRANT_OWNER},
+        { grant: GRANT_SPECIFIED },
+        { grant: GRANT_OWNER },
       );
     }
     else if (user != null) {
       grantConditions.push(
-        {grant: GRANT_SPECIFIED, grantedUsers: user._id},
-        {grant: GRANT_OWNER, grantedUsers: user._id},
+        { grant: GRANT_SPECIFIED, grantedUsers: user._id },
+        { grant: GRANT_OWNER, grantedUsers: user._id },
       );
     }
 
     if (showPagesRestrictedByGroup) {
       grantConditions.push(
-        {grant: GRANT_USER_GROUP},
+        { grant: GRANT_USER_GROUP },
       );
     }
     else if (userGroups != null && userGroups.length > 0) {
       grantConditions.push(
-        {grant: GRANT_USER_GROUP, grantedGroup: { $in: userGroups }},
+        { grant: GRANT_USER_GROUP, grantedGroup: { $in: userGroups } },
       );
     }
 
     this.query = this.query
       .and({
-        $or: grantConditions
+        $or: grantConditions,
       });
 
     return this;
@@ -244,7 +249,7 @@ class PageQueryBuilder {
       .populate({
         path: 'lastUpdateUser',
         select: userPublicFields,
-        populate: imagePopulation
+        populate: imagePopulation,
       });
     return this;
   }
@@ -253,7 +258,6 @@ class PageQueryBuilder {
     this.query = populateDataToShowRevision(this.query, userPublicFields, imagePopulation);
     return this;
   }
-
 }
 
 module.exports = function(crowi) {
@@ -378,7 +382,7 @@ module.exports = function(crowi) {
   };
 
   pageSchema.methods.isUpdatable = function(previousRevision) {
-    var revision = this.latestRevision || this.revision;
+    const revision = this.latestRevision || this.revision;
     if (revision != previousRevision) {
       return false;
     }
@@ -386,19 +390,19 @@ module.exports = function(crowi) {
   };
 
   pageSchema.methods.isLiked = function(userData) {
-    return this.liker.some(function(likedUser) {
+    return this.liker.some((likedUser) => {
       return likedUser == userData._id.toString();
     });
   };
 
   pageSchema.methods.like = function(userData) {
-    var self = this,
-      Page = self;
+    const self = this;
+    const Page = self;
 
-    return new Promise(function(resolve, reject) {
-      var added = self.liker.addToSet(userData._id);
+    return new Promise(((resolve, reject) => {
+      const added = self.liker.addToSet(userData._id);
       if (added.length > 0) {
-        self.save(function(err, data) {
+        self.save((err, data) => {
           if (err) {
             return reject(err);
           }
@@ -410,19 +414,18 @@ module.exports = function(crowi) {
         debug('liker not updated');
         return reject(self);
       }
-    });
-
+    }));
   };
 
   pageSchema.methods.unlike = function(userData, callback) {
-    var self = this,
-      Page = self;
+    const self = this;
+    const Page = self;
 
-    return new Promise(function(resolve, reject) {
-      var beforeCount = self.liker.length;
+    return new Promise(((resolve, reject) => {
+      const beforeCount = self.liker.length;
       self.liker.pull(userData._id);
       if (self.liker.length != beforeCount) {
-        self.save(function(err, data) {
+        self.save((err, data) => {
           if (err) {
             return reject(err);
           }
@@ -433,8 +436,7 @@ module.exports = function(crowi) {
         debug('liker not updated');
         return reject(self);
       }
-    });
-
+    }));
   };
 
   pageSchema.methods.isSeenUser = function(userData) {
@@ -478,14 +480,14 @@ module.exports = function(crowi) {
   pageSchema.methods.updateExtended = function(extended) {
     const page = this;
     page.extended = extended;
-    return new Promise(function(resolve, reject) {
-      return page.save(function(err, doc) {
+    return new Promise(((resolve, reject) => {
+      return page.save((err, doc) => {
         if (err) {
           return reject(err);
         }
         return resolve(doc);
       });
-    });
+    }));
   };
 
   pageSchema.methods.initLatestRevisionField = async function(revisionId) {
@@ -525,7 +527,7 @@ module.exports = function(crowi) {
     if (grant === GRANT_USER_GROUP) {
       this.grantedGroup = grantUserGroupId;
     }
-  }
+  };
 
 
   pageSchema.statics.updateCommentCount = function(pageId) {
@@ -534,8 +536,8 @@ module.exports = function(crowi) {
     const self = this;
     const Comment = crowi.model('Comment');
     return Comment.countCommentByPageId(pageId)
-    .then(function(count) {
-      self.update({_id: pageId}, {commentCount: count}, {}, function(err, data) {
+    .then((count) => {
+      self.update({ _id: pageId }, { commentCount: count }, {}, (err, data) => {
         if (err) {
           debug('Update commentCount Error', err);
           throw err;
@@ -547,38 +549,38 @@ module.exports = function(crowi) {
   };
 
   pageSchema.statics.getGrantLabels = function() {
-    var grantLabels = {};
-    grantLabels[GRANT_PUBLIC]     = 'Public'; // 公開
+    const grantLabels = {};
+    grantLabels[GRANT_PUBLIC] = 'Public'; // 公開
     grantLabels[GRANT_RESTRICTED] = 'Anyone with the link'; // リンクを知っている人のみ
-    //grantLabels[GRANT_SPECIFIED]  = 'Specified users only'; // 特定ユーザーのみ
+    // grantLabels[GRANT_SPECIFIED]  = 'Specified users only'; // 特定ユーザーのみ
     grantLabels[GRANT_USER_GROUP] = 'Only inside the group'; // 特定グループのみ
-    grantLabels[GRANT_OWNER]      = 'Just me'; // 自分のみ
+    grantLabels[GRANT_OWNER] = 'Just me'; // 自分のみ
 
     return grantLabels;
   };
 
   pageSchema.statics.getUserPagePath = function(user) {
-    return '/user/' + user.username;
+    return `/user/${user.username}`;
   };
 
   pageSchema.statics.getDeletedPageName = function(path) {
-    if (path.match('\/')) {
+    if (path.match('/')) {
       path = path.substr(1);
     }
-    return '/trash/' + path;
+    return `/trash/${path}`;
   };
 
   pageSchema.statics.getRevertDeletedPageName = function(path) {
-    return path.replace('\/trash', '');
+    return path.replace('/trash', '');
   };
 
   pageSchema.statics.isDeletableName = function(path) {
-    var notDeletable = [
-      /^\/user\/[^\/]+$/, // user page
+    const notDeletable = [
+      /^\/user\/[^/]+$/, // user page
     ];
 
-    for (var i = 0; i < notDeletable.length; i++) {
-      var pattern = notDeletable[i];
+    for (let i = 0; i < notDeletable.length; i++) {
+      const pattern = notDeletable[i];
       if (path.match(pattern)) {
         return false;
       }
@@ -588,25 +590,24 @@ module.exports = function(crowi) {
   };
 
   pageSchema.statics.isCreatableName = function(name) {
-    var forbiddenPages = [
+    const forbiddenPages = [
       /\^|\$|\*|\+|#|%/,
       /^\/-\/.*/,
       /^\/_r\/.*/,
       /^\/_apix?(\/.*)?/,
       /^\/?https?:\/\/.+$/, // avoid miss in renaming
-      /\/{2,}/,             // avoid miss in renaming
-      /\s+\/\s+/,           // avoid miss in renaming
+      /\/{2,}/, // avoid miss in renaming
+      /\s+\/\s+/, // avoid miss in renaming
       /.+\/edit$/,
       /.+\.md$/,
       /^\/(installer|register|login|logout|admin|me|files|trash|paste|comments)(\/.*|$)/,
     ];
 
-    var isCreatable = true;
-    forbiddenPages.forEach(function(page) {
-      var pageNameReg = new RegExp(page);
+    let isCreatable = true;
+    forbiddenPages.forEach((page) => {
+      const pageNameReg = new RegExp(page);
       if (name.match(pageNameReg)) {
         isCreatable = false;
-        return ;
       }
     });
 
@@ -615,12 +616,11 @@ module.exports = function(crowi) {
 
   pageSchema.statics.fixToCreatableName = function(path) {
     return path
-      .replace(/\/\//g, '/')
-    ;
+      .replace(/\/\//g, '/');
   };
 
   pageSchema.statics.updateRevision = function(pageId, revisionId, cb) {
-    this.update({_id: pageId}, {revision: revisionId}, {}, function(err, data) {
+    this.update({ _id: pageId }, { revision: revisionId }, {}, (err, data) => {
       cb(err, data);
     });
   };
@@ -631,7 +631,7 @@ module.exports = function(crowi) {
    * @param {User} user
    */
   pageSchema.statics.isAccessiblePageByViewer = async function(id, user) {
-    const baseQuery = this.count({_id: id});
+    const baseQuery = this.count({ _id: id });
 
     let userGroups = [];
     if (user != null) {
@@ -653,7 +653,7 @@ module.exports = function(crowi) {
    * @param {UserGroup[]} userGroups List of UserGroup instances
    */
   pageSchema.statics.findByIdAndViewer = async function(id, user, userGroups) {
-    const baseQuery = this.findOne({_id: id});
+    const baseQuery = this.findOne({ _id: id });
 
     let relatedUserGroups = userGroups;
     if (user != null && relatedUserGroups == null) {
@@ -673,7 +673,7 @@ module.exports = function(crowi) {
     if (path == null) {
       return null;
     }
-    return this.findOne({path});
+    return this.findOne({ path });
   };
 
   /**
@@ -686,7 +686,7 @@ module.exports = function(crowi) {
       throw new Error('path is required.');
     }
 
-    const baseQuery = this.findOne({path});
+    const baseQuery = this.findOne({ path });
 
     let relatedUserGroups = userGroups;
     if (user != null && relatedUserGroups == null) {
@@ -718,7 +718,7 @@ module.exports = function(crowi) {
     const ancestorsPaths = extractToAncestorsPaths(path);
 
     // pick the longest one
-    const baseQuery = this.findOne({path: { $in: ancestorsPaths }}).sort({path: -1});
+    const baseQuery = this.findOne({ path: { $in: ancestorsPaths } }).sort({ path: -1 });
 
     let relatedUserGroups = userGroups;
     if (user != null && relatedUserGroups == null) {
@@ -734,7 +734,7 @@ module.exports = function(crowi) {
   };
 
   pageSchema.statics.findByRedirectTo = function(path) {
-    return this.findOne({redirectTo: path});
+    return this.findOne({ redirectTo: path });
   };
 
   /**
@@ -765,7 +765,7 @@ module.exports = function(crowi) {
    * @param {any} option
    */
   pageSchema.statics.findListByCreator = async function(targetUser, currentUser, option) {
-    const opt = Object.assign({sort: 'createdAt', desc: -1}, option);
+    const opt = Object.assign({ sort: 'createdAt', desc: -1 }, option);
     const builder = new PageQueryBuilder(this.find({ creator: targetUser._id }));
 
     let showAnyoneKnowsLink = null;
@@ -792,7 +792,9 @@ module.exports = function(crowi) {
     builder.populateDataToList(User.USER_PUBLIC_FIELDS, User.IMAGE_POPULATION);
     const pages = await builder.query.exec('find');
 
-    const result = { pages, totalCount, offset: opt.offset, limit: opt.limit };
+    const result = {
+      pages, totalCount, offset: opt.offset, limit: opt.limit,
+    };
     return result;
   };
 
@@ -809,7 +811,7 @@ module.exports = function(crowi) {
 
     const User = crowi.model('User');
 
-    const opt = Object.assign({sort: 'updatedAt', desc: -1}, option);
+    const opt = Object.assign({ sort: 'updatedAt', desc: -1 }, option);
     const sortOpt = {};
     sortOpt[opt.sort] = opt.desc;
 
@@ -833,7 +835,9 @@ module.exports = function(crowi) {
     builder.populateDataToList(User.USER_PUBLIC_FIELDS, User.IMAGE_POPULATION);
     const pages = await builder.query.exec('find');
 
-    const result = { pages, totalCount, offset: opt.offset, limit: opt.limit };
+    const result = {
+      pages, totalCount, offset: opt.offset, limit: opt.limit,
+    };
     return result;
   }
 
@@ -889,12 +893,12 @@ module.exports = function(crowi) {
   pageSchema.statics.findTemplate = function(path) {
     const templatePath = nodePath.posix.dirname(path);
     const pathList = generatePathsOnTree(path, []);
-    const regexpList = pathList.map(path => new RegExp(`^${escapeStringRegexp(path)}/_{1,2}template$`));
+    const regexpList = pathList.map((path) => { return new RegExp(`^${escapeStringRegexp(path)}/_{1,2}template$`) });
 
     return this
-      .find({path: {$in: regexpList}})
-      .populate({path: 'revision', model: 'Revision'})
-      .then(templates => {
+      .find({ path: { $in: regexpList } })
+      .populate({ path: 'revision', model: 'Revision' })
+      .then((templates) => {
         return fetchTemplate(templates, templatePath);
       });
   };
@@ -948,7 +952,7 @@ module.exports = function(crowi) {
     const decendantsTemplate = assignDecendantsTemplate(templates, templatePath);
 
     if (childrenTemplate) {
-      templateBody =  childrenTemplate.revision.body;
+      templateBody = childrenTemplate.revision.body;
     }
     else if (decendantsTemplate) {
       templateBody = decendantsTemplate.revision.body;
@@ -1017,7 +1021,7 @@ module.exports = function(crowi) {
       grant = GRANT_PUBLIC;
     }
 
-    const isExist = await this.count({path: path});
+    const isExist = await this.count({ path });
 
     if (isExist) {
       throw new Error('Cannot create new page to existed path');
@@ -1034,7 +1038,7 @@ module.exports = function(crowi) {
     page.applyScope(user, grant, grantUserGroupId);
 
     let savedPage = await page.save();
-    const newRevision = Revision.prepareRevision(savedPage, body, null, user, {format: format});
+    const newRevision = Revision.prepareRevision(savedPage, body, null, user, { format });
     const revision = await pushRevision(savedPage, newRevision, user, grant, grantUserGroupId);
     savedPage = await this.findByPath(revision.path).populate('revision').populate('creator');
 
@@ -1096,27 +1100,25 @@ module.exports = function(crowi) {
   };
 
   pageSchema.statics.deletePage = async function(pageData, user, options = {}) {
-    const newPath = this.getDeletedPageName(pageData.path)
-      , isTrashed = checkIfTrashed(pageData.path)
-      , socketClientId = options.socketClientId || null
-      ;
+    const newPath = this.getDeletedPageName(pageData.path);
+    const isTrashed = checkIfTrashed(pageData.path);
 
+    const socketClientId = options.socketClientId || null;
     if (this.isDeletableName(pageData.path)) {
       if (isTrashed) {
         return this.completelyDeletePage(pageData, user, options);
       }
 
       pageData.status = STATUS_DELETED;
-      const updatedPageData = await this.rename(pageData, newPath, user, {createRedirectPage: true});
+      const updatedPageData = await this.rename(pageData, newPath, user, { createRedirectPage: true });
 
       if (socketClientId != null) {
         pageEvent.emit('delete', updatedPageData, user, socketClientId);
       }
       return updatedPageData;
     }
-    else {
-      return Promise.reject('Page is not deletable.');
-    }
+
+    return Promise.reject('Page is not deletable.');
   };
 
   const checkIfTrashed = (path) => {
@@ -1135,7 +1137,7 @@ module.exports = function(crowi) {
     const pages = result.pages;
 
     let updatedPage = null;
-    await Promise.all(pages.map(page => {
+    await Promise.all(pages.map((page) => {
       const isParent = (page.path === targetPage.path);
       const p = this.deletePage(page, user, options);
       if (isParent) {
@@ -1176,7 +1178,7 @@ module.exports = function(crowi) {
     const pages = result.pages;
 
     let updatedPage = null;
-    await Promise.all(pages.map(page => {
+    await Promise.all(pages.map((page) => {
       const isParent = (page.path === targetPage.path);
       const p = this.revertDeletedPage(page, user, options);
       if (isParent) {
@@ -1228,7 +1230,7 @@ module.exports = function(crowi) {
     const result = await this.findListWithDescendants(path, user, findOpts);
     const pages = result.pages;
 
-    await Promise.all(pages.map(page => {
+    await Promise.all(pages.map((page) => {
       return this.completelyDeletePage(page, user, options);
     }));
 
@@ -1268,12 +1270,11 @@ module.exports = function(crowi) {
   pageSchema.statics.rename = async function(pageData, newPagePath, user, options) {
     validateCrowi();
 
-    const Page = this
-      , Revision = crowi.model('Revision')
-      , path = pageData.path
-      , createRedirectPage = options.createRedirectPage || 0
-      , socketClientId = options.socketClientId || null
-      ;
+    const Page = this;
+    const Revision = crowi.model('Revision');
+    const path = pageData.path;
+    const createRedirectPage = options.createRedirectPage || 0;
+    const socketClientId = options.socketClientId || null;
 
     // sanitize path
     newPagePath = crowi.xss.process(newPagePath);
@@ -1285,11 +1286,11 @@ module.exports = function(crowi) {
     const updatedPageData = await pageData.save();
 
     // update Rivisions
-    await Revision.updateRevisionListByPath(path, {path: newPagePath}, {});
+    await Revision.updateRevisionListByPath(path, { path: newPagePath }, {});
 
     if (createRedirectPage) {
-      const body = 'redirect ' + newPagePath;
-      await Page.create(path, body, user, {redirectTo: newPagePath});
+      const body = `redirect ${newPagePath}`;
+      await Page.create(path, body, user, { redirectTo: newPagePath });
     }
 
     pageEvent.emit('delete', pageData, user, socketClientId);
@@ -1302,13 +1303,13 @@ module.exports = function(crowi) {
     validateCrowi();
 
     const path = pageData.path;
-    const pathRegExp = new RegExp('^' + escapeStringRegexp(path), 'i');
+    const pathRegExp = new RegExp(`^${escapeStringRegexp(path)}`, 'i');
 
     // sanitize path
     newPagePathPrefix = crowi.xss.process(newPagePathPrefix);
 
     const result = await this.findListWithDescendants(path, user, options);
-    await Promise.all(result.pages.map(page => {
+    await Promise.all(result.pages.map((page) => {
       const newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
       return this.rename(page, newPagePath, user, options);
     }));
@@ -1366,7 +1367,7 @@ module.exports = function(crowi) {
 
   pageSchema.statics.getHistories = function() {
     // TODO
-    return;
+
   };
 
   /**

+ 38 - 28
src/server/models/revision.js

@@ -1,18 +1,24 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 module.exports = function(crowi) {
   // eslint-disable-next-line no-unused-vars
   const logger = require('@alias/logger')('growi:models:revision');
 
-  const mongoose = require('mongoose')
-    , ObjectId = mongoose.Schema.Types.ObjectId
-    ;
+  const mongoose = require('mongoose');
 
+  const ObjectId = mongoose.Schema.Types.ObjectId;
   const revisionSchema = new mongoose.Schema({
     path: { type: String, required: true },
-    body: { type: String, required: true, get: (data) => {
+    body: {
+      type: String,
+      required: true,
+      get: (data) => {
       // replace CR/CRLF to LF above v3.1.5
       // see https://github.com/weseek/growi/issues/463
-      return data ? data.replace(/\r\n?/g, '\n') : '';
-    }},
+        return data ? data.replace(/\r\n?/g, '\n') : '';
+      },
+    },
     format: { type: String, default: 'markdown' },
     author: { type: ObjectId, ref: 'User' },
     createdAt: { type: Date, default: Date.now },
@@ -32,65 +38,69 @@ module.exports = function(crowi) {
   // });
 
   revisionSchema.statics.findRevisions = function(ids) {
-    const Revision = this,
-      User = crowi.model('User');
+    const Revision = this;
+
+
+    const User = crowi.model('User');
 
     if (!Array.isArray(ids)) {
       return Promise.reject('The argument was not Array.');
     }
 
-    return new Promise(function(resolve, reject) {
+    return new Promise(((resolve, reject) => {
       Revision
-        .find({ _id: { $in: ids }})
-        .sort({createdAt: -1})
+        .find({ _id: { $in: ids } })
+        .sort({ createdAt: -1 })
         .populate('author', User.USER_PUBLIC_FIELDS)
-        .exec(function(err, revisions) {
+        .exec((err, revisions) => {
           if (err) {
             return reject(err);
           }
 
           return resolve(revisions);
         });
-    });
+    }));
   };
 
   revisionSchema.statics.findRevisionIdList = function(path) {
-    return this.find({path: path})
+    return this.find({ path })
       .select('_id author createdAt hasDiffToPrev')
-      .sort({createdAt: -1})
+      .sort({ createdAt: -1 })
       .exec();
   };
 
   revisionSchema.statics.findRevisionList = function(path, options) {
-    const Revision = this,
-      User = crowi.model('User');
+    const Revision = this;
+
+
+    const User = crowi.model('User');
 
-    return new Promise(function(resolve, reject) {
-      Revision.find({path: path})
-        .sort({createdAt: -1})
+    return new Promise(((resolve, reject) => {
+      Revision.find({ path })
+        .sort({ createdAt: -1 })
         .populate('author', User.USER_PUBLIC_FIELDS)
-        .exec(function(err, data) {
+        .exec((err, data) => {
           if (err) {
             return reject(err);
           }
 
           return resolve(data);
         });
-    });
+    }));
   };
 
   revisionSchema.statics.updateRevisionListByPath = function(path, updateData, options) {
     const Revision = this;
 
-    return new Promise(function(resolve, reject) {
-      Revision.update({path: path}, {$set: updateData}, {multi: true}, function(err, data) {
+    return new Promise(((resolve, reject) => {
+      Revision.update({ path }, { $set: updateData }, { multi: true }, (err, data) => {
         if (err) {
           return reject(err);
         }
 
         return resolve(data);
       });
-    });
+    }));
   };
 
   revisionSchema.statics.prepareRevision = function(pageData, body, previousBody, user, options) {
@@ -121,15 +131,15 @@ module.exports = function(crowi) {
   revisionSchema.statics.removeRevisionsByPath = function(path) {
     const Revision = this;
 
-    return new Promise(function(resolve, reject) {
-      Revision.remove({path: path}, function(err, data) {
+    return new Promise(((resolve, reject) => {
+      Revision.remove({ path }, (err, data) => {
         if (err) {
           return reject(err);
         }
 
         return resolve(data);
       });
-    });
+    }));
   };
 
   return mongoose.model('Revision', revisionSchema);

+ 4 - 3
src/server/models/tag.js

@@ -1,3 +1,6 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 const mongoose = require('mongoose');
 const mongoosePaginate = require('mongoose-paginate');
 
@@ -7,7 +10,7 @@ const mongoosePaginate = require('mongoose-paginate');
 const schema = new mongoose.Schema({
   name: {
     type: String,
-    required: true
+    required: true,
   },
 });
 schema.plugin(mongoosePaginate);
@@ -18,11 +21,9 @@ schema.plugin(mongoosePaginate);
  * @class Tag
  */
 class Tag {
-
   async findOrCreate(tagName) {
 
   }
-
 }
 
 module.exports = function() {

+ 46 - 42
src/server/models/updatePost.js

@@ -1,12 +1,15 @@
+// disable no-return-await for model functions
+/* eslint-disable no-return-await */
+
 /**
  * This is the setting for notify to 3rd party tool (like Slack).
  */
 module.exports = function(crowi) {
-  var debug = require('debug')('growi:models:updatePost')
-    , mongoose = require('mongoose')
-    , ObjectId = mongoose.Schema.Types.ObjectId
-    , updatePostSchema
-  ;
+  const debug = require('debug')('growi:models:updatePost');
+  const mongoose = require('mongoose');
+  const ObjectId = mongoose.Schema.Types.ObjectId;
+
+  let updatePostSchema;
 
   // TODO: slack 以外の対応
   updatePostSchema = new mongoose.Schema({
@@ -15,8 +18,8 @@ module.exports = function(crowi) {
     patternPrefix2: { type: String, required: true },
     channel: { type: String, required: true },
     provider: { type: String, required: true },
-    creator: { type: ObjectId, ref: 'User', index: true  },
-    createdAt: { type: Date, default: Date.now }
+    creator: { type: ObjectId, ref: 'User', index: true },
+    createdAt: { type: Date, default: Date.now },
   });
 
   updatePostSchema.statics.normalizeChannelName = function(channel) {
@@ -24,14 +27,14 @@ module.exports = function(crowi) {
   };
 
   updatePostSchema.statics.createPrefixesByPathPattern = function(pathPattern) {
-    var patternPrefix = ['*', '*'];
+    const patternPrefix = ['*', '*'];
 
     // not begin with slash
     if (!pathPattern.match(/^\/.+/)) {
       return patternPrefix;
     }
 
-    var pattern = pathPattern.split('/');
+    const pattern = pathPattern.split('/');
     pattern.shift();
     if (pattern[0] && pattern[0] != '*') {
       patternPrefix[0] = pattern[0];
@@ -44,11 +47,11 @@ module.exports = function(crowi) {
   };
 
   updatePostSchema.statics.getRegExpByPattern = function(pattern) {
-    var reg = pattern;
+    let reg = pattern;
     if (!reg.match(/^\/.*/)) {
-      reg = '/*' + reg + '*';
+      reg = `/*${reg}*`;
     }
-    reg = '^' + reg;
+    reg = `^${reg}`;
     reg = reg.replace(/\//g, '\\/');
     reg = reg.replace(/(\*)/g, '.*');
 
@@ -56,40 +59,42 @@ module.exports = function(crowi) {
   };
 
   updatePostSchema.statics.findSettingsByPath = function(path) {
-    var UpdatePost = this;
-    var prefixes = UpdatePost.createPrefixesByPathPattern(path);
-
-    return new Promise(function(resolve, reject) {
-      UpdatePost.find({$or: [
-        {patternPrefix: prefixes[0], patternPrefix2: prefixes[1]},
-        {patternPrefix: '*', patternPrefix2: '*'},
-        {patternPrefix: prefixes[0], patternPrefix2: '*'},
-        {patternPrefix: '*', patternPrefix2: prefixes[1]},
-      ]}).then(function(settings) {
+    const UpdatePost = this;
+    const prefixes = UpdatePost.createPrefixesByPathPattern(path);
+
+    return new Promise(((resolve, reject) => {
+      UpdatePost.find({
+        $or: [
+          { patternPrefix: prefixes[0], patternPrefix2: prefixes[1] },
+          { patternPrefix: '*', patternPrefix2: '*' },
+          { patternPrefix: prefixes[0], patternPrefix2: '*' },
+          { patternPrefix: '*', patternPrefix2: prefixes[1] },
+        ],
+      }).then((settings) => {
         if (settings.length <= 0) {
           return resolve(settings);
         }
 
-        settings = settings.filter(function(setting) {
-          var patternRegex = UpdatePost.getRegExpByPattern(setting.pathPattern);
+        settings = settings.filter((setting) => {
+          const patternRegex = UpdatePost.getRegExpByPattern(setting.pathPattern);
           return patternRegex.test(path);
         });
 
         return resolve(settings);
       });
-    });
+    }));
   };
 
   updatePostSchema.statics.findAll = function(offset) {
-    var UpdatePost = this;
+    const UpdatePost = this;
     var offset = offset || 0;
 
-    return new Promise(function(resolve, reject) {
+    return new Promise(((resolve, reject) => {
       UpdatePost
         .find()
-        .sort({'createdAt': 1})
+        .sort({ createdAt: 1 })
         .populate('creator')
-        .exec(function(err, data) {
+        .exec((err, data) => {
           if (err) {
             return reject(err);
           }
@@ -100,15 +105,15 @@ module.exports = function(crowi) {
 
           return resolve(data);
         });
-    });
+    }));
   };
 
   updatePostSchema.statics.create = function(pathPattern, channel, user) {
-    var UpdatePost = this;
-    var provider = 'slack'; // now slack only
+    const UpdatePost = this;
+    const provider = 'slack'; // now slack only
 
-    var prefixes = UpdatePost.createPrefixesByPathPattern(pathPattern);
-    var notif = new UpdatePost;
+    const prefixes = UpdatePost.createPrefixesByPathPattern(pathPattern);
+    const notif = new UpdatePost();
     notif.pathPattern = pathPattern;
     notif.patternPrefix = prefixes[0];
     notif.patternPrefix2 = prefixes[1];
@@ -117,22 +122,22 @@ module.exports = function(crowi) {
     notif.creator = user;
     notif.createdAt = Date.now();
 
-    return new Promise(function(resolve, reject) {
-      notif.save(function(err, doc) {
+    return new Promise(((resolve, reject) => {
+      notif.save((err, doc) => {
         if (err) {
           return reject(err);
         }
 
         return resolve(doc);
       });
-    });
+    }));
   };
 
   updatePostSchema.statics.remove = function(id) {
-    var UpdatePost = this;
+    const UpdatePost = this;
 
-    return new Promise(function(resolve, reject) {
-      UpdatePost.findOneAndRemove({_id: id}, function(err, data) {
+    return new Promise(((resolve, reject) => {
+      UpdatePost.findOneAndRemove({ _id: id }, (err, data) => {
         if (err) {
           debug('UpdatePost.findOneAndRemove failed', err);
           return reject(err);
@@ -140,9 +145,8 @@ module.exports = function(crowi) {
 
         return resolve(data);
       });
-    });
+    }));
   };
 
   return mongoose.model('UpdatePost', updatePostSchema);
 };
-