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

+ 18 - 13
src/lib/service/cdn-resources-downloader.js

@@ -26,13 +26,14 @@ class CdnResourcesDownloader {
     const opts = Object.assign({}, options);
     const ext = opts.ext || 'js';
 
-    const promises = cdnResources.map(cdnResource => {
+    const promises = cdnResources.map((cdnResource) => {
       this.logger.info(`Processing CdnResource '${cdnResource.name}'`);
 
       return this.downloadAndWriteToFS(
         cdnResource.url,
         cdnResource.outDir,
-        `${cdnResource.name}.${ext}`);
+        `${cdnResource.name}.${ext}`,
+      );
     });
 
     return Promise.all(promises);
@@ -52,7 +53,7 @@ class CdnResourcesDownloader {
 
     // styles
     const assetsResourcesStore = [];
-    const promisesForStyle = cdnResources.map(cdnResource => {
+    const promisesForStyle = cdnResources.map((cdnResource) => {
       this.logger.info(`Processing CdnResource '${cdnResource.name}'`);
 
       let urlReplacer = null;
@@ -66,7 +67,8 @@ class CdnResourcesDownloader {
         cdnResource.url,
         cdnResource.outDir,
         `${cdnResource.name}.${ext}`,
-        urlReplacer);
+        urlReplacer,
+      );
     });
 
     // wait until all styles are downloaded
@@ -75,13 +77,14 @@ class CdnResourcesDownloader {
     this.logger.debug('Downloading assets', assetsResourcesStore);
 
     // assets in css
-    const promisesForAssets = assetsResourcesStore.map(cdnResource => {
+    const promisesForAssets = assetsResourcesStore.map((cdnResource) => {
       this.logger.info(`Processing assts in css '${cdnResource.name}'`);
 
       return this.downloadAndWriteToFS(
         cdnResource.url,
         cdnResource.outDir,
-        cdnResource.name);
+        cdnResource.name,
+      );
     });
 
     return Promise.all(promisesForAssets);
@@ -100,12 +103,12 @@ class CdnResourcesDownloader {
    */
   generateReplaceUrlInCssStream(cdnResource, assetsResourcesStore, webroot) {
     return replaceStream(
-      /url\((?!['"]?data:)["']?(.+?)["']?\)/g,    // https://regex101.com/r/Sds38A/3
+      /url\((?!['"]?data:)["']?(.+?)["']?\)/g, // https://regex101.com/r/Sds38A/3
       (match, url) => {
         // generate URL Object
         const parsedUrl = url.startsWith('http')
-          ? new URL(url)                    // when url is fqcn
-          : new URL(url, cdnResource.url);  // when url is relative
+          ? new URL(url) // when url is fqcn
+          : new URL(url, cdnResource.url); // when url is relative
         const basename = path.basename(parsedUrl.pathname);
 
         this.logger.debug(`${cdnResource.name} has ${parsedUrl.toString()}`);
@@ -115,15 +118,17 @@ class CdnResourcesDownloader {
           new CdnResource(
             basename,
             parsedUrl.toString(),
-            path.join(cdnResource.outDir, cdnResource.name)
-          )
+            path.join(cdnResource.outDir, cdnResource.name),
+          ),
         );
 
         const replaceUrl = urljoin(webroot, cdnResource.name, basename);
         return `url(${replaceUrl})`;
-      });
+      },
+    );
   }
 
+  /* eslint-disable class-methods-use-this */
   async downloadAndWriteToFS(url, outDir, fileName, replacestream) {
     // get
     const response = await axios.get(url, { responseType: 'stream' });
@@ -140,7 +145,7 @@ class CdnResourcesDownloader {
 
     return streamToPromise(stream);
   }
-
+  /* eslint-enable */
 }
 
 module.exports = CdnResourcesDownloader;

+ 16 - 13
src/lib/service/cdn-resources-service.js

@@ -24,14 +24,14 @@ class CdnResourcesService {
 
   getScriptManifestByName(name) {
     const manifests = this.cdnManifests.js
-      .filter(manifest => manifest.name === name);
+      .filter((manifest) => { return manifest.name === name });
 
     return (manifests.length > 0) ? manifests[0] : null;
   }
 
   getStyleManifestByName(name) {
     const manifests = this.cdnManifests.style
-      .filter(manifest => manifest.name === name);
+      .filter((manifest) => { return manifest.name === name });
 
     return (manifests.length > 0) ? manifests[0] : null;
   }
@@ -46,11 +46,11 @@ class CdnResourcesService {
   async downloadAndWriteAll(cdnResourceDownloader) {
     const CdnResource = require('@commons/models/cdn-resource');
 
-    const cdnScriptResources = this.cdnManifests.js.map(manifest => {
+    const cdnScriptResources = this.cdnManifests.js.map((manifest) => {
       const outDir = helpers.root(cdnLocalScriptRoot);
       return new CdnResource(manifest.name, manifest.url, outDir);
     });
-    const cdnStyleResources = this.cdnManifests.style.map(manifest => {
+    const cdnStyleResources = this.cdnManifests.style.map((manifest) => {
       const outDir = helpers.root(cdnLocalStyleRoot);
       return new CdnResource(manifest.name, manifest.url, outDir);
     });
@@ -58,7 +58,7 @@ class CdnResourcesService {
     const dlStylesOptions = {
       replaceUrl: {
         webroot: cdnLocalStyleWebRoot,
-      }
+      },
     };
 
     return Promise.all([
@@ -73,6 +73,7 @@ class CdnResourcesService {
    * @param {Object} manifest
    * @param {boolean} noCdn
    */
+  /* eslint-disable class-methods-use-this */
   generateScriptTag(manifest, noCdn) {
     const attrs = [];
     const args = manifest.args || {};
@@ -87,10 +88,11 @@ class CdnResourcesService {
     // TODO process integrity
 
     const url = noCdn
-      ? urljoin(cdnLocalScriptWebRoot, manifest.name) + '.js'
+      ? `${urljoin(cdnLocalScriptWebRoot, manifest.name)}.js`
       : manifest.url;
     return `<script src="${url}" ${attrs.join(' ')}></script>`;
   }
+  /* eslint-enable */
 
   getScriptTagByName(name) {
     const manifest = this.getScriptManifestByName(name);
@@ -99,10 +101,10 @@ class CdnResourcesService {
 
   getScriptTagsByGroup(group) {
     return this.cdnManifests.js
-      .filter(manifest => {
+      .filter((manifest) => {
         return manifest.groups != null && manifest.groups.includes(group);
       })
-      .map(manifest => {
+      .map((manifest) => {
         return this.generateScriptTag(manifest, this.noCdn);
       });
   }
@@ -113,6 +115,7 @@ class CdnResourcesService {
    * @param {Object} manifest
    * @param {boolean} noCdn
    */
+  /* eslint-disable class-methods-use-this */
   generateStyleTag(manifest, noCdn) {
     const attrs = [];
     const args = manifest.args || {};
@@ -127,11 +130,12 @@ class CdnResourcesService {
     // TODO process integrity
 
     const url = noCdn
-      ? urljoin(cdnLocalStyleWebRoot, manifest.name) + '.css'
+      ? `${urljoin(cdnLocalStyleWebRoot, manifest.name)}.css`
       : manifest.url;
 
     return `<link rel="stylesheet" href="${url}" ${attrs.join(' ')}>`;
   }
+  /* eslint-enable */
 
   getStyleTagByName(name) {
     const manifest = this.getStyleManifestByName(name);
@@ -140,10 +144,10 @@ class CdnResourcesService {
 
   getStyleTagsByGroup(group) {
     return this.cdnManifests.style
-      .filter(manifest => {
+      .filter((manifest) => {
         return manifest.groups != null && manifest.groups.includes(group);
       })
-      .map(manifest => {
+      .map((manifest) => {
         return this.generateStyleTag(manifest, this.noCdn);
       });
   }
@@ -153,7 +157,7 @@ class CdnResourcesService {
 
     // replace style
     if (!this.noCdn) {
-      const url = new URL(`${styleName}.css`, manifest.url);  // resolve `${styleName}.css` from manifest.url
+      const url = new URL(`${styleName}.css`, manifest.url); // resolve `${styleName}.css` from manifest.url
 
       // clone manifest
       manifest = Object.assign(manifest, { url: url.toString() });
@@ -161,7 +165,6 @@ class CdnResourcesService {
 
     return this.generateStyleTag(manifest, this.noCdn);
   }
-
 }
 
 module.exports = CdnResourcesService;

+ 15 - 15
src/lib/service/interceptor-manager.js

@@ -4,7 +4,6 @@ const logger = require('@alias/logger')('growi:InterceptorManager');
  * the manager class of Interceptor
  */
 class InterceptorManager {
-
   constructor() {
     this.interceptorAndOrders = []; /* [
                                           {interceptor: instanceA, order: 200 },
@@ -31,25 +30,25 @@ class InterceptorManager {
   addInterceptors(interceptors, order) {
     let isDefaultOrder = false;
     if (order == null) {
-      order = 100;
+      order = 100; // eslint-disable-line
       isDefaultOrder = true;
     }
 
-    const interceptorIds = interceptors.map((i) => i.getId());
+    const interceptorIds = interceptors.map((i) => { return i.getId() });
     logger.info(`'addInterceptors' invoked. adding interceptors '${interceptorIds}' at order=${order}${isDefaultOrder ? '(default)' : ''}`);
 
     this.interceptorAndOrders = this.interceptorAndOrders.concat(
-      interceptors.map(interceptor => {
+      interceptors.map((interceptor) => {
         return { interceptor, order };
-      })
+      }),
     );
 
     // sort asc
-    this.interceptorAndOrders.sort((a, b) => a.order - b.order);
+    this.interceptorAndOrders.sort((a, b) => { return a.order - b.order });
     // store sorted list
-    this.interceptors = this.interceptorAndOrders.map(obj => obj.interceptor);
+    this.interceptors = this.interceptorAndOrders.map((obj) => { return obj.interceptor });
 
-    const thisInterceptorIds = this.interceptors.map((i) => i.getId());
+    const thisInterceptorIds = this.interceptors.map((i) => { return i.getId() });
     logger.info(`interceptors list has initialized: ${thisInterceptorIds}`);
   }
 
@@ -63,10 +62,10 @@ class InterceptorManager {
     logger.debug(`processing the context '${contextName}'`);
 
     // filter only contexts matches to specified 'contextName'
-    const matchInterceptors = this.interceptors.filter((i) => i.isInterceptWhen(contextName));
+    const matchInterceptors = this.interceptors.filter((i) => { return i.isInterceptWhen(contextName) });
 
-    const parallels = matchInterceptors.filter((i) => i.isProcessableParallel());
-    const sequentials = matchInterceptors.filter((i) => !i.isProcessableParallel());
+    const parallels = matchInterceptors.filter((i) => { return i.isProcessableParallel() });
+    const sequentials = matchInterceptors.filter((i) => { return !i.isProcessableParallel() });
 
     logger.debug(`${parallels.length} parallel interceptors found.`);
     logger.debug(`${sequentials.length} sequencial interceptors found.`);
@@ -79,15 +78,15 @@ class InterceptorManager {
       // sequential
       .concat([
         sequentials.reduce((prevPromise, nextInterceptor) => {
-          return prevPromise.then((...results) => this.doProcess(nextInterceptor, contextName, ...results));
-        }, Promise.resolve(...args)/* initial Promise */)
-      ])
+          return prevPromise.then((...results) => { return this.doProcess(nextInterceptor, contextName, ...results) });
+        }, Promise.resolve(...args)/* initial Promise */),
+      ]),
     ).then(() => {
       logger.debug(`end processing the context '${contextName}'`);
-      return;
     });
   }
 
+  /* eslint-disable class-methods-use-this */
   doProcess(interceptor, contextName, ...args) {
     return interceptor.process(contextName, ...args)
       .then((...results) => {
@@ -100,6 +99,7 @@ class InterceptorManager {
         return Promise.resolve(...args);
       });
   }
+  /* eslint-enable */
 }
 
 module.exports = InterceptorManager;

+ 11 - 10
src/lib/service/logger/index.js

@@ -1,14 +1,14 @@
-const bunyan = require('bunyan');   // will be replaced to browser-bunyan on browser by webpack
+const bunyan = require('bunyan'); // will be replaced to browser-bunyan on browser by webpack
 const minimatch = require('minimatch');
 
 const isBrowser = typeof window !== 'undefined';
 const isProd = process.env.NODE_ENV === 'production';
 
-let config = require('@root/config').logger;
-let stream = isProd ? require('./stream.prod') : require('./stream.dev');
+const config = require('@root/config').logger;
+const stream = isProd ? require('./stream.prod') : require('./stream.dev');
 
 // logger store
-let loggers = {};
+const loggers = {};
 
 
 // merge configuration from environment variables
@@ -19,11 +19,11 @@ const envLevelMap = {
   TRACE:  'trace',
   ERROR:  'error',
 };
-Object.keys(envLevelMap).forEach(envName => {   // ['INFO', 'DEBUG', ...].forEach
-  const envVars = process.env[envName];         // process.env.DEBUG should have a value like 'growi:routes:page,growi:models.page,...'
+Object.keys(envLevelMap).forEach((envName) => { // ['INFO', 'DEBUG', ...].forEach
+  const envVars = process.env[envName]; // process.env.DEBUG should have a value like 'growi:routes:page,growi:models.page,...'
   if (envVars != null) {
     const level = envLevelMap[envName];
-    envVars.split(',').forEach(ns => {          // ['growi:routes:page', 'growi:models.page', ...].forEach
+    envVars.split(',').forEach((ns) => { // ['growi:routes:page', 'growi:models.page', ...].forEach
       config[ns.trim()] = level;
     });
   }
@@ -36,17 +36,18 @@ Object.keys(envLevelMap).forEach(envName => {   // ['INFO', 'DEBUG', ...].forEac
  */
 function determineLoggerLevel(name) {
   if (isBrowser && isProd) {
-    'error';
+    return 'error';
   }
 
   let level = config.default;
 
+  /* eslint-disable array-callback-return, no-useless-return */
   // retrieve configured level
-  Object.keys(config).some(key => { // breakable forEach
+  Object.keys(config).some((key) => { //  breakable forEach
     // test whether 'name' matches to 'key'(blob)
     if (minimatch(name, key)) {
       level = config[key];
-      return;                       // break if match
+      return; //                          break if match
     }
   });
 

+ 1 - 1
src/lib/service/logger/stream.dev.js

@@ -1,6 +1,6 @@
 const isBrowser = typeof window !== 'undefined';
 
-let stream = undefined;
+let stream;
 
 // browser settings
 if (isBrowser) {

+ 1 - 1
src/lib/service/logger/stream.prod.js

@@ -1,6 +1,6 @@
 const isBrowser = typeof window !== 'undefined';
 
-let stream = undefined;
+let stream;
 
 // browser settings
 if (isBrowser) {

+ 6 - 8
src/lib/service/xss/index.js

@@ -1,25 +1,24 @@
 class Xss {
-
   constructor(xssOption) {
     const xss = require('xss');
 
-    xssOption = xssOption || {};
+    xssOption = xssOption || {}; // eslint-disable-line no-param-reassign
 
     const tagWhiteList = xssOption.tagWhiteList || [];
     const attrWhiteList = xssOption.attrWhiteList || [];
 
-    let whiteListContent = {};
+    const whiteListContent = {};
 
     // default
-    let option = {
+    const option = {
       stripIgnoreTag: true,
-      stripIgnoreTagBody: false,    // see https://github.com/weseek/growi/pull/505
+      stripIgnoreTagBody: false, // see https://github.com/weseek/growi/pull/505
       css: false,
       whiteList: whiteListContent,
-      escapeHtml: (html) => html,   // resolve https://github.com/weseek/growi/issues/221
+      escapeHtml: (html) => { return html }, // resolve https://github.com/weseek/growi/issues/221
     };
 
-    tagWhiteList.forEach(tag => {
+    tagWhiteList.forEach((tag) => {
       whiteListContent[tag] = attrWhiteList;
     });
 
@@ -30,7 +29,6 @@ class Xss {
   process(document) {
     return this.myxss.process(document);
   }
-
 }
 
 module.exports = Xss;

+ 2 - 2
src/lib/service/xss/recommendedXssWhiteList.js

@@ -14,6 +14,6 @@ const tags = [
 const attrs = ['src', 'href', 'class', 'id', 'width', 'height', 'alt', 'title', 'style'];
 
 module.exports = {
-  'tags': tags,
-  'attrs': attrs,
+  tags,
+  attrs,
 };

+ 0 - 2
src/lib/service/xss/xssOption.js

@@ -1,5 +1,4 @@
 class XssOption {
-
   constructor(config) {
     const recommendedXssWhiteList = require('./recommendedXssWhiteList');
     const initializedConfig = (config != null) ? config : {};
@@ -8,6 +7,5 @@ class XssOption {
     this.tagWhiteList = initializedConfig.tagWhiteList || recommendedXssWhiteList.tags;
     this.attrWhiteList = initializedConfig.attrWhiteList || recommendedXssWhiteList.attrs;
   }
-
 }
 module.exports = XssOption;

+ 9 - 10
src/lib/util/path-utils.js

@@ -1,7 +1,14 @@
-'use strict';
+
+function encodePagePath(path) {
+  const paths = path.split('/');
+  paths.forEach((item, index) => {
+    paths[index] = encodeURIComponent(item);
+  });
+  return paths.join('/');
+}
 
 function encodePagesPath(pages) {
-  pages.forEach(function(page) {
+  pages.forEach((page) => {
     if (!page.path) {
       return;
     }
@@ -10,14 +17,6 @@ function encodePagesPath(pages) {
   return pages;
 }
 
-function encodePagePath(path) {
-  const paths = path.split('/');
-  paths.forEach(function(item, index) {
-    paths[index] = encodeURIComponent(item);
-  });
-  return paths.join('/');
-}
-
 function matchSlashes(path) {
   // https://regex101.com/r/Z21fEd/5
   return path.match(/^((\/+)?(.+?))(\/+)?$/);

+ 4 - 4
src/lib/util/template-checker.js

@@ -2,12 +2,12 @@
  * templateChecker
  */
 
-module.exports = function(path) {
-  'use strict';
-
+function checkTemplatePath(path) {
   if (path.match(/.*\/_{1,2}template$/)) {
     return true;
   }
 
   return false;
-};
+}
+
+module.exports = checkTemplatePath;