Skip to content

Commit

Permalink
Merge pull request #6 from hepsiburada/eslint-fixes
Browse files Browse the repository at this point in the history
Eslint fixes
  • Loading branch information
yasinatesim authored Jan 16, 2021
2 parents 47b64a9 + e06ed12 commit 65e9754
Show file tree
Hide file tree
Showing 27 changed files with 148 additions and 108 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module.exports = {
'no-use-before-define': 'off',
'no-unused-expressions': 'off',
'no-nested-ternary': 'off',
'no-underscore-dangle': 'off'
'no-underscore-dangle': 'off',
'consistent-return': 'off',
'array-callback-return': 'off'
},
env: {
jest: true,
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'whatwg-fetch';
import Eev from 'eev';

"__V_styles__"
('__V_styles__');

if (!window.HbEventBus) {
window.HbEventBus = new Eev();
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import withBaseComponent from './universal/partials/withBaseComponent';
import { SERVICES } from './universal/utils/constants';

export default {
withBaseComponent,
SERVICES,
};
withBaseComponent,
SERVICES
};
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (cluster.isMaster) {
cluster.fork();
});

if (enablePrometheus){
if (enablePrometheus) {
const aggregatorRegistry = new prom.AggregatorRegistry();
const metricsPort = voltranConfig.port + 1;

Expand Down
13 changes: 9 additions & 4 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import {
import Component from './universal/model/Component';
import logger from './universal/utils/logger';

// eslint-disable-next-line consistent-return
export default async (req, res) => {
const pathParts = xss(req.path).split('/').filter(part => part);
const pathParts = xss(req.path)
.split('/')
.filter(part => part);
const componentPath = `/${pathParts.join('/')}`;

const routeInfo = matchUrlInRouteConfigs(componentPath);
Expand All @@ -26,8 +29,10 @@ export default async (req, res) => {
path: xss(path),
query: JSON.parse(xss(JSON.stringify(req.query))),
cookies: xss(JSON.stringify(req.cookies)),
url: xss(req.url).replace(componentPath, '/').replace('//', '/'),
userAgent: xss(req.headers['user-agent']),
url: xss(req.url)
.replace(componentPath, '/')
.replace('//', '/'),
userAgent: xss(req.headers['user-agent'])
};

const component = new Component(routeInfo.path);
Expand Down Expand Up @@ -62,7 +67,7 @@ export default async (req, res) => {
.labels(componentName, isWithoutHTML(context.query) ? '1' : '0')
.observe(Date.now() - res.locals.startEpoch);
} else {
res.html(Preview([fullHtml].join('\n'), [componentName]));
res.html(Preview([fullHtml].join('\n')));
}
} else {
res.status(HTTP_STATUS_CODES.NOT_FOUND).json({
Expand Down
15 changes: 12 additions & 3 deletions src/renderMultiple.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
import { matchUrlInRouteConfigs } from './universal/core/route/routeUtils';
import Component from './universal/model/Component';
import Renderer from './universal/model/Renderer';
Expand All @@ -20,7 +21,7 @@ function getRenderer(name, query, cookies, url, path, userAgent) {
query,
cookies,
url: urlWithPath,
userAgent,
userAgent
};

if (Component.isExist(componentPath)) {
Expand Down Expand Up @@ -173,7 +174,6 @@ async function getResponses(renderers) {
async function getPreview(responses, requestCount) {
return Preview(
[...Object.keys(responses).map(name => responses[name].fullHtml)].join('\n'),
Object.keys(responses),
`${requestCount} request!`
);
}
Expand All @@ -183,7 +183,16 @@ export default async (req, res) => {
const renderers = req.params.components
.split(',')
.filter((value, index, self) => self.indexOf(value) === index)
.map(name => getRenderer(name, req.query, req.cookies, req.url, `/${req.params.path || ''}`, req.headers['user-agent']))
.map(name =>
getRenderer(
name,
req.query,
req.cookies,
req.url,
`/${req.params.path || ''}`,
req.headers['user-agent']
)
)
.filter(renderer => renderer != null);

if (!renderers.length) {
Expand Down
14 changes: 6 additions & 8 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ import render from './render';
import registerControllers from './api/controllers';
import renderMultiple from './renderMultiple';

import { HTTP_STATUS_CODES } from './universal/utils/constants';
import { HTTP_STATUS_CODES } from './universal/utils/constants';

import voltranConfig from '../voltran.config';

const enablePrometheus = voltranConfig.monitoring.prometheus;
let Prometheus;

if (enablePrometheus) {
Prometheus = require("__V_PROMETHEUS__");
// eslint-disable-next-line global-require
Prometheus = require('__V_PROMETHEUS__');
}

const fragmentManifest = require("__V_DICTIONARY__");
const fragmentManifest = require('__V_DICTIONARY__');

process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at:', p, 'reason:', reason);
Expand Down Expand Up @@ -115,10 +116,7 @@ if (process.env.NODE_ENV === 'production') {
hiddie.use(locals);
hiddie.use(helmet());
hiddie.use(cors);
hiddie.use(
'/',
serveStatic(voltranConfig.distFolder + '/public')
);
hiddie.use('/', serveStatic(`${voltranConfig.distFolder}/public`));
hiddie.use(cookieParser());
hiddie.use(utils);
hiddie.use(handleUrls);
Expand All @@ -140,7 +138,7 @@ export default () => {
compression(),
locals,
helmet(),
serveStatic(voltranConfig.distFolder + '/public'),
serveStatic(`${voltranConfig.distFolder}/public`),
cookieParser(),
utils,
handleUrls,
Expand Down
8 changes: 6 additions & 2 deletions src/tools/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ function run(fn, options) {
const start = new Date();

console.log(
'src/tools/run.js', 'run', `Starting '${task.name}${options ? ` (${options})` : ''}'...`
'src/tools/run.js',
'run',
`Starting '${task.name}${options ? ` (${options})` : ''}'...`
);

return task(options).then(resolution => {
const end = new Date();
const time = end.getTime() - start.getTime();
console.log(
'src/tools/run.js', 'run', `Finished '${task.name}${options ? ` (${options})` : ''}' after ${time} ms`
'src/tools/run.js',
'run',
`Finished '${task.name}${options ? ` (${options})` : ''}' after ${time} ms`
);
return resolution;
});
Expand Down
10 changes: 6 additions & 4 deletions src/tools/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ async function start() {
);

hiddie.use(webpackHotMiddleware(clientCompiler));
hiddie.use(webpackHotServerMiddleware(compiler, {
chunkName: 'server',
serverRendererOptions: { hiddie }
}));
hiddie.use(
webpackHotServerMiddleware(compiler, {
chunkName: 'server',
serverRendererOptions: { hiddie }
})
);

http.createServer(hiddie.run).listen(voltranConfig.port);

Expand Down
12 changes: 6 additions & 6 deletions src/universal/common/network/apiUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Request from '../../model/Request';
import {createCacheManagerInstance} from '../../core/cache/cacheUtils';
import { createCacheManagerInstance } from '../../core/cache/cacheUtils';

function createApiClient(apiManager) {
const cacheManager = createCacheManagerInstance();
Expand All @@ -23,9 +23,9 @@ function createApiClient(apiManager) {
function getPayload(url, method, params, configArgument) {
let payload;
if (configArgument) {
payload = {url, method, params, ...configArgument};
payload = { url, method, params, ...configArgument };
} else {
payload = {url, method, params};
payload = { url, method, params };
}
return payload;
}
Expand All @@ -48,7 +48,7 @@ function createApiClient(apiManager) {
if (cacheResponse && !cacheResponse.isExpired) {
// console.log('Came from cache', cacheSettings.cacheKey);
request = getRequest(method, url, paramsArgument, configArgument, {
cacheResponse: cacheResponse.cacheValue,
cacheResponse: cacheResponse.cacheValue
});
} else {
// console.log('Not exist cache, request sent', cacheSettings.cacheKey);
Expand Down Expand Up @@ -97,9 +97,9 @@ function createApiClient(apiManager) {

options(url, config, cacheSettings) {
return makeRequest('options', url, config, null, cacheSettings);
},
}
};
}

// eslint-disable-next-line import/prefer-default-export
export {createApiClient};
export { createApiClient };
14 changes: 12 additions & 2 deletions src/universal/components/Html.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ function componentClassName(componentName, context) {
return context.query && context.query.id ? `${componentName}_${context.query.id}` : componentName;
}

function Html({ componentName, children, styleTags, initialState, fullWidth, isMobileFragment, context }) {
function Html({
componentName,
children,
styleTags,
initialState,
fullWidth,
isMobileFragment,
context
}) {
return `
<div>
${styleTags}
<script type='text/javascript'>${generateInitialState(initialState, componentName)}</script>
<div
id='${componentName.replace(/['"']+/g, '')}_${initialState.id}'
style="pointer-events: none;"
class="${voltranConfig.prefix}-voltran-body voltran-body ${isMobileFragment ? 'mobile' : ''}${fullWidth ? 'full' : ''} ${componentClassName(componentName, context)}">
class="${voltranConfig.prefix}-voltran-body voltran-body ${
isMobileFragment ? 'mobile' : ''
}${fullWidth ? 'full' : ''} ${componentClassName(componentName, context)}">
${children}
</div>
<div>REPLACE_WITH_LINKS</div>
Expand Down
5 changes: 3 additions & 2 deletions src/universal/components/Preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const appConfig = require('__APP_CONFIG__');

export default (body, componentNames = [], title = null) => {
export default (body, title = null) => {
const additionalTitle = title ? ` - ${title}` : '';

function cr(condition, ok, cancel) {
Expand All @@ -14,7 +14,8 @@ export default (body, componentNames = [], title = null) => {
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>window.HBUS_LAZY = true;</script>
<script src="${appConfig.voltranCommonUrl}"></script>
${cr(appConfig.showPreviewFrame,
${cr(
appConfig.showPreviewFrame,
`<style>
.voltran-body {
color: #484848;
Expand Down
9 changes: 7 additions & 2 deletions src/universal/components/PureHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function generateInitialState(initialState, componentName) {
${include} = {
...(${include} || {}),
'${initialState.id}': {
'STATE': ${JSON.stringify(initialState).replace(new RegExp('</script>', 'g'), '<\\/script>')}
'STATE': ${JSON.stringify(initialState).replace(
new RegExp('</script>', 'g'),
'<\\/script>'
)}
}
}`;
}
Expand All @@ -32,7 +35,9 @@ export default (resultPath, componentName, initialState) => {
return `
<div>
<script type="text/javascript">${generateInitialState(initialState, componentName)}</script>
<div id='${componentName.replace(/['"']+/g, '')}_${initialState.id}' style="pointer-events: none;"></div>
<div id='${componentName.replace(/['"']+/g, '')}_${
initialState.id
}' style="pointer-events: none;"></div>
<div>REPLACE_WITH_LINKS</div>
<div>REPLACE_WITH_SCRIPTS</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/universal/core/api/ClientApiManagerCache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* istanbul ignore file */
const { services, timeouts } = require('__APP_CONFIG__');
import ClientApiManager from './ClientApiManager';
import { SERVICES } from '../../utils/constants';

const { services, timeouts } = require('__APP_CONFIG__');

const cache = {};

Object.entries(services).forEach(entity => {
Expand Down
3 changes: 2 additions & 1 deletion src/universal/core/api/ServerApiManagerCache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* istanbul ignore file */
const { services, timeouts } = require('__APP_CONFIG__');
import ServerApiManager from './ServerApiManager';
import { SERVICES } from '../../utils/constants';

const { services, timeouts } = require('__APP_CONFIG__');

const cache = {};

Object.entries(services).forEach(entity => {
Expand Down
24 changes: 7 additions & 17 deletions src/universal/core/cache/cacheManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,30 @@ class CacheManager {
}

get(options) {
const {
cacheKey,
expireTime,
} = options;
const { cacheKey, expireTime } = options;

const cache = this.store.get(cacheKey);
if (!cache) {
return null;
}

const {
createdDate,
cacheValue,
} = cache;
const { createdDate, cacheValue } = cache;
const cacheCreatedDate = cache && new Date(createdDate);
const cacheExpireDate = new Date(
new Date() - (expireTime || DEFAULT_EXPIRE_TIME),
);
const cacheExpireDate = new Date(new Date() - (expireTime || DEFAULT_EXPIRE_TIME));

return {
createdDate,
cacheValue,
isExpired: cacheExpireDate > cacheCreatedDate,
isExpired: cacheExpireDate > cacheCreatedDate
};
}

put(options, val) {
const {
cacheKey,
} = options;
const { cacheKey } = options;

this.store.set(cacheKey, {
createdDate: new Date(),
cacheValue: val,
cacheValue: val
});
}

Expand All @@ -54,7 +44,7 @@ class CacheManager {
}

delete() {
//no op here because this is standalone, not a part of $cacheFactory
// no op here because this is standalone, not a part of $cacheFactory
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/universal/core/cache/cacheUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ function createCacheManagerInstance() {
return cacheManagerInstance;
}

export {
createCacheManagerInstance,
}
// eslint-disable-next-line import/prefer-default-export
export { createCacheManagerInstance };
2 changes: 0 additions & 2 deletions src/universal/core/route/routesWithComponents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import withBaseComponent from '../../partials/withBaseComponent';

const components = require('__V_COMPONENTS__');

const routesWithComponents = {};
Expand Down
Loading

0 comments on commit 65e9754

Please sign in to comment.