Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 committed May 13, 2023
1 parent 89ecb72 commit d727dea
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 244 deletions.
6 changes: 3 additions & 3 deletions packages/fastboot-express-middleware/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function fastbootExpressMiddleware(distPath, options) {

opts = opts || {};

let log = opts.log !== false ? _log : function () {};
let log = opts.log !== false ? _log : function() {};

let fastboot = opts.fastboot;

Expand All @@ -25,7 +25,7 @@ function fastbootExpressMiddleware(distPath, options) {
});
}

return async function (req, res, next) {
return async function(req, res, next) {
let path = req.url;

try {
Expand Down Expand Up @@ -53,7 +53,7 @@ function fastbootExpressMiddleware(distPath, options) {
} else if (result.error) {
res.send(body[0]);
} else {
body.forEach((chunk) => res.write(chunk));
body.forEach(chunk => res.write(chunk));
res.end();
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var path = require('path');

module.exports = function (fixturePath) {
module.exports = function(fixturePath) {
return path.join(__dirname, '../fixtures/', fixturePath);
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestHTTPServer {
});
}

return new Promise((resolve) => {
return new Promise(resolve => {
let port = options.port || 3000;
let host = options.host || 'localhost';

Expand Down
48 changes: 24 additions & 24 deletions packages/fastboot-express-middleware/test/middleware-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ const fastbootMiddleware = require('./../src/index');
const fixture = require('./helpers/fixture-path');
const TestHTTPServer = require('./helpers/test-http-server');

describe('FastBoot', function () {
describe('FastBoot', function() {
let server;

this.timeout(10000);

afterEach(function () {
afterEach(function() {
if (server) {
server.stop();
server = null;
}
});

it('throws an exception if no distPath is provided', function () {
let fn = function () {
it('throws an exception if no distPath is provided', function() {
let fn = function() {
fastbootMiddleware();
};

expect(fn).to.throw(/You must instantiate FastBoot with a distPath option/);
});

it('can provide distPath as the first argument', async function () {
it('can provide distPath as the first argument', async function() {
let middleware = fastbootMiddleware(fixture('basic-app'));
server = new TestHTTPServer(middleware);
await server.start();
Expand All @@ -35,7 +35,7 @@ describe('FastBoot', function () {
expect(html).to.match(/Welcome to Ember/);
});

it('can provide distPath as an option', async function () {
it('can provide distPath as an option', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('basic-app'),
});
Expand All @@ -46,7 +46,7 @@ describe('FastBoot', function () {
expect(html).to.match(/Welcome to Ember/);
});

it('can be provided with a custom FastBoot instance', async function () {
it('can be provided with a custom FastBoot instance', async function() {
let fastboot = new FastBoot({
distPath: fixture('basic-app'),
});
Expand All @@ -62,7 +62,7 @@ describe('FastBoot', function () {
expect(html).to.match(/Welcome to Ember/);
});

it('can reload the FastBoot instance', async function () {
it('can reload the FastBoot instance', async function() {
let fastboot = new FastBoot({
distPath: fixture('basic-app'),
});
Expand All @@ -85,7 +85,7 @@ describe('FastBoot', function () {
expect(html).to.match(/Goodbye from Ember/);
});

it('it appends multivalue headers', async function () {
it('it appends multivalue headers', async function() {
let middleware = fastbootMiddleware(fixture('multivalue-headers'));
server = new TestHTTPServer(middleware);
await server.start();
Expand All @@ -94,7 +94,7 @@ describe('FastBoot', function () {
expect(headers['x-fastboot']).to.eq('a, b, c');
});

it('can pass metadata info to the app', async function () {
it('can pass metadata info to the app', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('app-with-metadata'),
visitOptions: {
Expand All @@ -111,7 +111,7 @@ describe('FastBoot', function () {
// FIXME:
// TODO:
// https://github.com/ember-fastboot/ember-cli-fastboot/pull/840#issuecomment-894329631
xit('works without metadata passed', async function () {
it('works without metadata passed', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('app-with-metadata'),
});
Expand All @@ -123,10 +123,10 @@ describe('FastBoot', function () {
});

/* eslint-disable mocha/no-setup-in-describe */
[true, false].forEach((chunkedResponse) => {
describe(`when chunked response is ${chunkedResponse ? 'enabled' : 'disabled'}`, function () {
[true, false].forEach(chunkedResponse => {
describe(`when chunked response is ${chunkedResponse ? 'enabled' : 'disabled'}`, function() {
if (chunkedResponse) {
it('responds with a chunked response', async function () {
it('responds with a chunked response', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('basic-app'),
chunkedResponse,
Expand All @@ -140,7 +140,7 @@ describe('FastBoot', function () {
});
}

it("returns 404 when navigating to a URL that doesn't exist", async function () {
it("returns 404 when navigating to a URL that doesn't exist", async function() {
let middleware = fastbootMiddleware({
distPath: fixture('basic-app'),
chunkedResponse,
Expand All @@ -155,7 +155,7 @@ describe('FastBoot', function () {
}
});

it('returns a 500 error if an error occurs', async function () {
it('returns a 500 error if an error occurs', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
chunkedResponse,
Expand All @@ -170,8 +170,8 @@ describe('FastBoot', function () {
}
});

describe('when resilient mode is enabled', function () {
it('renders no FastBoot markup', async function () {
describe('when resilient mode is enabled', function() {
it('renders no FastBoot markup', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
resilient: true,
Expand All @@ -184,7 +184,7 @@ describe('FastBoot', function () {
expect(html).to.not.match(/error/);
});

it('propagates to error handling middleware', async function () {
it('propagates to error handling middleware', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
resilient: true,
Expand All @@ -201,7 +201,7 @@ describe('FastBoot', function () {
expect(body).to.match(/hello world/);
});

it('is does not propagate errors when and there is no error handling middleware', async function () {
it('is does not propagate errors when and there is no error handling middleware', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
resilient: true,
Expand All @@ -219,7 +219,7 @@ describe('FastBoot', function () {
expect(body).to.match(/hello world/);
});

it('allows post-fastboot middleware to recover the response when it fails', async function () {
it('allows post-fastboot middleware to recover the response when it fails', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
resilient: true,
Expand All @@ -237,8 +237,8 @@ describe('FastBoot', function () {
});
});

describe('when resilient mode is disabled', function () {
it('propagates to error handling middleware', async function () {
describe('when resilient mode is disabled', function() {
it('propagates to error handling middleware', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
resilient: false,
Expand All @@ -257,7 +257,7 @@ describe('FastBoot', function () {
}
});

it('allows post-fastboot middleware to recover the response when it fails', async function () {
it('allows post-fastboot middleware to recover the response when it fails', async function() {
let middleware = fastbootMiddleware({
distPath: fixture('rejected-promise'),
resilient: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/fastboot/dev/memory-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ session.connect();

let file;
// uses whatever the "current" file is
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
session.on('HeapProfiler.addHeapSnapshotChunk', m => {
fs.writeSync(file, m.params.chunk);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/fastboot/src/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class EmberApp {
debug('files evaluated');

// Retrieve the application factory from within the sandbox
let AppFactory = sandbox.run(function (ctx) {
let AppFactory = sandbox.run(function(ctx) {
return ctx.require('~fastboot/app-factory');
});

Expand Down Expand Up @@ -316,7 +316,7 @@ class EmberApp {
if (destroyAppInstanceInMs > 0) {
// start a timer to destroy the appInstance forcefully in the given ms.
// This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
destroyAppInstanceTimer = setTimeout(function () {
destroyAppInstanceTimer = setTimeout(function() {
if (result._destroy()) {
result.error = new Error(
'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms'
Expand Down Expand Up @@ -418,7 +418,7 @@ const JSON_ESCAPE = {
const JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/g;

function escapeJSONString(string) {
return string.replace(JSON_ESCAPE_REGEXP, function (match) {
return string.replace(JSON_ESCAPE_REGEXP, function(match) {
return JSON_ESCAPE[match];
});
}
Expand All @@ -432,7 +432,7 @@ function registerFastBootInfo(info, instance) {
}

function buildScripts(filePaths) {
return filePaths.filter(Boolean).map((filePath) => {
return filePaths.filter(Boolean).map(filePath => {
let source = fs.readFileSync(filePath, { encoding: 'utf8' });

return new vm.Script(source, { filename: filePath });
Expand Down
2 changes: 1 addition & 1 deletion packages/fastboot/src/fastboot-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FastBootRequest {
}

var host = this.headers.get('host');
var matchFound = this.hostWhitelist.some(function (entry) {
var matchFound = this.hostWhitelist.some(function(entry) {
if (entry[0] === '/' && entry.slice(-1) === '/') {
var regexp = new RegExp(entry.slice(1, -1));
return regexp.test(host);
Expand Down
6 changes: 3 additions & 3 deletions packages/fastboot/src/fastboot-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function loadManifest(distPath, fastbootConfig, schemaVersion) {
}
}

let scripts = manifest.vendorFiles.concat(manifest.appFiles).map(function (file) {
let scripts = manifest.vendorFiles.concat(manifest.appFiles).map(function(file) {
return path.join(distPath, file);
});
let html = fs.readFileSync(path.join(distPath, manifest.htmlFile), 'utf8');
Expand All @@ -149,7 +149,7 @@ function loadManifest(distPath, fastbootConfig, schemaVersion) {
* @param {boolean} isLegacyWhiteList flag to enable legacy behavior
*/
function buildWhitelistedRequire(whitelist, distPath, isLegacyWhitelist) {
whitelist.forEach(function (whitelistedModule) {
whitelist.forEach(function(whitelistedModule) {
debug('module whitelisted; module=%s', whitelistedModule);

if (isLegacyWhitelist) {
Expand All @@ -161,7 +161,7 @@ function buildWhitelistedRequire(whitelist, distPath, isLegacyWhitelist) {
}
});

return function (moduleName) {
return function(moduleName) {
let packageName = getPackageName(moduleName);
let isWhitelisted = whitelist.indexOf(packageName) > -1;

Expand Down
2 changes: 1 addition & 1 deletion packages/fastboot/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FastBoot {
console.warn(
'[DEPRECATION] Instantiating `fastboot` with a `sandboxGlobals` option has been deprecated. Please migrate to specifying `buildSandboxGlobals` instead.'
);
buildSandboxGlobals = (globals) => Object.assign({}, globals, options.sandboxGlobals);
buildSandboxGlobals = globals => Object.assign({}, globals, options.sandboxGlobals);
}

this.buildSandboxGlobals = buildSandboxGlobals;
Expand Down
18 changes: 9 additions & 9 deletions packages/fastboot/src/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Result {
this._body,
this._bodyAttributes,
this._bodyClass
).then((html) => {
).then(html => {
let docParts = html.match(HTML_HEAD_REGEX);
if (!docParts || docParts.length === 1) {
return [html];
Expand All @@ -97,7 +97,7 @@ class Result {
let [plainBody, ...shoeboxes] = body.split(SHOEBOX_TAG_PATTERN);

let chunks = [head, plainBody].concat(
shoeboxes.map((shoebox) => `${SHOEBOX_TAG_PATTERN}${shoebox}`)
shoeboxes.map(shoebox => `${SHOEBOX_TAG_PATTERN}${shoebox}`)
);

return chunks;
Expand Down Expand Up @@ -203,10 +203,10 @@ function extractExtraAttributes(element) {
let klass;
let attributes;
if (element.attributes.length > 0) {
let elementClass = element.attributes.find((attr) => attr.name === 'class');
let elementClass = element.attributes.find(attr => attr.name === 'class');
if (elementClass) {
klass = elementClass;
let otherAttrs = element.attributes.filter((attr) => attr.name !== 'class');
let otherAttrs = element.attributes.filter(attr => attr.name !== 'class');
if (otherAttrs.length > 0) {
attributes = HTMLSerializer.attributes(otherAttrs);
} else {
Expand All @@ -229,9 +229,9 @@ function missingTag(tag) {
}

function addClass(html, regex, newClass) {
return html.replace(regex, function (_, tag, attributes) {
return html.replace(regex, function(_, tag, attributes) {
if (/class="([^"]*)"/i.test(attributes)) {
attributes = attributes.replace(/class="([^"]*)"/i, function (_, klass) {
attributes = attributes.replace(/class="([^"]*)"/i, function(_, klass) {
return `class="${klass} ${newClass}"`;
});
} else {
Expand All @@ -256,7 +256,7 @@ async function insertIntoIndexHTML(
let isBodyReplaced = false;
let isHeadReplaced = false;

html = html.replace(/<!-- EMBER_CLI_FASTBOOT_(HEAD|BODY) -->/g, function (match, tag) {
html = html.replace(/<!-- EMBER_CLI_FASTBOOT_(HEAD|BODY) -->/g, function(match, tag) {
if (tag === 'HEAD' && head && !isHeadReplaced) {
isHeadReplaced = true;
return head;
Expand All @@ -271,7 +271,7 @@ async function insertIntoIndexHTML(
html = addClass(html, /<(html)(.*)>/i, htmlClass.value);
}
if (htmlAttributes) {
html = html.replace(/<html[^>]*/i, function (match) {
html = html.replace(/<html[^>]*/i, function(match) {
return match + ' ' + htmlAttributes;
});
}
Expand All @@ -280,7 +280,7 @@ async function insertIntoIndexHTML(
html = addClass(html, /<(body)(.*)>/i, bodyClass.value);
}
if (bodyAttributes) {
html = html.replace(/<body[^>]*/i, function (match) {
html = html.replace(/<body[^>]*/i, function(match) {
return match + ' ' + bodyAttributes;
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fastboot/src/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ module.exports = class Sandbox {
buildWrappedConsole() {
let wrappedConsole = Object.create(console);

wrappedConsole.error = function (...args) {
wrappedConsole.error = function(...args) {
console.error.apply(
console,
args.map(function (a) {
args.map(function(a) {
return typeof a === 'string' ? chalk.red(a) : a;
})
);
Expand Down
Loading

0 comments on commit d727dea

Please sign in to comment.