Skip to content

Commit

Permalink
#210: Apply linter
Browse files Browse the repository at this point in the history
  • Loading branch information
groenroos committed Aug 1, 2021
1 parent b111ca3 commit a5db189
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/initRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function initRoute(route, view) {
/* Create a handler for incoming requests */
const handler = async (request, response) => {
/* Run a hook, if it exists */
return await this.runHook.call(this, 'get', route, request, response, null, async () => {
return await this.runHook('get', route, request, response, null, async () => {
const html = await this.templating.renderView(view, {}, request);

return html instanceof SaplingError ? new Response(this, request, response, html) : new Response(this, request, response, null, html);
Expand Down
1 change: 1 addition & 0 deletions core/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/* Dependencies */
import yargs from 'yargs';
/* eslint-disable-next-line node/file-extension-in-import */
import { hideBin } from 'yargs/helpers';
import fs from 'fs';
import path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion core/loadHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default async function loadHooks(next) {
/* Listen on */
this.server[method](route, async (request, response) => {
/* Run a hook, if it exists */
return await this.runHook.call(this, method, route, request, response, null, () => {
return await this.runHook(method, route, request, response, null, () => {
return new Response(this, request, response, null);
});
});
Expand Down
8 changes: 4 additions & 4 deletions core/loadRest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SaplingError from '../lib/SaplingError.js';
export default async function loadRest(next) {
/* Direct user creation to a special case endpoint */
this.server.post(/\/data\/users\/?$/, async (request, response) => {
await this.runHook.call(this, 'post', '/api/user/register', request, response);
await this.runHook('post', '/api/user/register', request, response);
});

/* Otherwise, send each type of query to be handled by Storage */
Expand All @@ -27,7 +27,7 @@ export default async function loadRest(next) {
const data = await this.storage.get(request, response);

/* Run hooks, then send data */
await this.runHook.call(this, 'get', request.originalUrl, request, response, data, (app, request, response, data) => {
await this.runHook('get', request.originalUrl, request, response, data, (app, request, response, data) => {
if (data) {
new Response(this, request, response, null, data || []);
} else {
Expand All @@ -40,7 +40,7 @@ export default async function loadRest(next) {
const data = await this.storage.post(request, response);

/* Run hooks, then send data */
await this.runHook.call(this, 'post', request.originalUrl, request, response, data, (app, request, response, data) => {
await this.runHook('post', request.originalUrl, request, response, data, (app, request, response, data) => {
if (data) {
new Response(this, request, response, null, data || []);
} else {
Expand All @@ -53,7 +53,7 @@ export default async function loadRest(next) {
await this.storage.delete(request, response);

/* Run hooks, then send data */
await this.runHook.call(this, 'delete', request.originalUrl, request, response, [], (app, request, response, data) => {
await this.runHook('delete', request.originalUrl, request, response, [], (app, request, response, data) => {
if (data) {
new Response(this, request, response, null, data || []);
} else {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import cluster from 'cluster';
import os from 'os';
import chalk from 'chalk';
import yargs from 'yargs';
/* eslint-disable-next-line node/file-extension-in-import */
import { hideBin } from 'yargs/helpers';
import path from 'path';
import fs from 'fs';
Expand Down
3 changes: 3 additions & 0 deletions lib/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,15 @@ export default class Storage {
const driver = String(this.config.db.driver).toLowerCase();

if (driver === 'memory') {
/* eslint-disable-next-line new-cap */
this.db = new (await import('../drivers/db/Memory.js')).default(this.options);
} else {
try {
/* eslint-disable-next-line new-cap */
this.db = new (await import(`@sapling/db-driver-${driver}`)).default(this.options);
} catch {
try {
/* eslint-disable-next-line new-cap */
this.db = new (await import(driver)).default(this.options);
} catch {
throw new SaplingError(`Cannot find any DB driver for '${driver}'`);
Expand Down
3 changes: 3 additions & 0 deletions lib/Templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ export default class Templating {
const driver = String(this.app.config.render.driver).toLowerCase();

if (driver === 'html') {
/* eslint-disable-next-line new-cap */
this.renderer = new (await import('../drivers/render/Html.js')).default(this.app, this.viewsPath);
} else {
try {
/* eslint-disable-next-line new-cap */
this.renderer = new (await import(`@sapling/render-driver-${driver}`)).default(this.app, this.viewsPath);
} catch {
try {
/* eslint-disable-next-line new-cap */
this.renderer = new (await import(driver)).default(this.app, this.viewsPath);
} catch {
throw new SaplingError(`Cannot find any render driver for '${driver}'`);
Expand Down

0 comments on commit a5db189

Please sign in to comment.