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

+ 21 - 0
.eslintrc.js

@@ -40,10 +40,31 @@ module.exports = {
         ignoreTrailingComments: true
       }
     ],
+    "no-param-reassign": [
+      "error",
+      { "props": false }
+    ],
     "no-plusplus": [
       "error",
       { "allowForLoopAfterthoughts": true }
     ],
+    // Allow only for-of
+    // https://qiita.com/the_red/items/0c826e97b57da6d67621
+    'no-restricted-syntax': [
+      'error',
+      {
+        selector: 'ForInStatement',
+        message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
+      },
+      {
+        selector: 'LabeledStatement',
+        message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
+      },
+      {
+        selector: 'WithStatement',
+        message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
+      },
+    ],
     "prefer-destructuring": 'off',
     // "comma-spacing": [
     //   "error",

+ 1 - 1
package.json

@@ -32,7 +32,7 @@
     "clean:report": "rimraf -- report",
     "clean": "npm-run-all -p clean:*",
     "heroku-postbuild": "sh bin/heroku/install-plugins.sh && npm run build:prod",
-    "lint:js:fix": "eslint src/test --fix",
+    "lint:js:fix": "eslint src/migrations --fix",
     "lint:js": "eslint .",
     "lint:styles:fix": "prettier-stylelint --quiet --write src/client/styles/scss/**/*.scss",
     "lint:styles": "stylelint src/client/styles/scss/**/*.scss",

+ 3 - 5
src/migrations/20180926134048-make-email-unique.js

@@ -1,5 +1,3 @@
-'use strict';
-
 require('module-alias/register');
 const logger = require('@alias/logger')('growi:migrate:make-email-unique');
 
@@ -15,13 +13,13 @@ module.exports = {
     const User = require('@server/models/user')();
 
     // get all users who has 'deleted@deleted' email
-    const users = await User.find({email: 'deleted@deleted'});
+    const users = await User.find({ email: 'deleted@deleted' });
     if (users.length > 0) {
       logger.info(`${users.length} users found. Replace email...`, users);
     }
 
     // make email unique
-    const promises = users.map(user => {
+    const promises = users.map((user) => {
       const now = new Date();
       const deletedLabel = `deleted_at_${now.getTime()}`;
       user.email = `${deletedLabel}@deleted`;
@@ -42,6 +40,6 @@ module.exports = {
   down(db, next) {
     // do not rollback
     next();
-  }
+  },
 
 };

+ 7 - 7
src/migrations/20180927102719-init-serverurl.js

@@ -1,4 +1,4 @@
-'use strict';
+
 
 require('module-alias/register');
 const logger = require('@alias/logger')('growi:migrate:init-serverurl');
@@ -18,7 +18,7 @@ function isAllValuesSame(array) {
 
 module.exports = {
 
-  async up(db) {
+  async up(db) { // eslint-disable-line no-unused-vars
     logger.info('Apply migration');
     mongoose.connect(config.mongoUri, config.mongodb.options);
 
@@ -43,7 +43,7 @@ module.exports = {
         { key: 'security:passport-google:callbackUrl' },
         { key: 'security:passport-twitter:callbackUrl' },
         { key: 'security:passport-saml:callbackUrl' },
-      ]
+      ],
     });
 
     // determine serverUrl
@@ -53,11 +53,11 @@ module.exports = {
       logger.info(configs);
 
       // extract domain
-      const siteUrls = configs.map(config => {
+      const siteUrls = configs.map((config) => { // eslint-disable-line no-shadow
         // see https://regex101.com/r/Q0Isjo/2
         const match = config.value.match(/^"(https?:\/\/[^/]+).*"$/);
         return (match != null) ? match[1] : null;
-      }).filter(value => value != null);
+      }).filter((value) => { return value != null });
 
       // determine serverUrl if all values are same
       if (siteUrls.length > 0 && isAllValuesSame(siteUrls)) {
@@ -71,7 +71,7 @@ module.exports = {
     }
   },
 
-  async down(db) {
+  async down(db) { // eslint-disable-line no-unused-vars
     logger.info('Undo migration');
     mongoose.connect(config.mongoUri, config.mongodb.options);
 
@@ -84,6 +84,6 @@ module.exports = {
     });
 
     logger.info('Migration has successfully undoed');
-  }
+  },
 
 };

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

@@ -1,5 +1,3 @@
-'use strict';
-
 require('module-alias/register');
 const logger = require('@alias/logger')('growi:migrate:abolish-page-group-relation');
 
@@ -45,7 +43,8 @@ module.exports = {
     // retrieve all documents from 'pagegrouprelations'
     const relations = await db.collection('pagegrouprelations').find().toArray();
 
-    for (let relation of relations) {
+    /* eslint-disable no-continue, no-await-in-loop */
+    for (const relation of relations) {
       const page = await Page.findOne({ _id: relation.targetPage });
 
       // skip if grant mismatch
@@ -63,6 +62,7 @@ module.exports = {
       page.grantedGroup = userGroup;
       await page.save();
     }
+    /* eslint-enable */
 
     // drop collection
     await db.collection('pagegrouprelations').drop();
@@ -80,7 +80,8 @@ module.exports = {
     // retrieve all Page documents which granted by UserGroup
     const relatedPages = await Page.find({ grant: Page.GRANT_USER_GROUP });
     const insertDocs = [];
-    for (let page of relatedPages) {
+    /* eslint-disable no-continue, no-await-in-loop */
+    for (const page of relatedPages) {
       if (page.grantedGroup == null) {
         continue;
       }
@@ -94,8 +95,8 @@ module.exports = {
 
       // create a new document for 'pagegrouprelations' collection that is managed by mongoose
       insertDocs.push({
-        targetPage: page._id,
-        relatedGroup: userGroup._id,
+        targetPage: page._id, // eslint-disable-line no-underscore-dangle
+        relatedGroup: userGroup._id, // eslint-disable-line no-underscore-dangle
         __v: 0,
       });
 
@@ -103,10 +104,11 @@ module.exports = {
       page.grantedGroup = undefined;
       await page.save();
     }
+    /* eslint-enable */
 
     await db.collection('pagegrouprelations').insertMany(insertDocs);
 
     logger.info('Migration has successfully undoed');
-  }
+  },
 
 };