Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linting dependencies and fix lint errors #887

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
18 changes: 14 additions & 4 deletions packages/ember-cli-fastboot/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ module.exports = {
'plugin:prettier/recommended',
],
env: {
browser: true
browser: true,
},
rules: {
'ember/no-classic-classes': 'warn',
'ember/no-get': 'warn',
'ember/require-computed-property-dependencies': 'warn'
'ember/require-computed-property-dependencies': 'warn',
},
rules: {},
overrides: [
// node files
{
Expand All @@ -37,7 +37,11 @@ module.exports = {
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js',
'lib/**/*.js'
'lib/**/*.js',
'test/*.js',
'test/**/ember-cli-build.js',
'test/**/config/**/*.js',
'test/**/lib/**/*.js',
],
excludedFiles: [
'app/**',
Expand All @@ -56,5 +60,11 @@ module.exports = {
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// mocha test files
files: ['test/*-test.{js,ts}'],
plugins: ['mocha'],
extends: ['plugin:mocha/recommended'],
},
],
};
2 changes: 1 addition & 1 deletion packages/ember-cli-fastboot/.template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'octane',
extends: 'recommended',
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function clearHtml() {
if (current && endMarker) {
let shoeboxNodes = document.querySelectorAll('[type="fastboot/shoebox"]');
let shoeboxNodesArray = []; // Note that IE11 doesn't support more concise options like Array.from, so we have to do something like this
for(let i=0; i < shoeboxNodes.length; i++){
for (let i = 0; i < shoeboxNodes.length; i++) {
shoeboxNodesArray.push(shoeboxNodes[i]);
}
let parent = current.parentElement;
Expand All @@ -22,21 +22,25 @@ export function clearHtml() {
nextNode = current.nextSibling;
parent.removeChild(current);
current = nextNode;
} while (nextNode && nextNode !== endMarker && shoeboxNodesArray.indexOf(nextNode) < 0);
} while (
nextNode &&
nextNode !== endMarker &&
shoeboxNodesArray.indexOf(nextNode) < 0
);
endMarker.parentElement.removeChild(endMarker);
}
}
export default {
name: "clear-double-boot",
name: 'clear-double-boot',

initialize(instance) {
if (typeof FastBoot === 'undefined') {
var originalDidCreateRootView = instance.didCreateRootView;

instance.didCreateRootView = function() {
instance.didCreateRootView = function () {
clearHtml();
originalDidCreateRootView.apply(instance, arguments);
};
}
}
}
},
};
20 changes: 11 additions & 9 deletions packages/ember-cli-fastboot/addon/locations/none.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { computed, get } from '@ember/object';
import { bool, readOnly } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { getOwner } from '@ember/application'
import NoneLocation from '@ember/routing/none-location'
import { getOwner } from '@ember/application';
import NoneLocation from '@ember/routing/none-location';

const TEMPORARY_REDIRECT_CODE = 307;

Expand All @@ -16,17 +16,19 @@ export default NoneLocation.extend({

_fastbootHeadersEnabled: bool('_config.fastboot.fastbootHeaders'),

_redirectCode: computed(function () {
return get(this, '_config.fastboot.redirectCode') || TEMPORARY_REDIRECT_CODE;
_redirectCode: computed('_config.fastboot.redirectCode', function () {
return (
get(this, '_config.fastboot.redirectCode') || TEMPORARY_REDIRECT_CODE
);
}),

_response: readOnly('fastboot.response'),
_request: readOnly('fastboot.request'),

setURL(path) {
if (get(this, 'fastboot.isFastBoot')) {
let response = get(this, '_response');
let currentPath = get(this, 'path');
let response = this._response;
let currentPath = this.path;
let isInitialPath = !currentPath || currentPath.length === 0;

if (!isInitialPath) {
Expand All @@ -37,17 +39,17 @@ export default NoneLocation.extend({
let host = get(this, '_request.host');
let redirectURL = `//${host}${path}`;

response.statusCode = this.get('_redirectCode');
response.statusCode = this._redirectCode;
response.headers.set('location', redirectURL);
}
}

// for testing and debugging
if (get(this, '_fastbootHeadersEnabled')) {
if (this._fastbootHeadersEnabled) {
response.headers.set('x-fastboot-path', path);
}
}

this._super(...arguments);
}
},
});
56 changes: 38 additions & 18 deletions packages/ember-cli-fastboot/addon/services/fastboot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global FastBoot */
import { set } from '@ember/object';
import { getOwner } from '@ember/application';
import { computed, get } from '@ember/object';
import { readOnly } from '@ember/object/computed';
Expand All @@ -20,58 +21,72 @@ const RequestObject = EObject.extend({
this.queryParams = request.queryParams;
this.path = request.path;
this.protocol = request.protocol;
this._host = function() {
this._host = function () {
return request.host();
};
},

host: computed(function() {
host: computed(function () {
return this._host();
})
}),
});

const Shoebox = EObject.extend({
put(key, value) {
assert('shoebox.put is only invoked from the FastBoot rendered application', this.get('fastboot.isFastBoot'));
assert(
'shoebox.put is only invoked from the FastBoot rendered application',
this.get('fastboot.isFastBoot')
);
assert('the provided key is a string', typeof key === 'string');

let fastbootInfo = this.get('fastboot._fastbootInfo');
if (!fastbootInfo.shoebox) { fastbootInfo.shoebox = {}; }
if (!fastbootInfo.shoebox) {
fastbootInfo.shoebox = {};
}

fastbootInfo.shoebox[key] = value;
},

retrieve(key) {
if (this.get('fastboot.isFastBoot')) {
let shoebox = this.get('fastboot._fastbootInfo.shoebox');
if (!shoebox) { return; }
if (!shoebox) {
return;
}

return shoebox[key];
}

let shoeboxItem = this.get(key);
if (shoeboxItem) { return shoeboxItem; }
if (shoeboxItem) {
return shoeboxItem;
}

let el = document.querySelector(`#shoebox-${key}`);
if (!el) { return; }
if (!el) {
return;
}
let valueString = el.textContent;
if (!valueString) { return; }
if (!valueString) {
return;
}

shoeboxItem = JSON.parse(valueString);
this.set(key, shoeboxItem);

return shoeboxItem;
}
},
});

const FastBootService = Service.extend({
isFastBoot: typeof FastBoot !== 'undefined',

isFastboot: computed(function() {
isFastboot: computed(function () {
assert(
'The fastboot service does not have an `isFastboot` property. This is likely a typo. Please use `isFastBoot` instead.',
false
);
return;
}),

init() {
Expand All @@ -84,13 +99,15 @@ const FastBootService = Service.extend({
response: readOnly('_fastbootInfo.response'),
metadata: readOnly('_fastbootInfo.metadata'),

request: computed(function() {
request: computed('_fastbootInfo.request', 'isFastBoot', function () {
if (!this.isFastBoot) return null;
return RequestObject.create({ request: get(this, '_fastbootInfo.request') });
return RequestObject.create({
request: get(this, '_fastbootInfo.request'),
});
}),

// this getter/setter pair is to avoid deprecation from [RFC - 680](https://github.com/emberjs/rfcs/pull/680)
_fastbootInfo: computed({
_fastbootInfo: computed('__fastbootInfo', {
get() {
if (this.__fastbootInfo) {
return this.__fastbootInfo;
Expand All @@ -99,15 +116,18 @@ const FastBootService = Service.extend({
return getOwner(this).lookup('info:-fastboot');
},
set(_key, value) {
this.__fastbootInfo = value;
set(this, '__fastbootInfo', value);
return value;
}
},
}),

deferRendering(promise) {
assert('deferRendering requires a promise or thennable object', typeof promise.then === 'function');
assert(
'deferRendering requires a promise or thennable object',
typeof promise.then === 'function'
);
this._fastbootInfo.deferRendering(promise);
}
},
});

export default FastBootService;
26 changes: 17 additions & 9 deletions packages/ember-cli-fastboot/blueprints/ember-cli-fastboot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ module.exports = {
},

afterInstall() {
let targetsFile = './config/targets.js'
let targetsFile = './config/targets.js';

if(this.project.isEmberCLIAddon()) {
if (this.project.isEmberCLIAddon()) {
targetsFile = './tests/dummy/config/targets.js';
}

const targetsAst = recast.parse(readFileSync(targetsFile));

recast.visit(targetsAst, {
visitAssignmentExpression (path) {
visitAssignmentExpression(path) {
let node = path.node;

if (node.left.object.name === 'module' && node.left.property.name === 'exports') {
let nodeProperty = node.right.properties.find(property => property.key.name === 'node');
if (
node.left.object.name === 'module' &&
node.left.property.name === 'exports'
) {
let nodeProperty = node.right.properties.find(
(property) => property.key.name === 'node'
);

if(!nodeProperty) {
if (!nodeProperty) {
let builders = recast.types.builders;
nodeProperty = builders.property(
'init',
Expand All @@ -36,9 +41,12 @@ module.exports = {
}

this.traverse(path);
}
},
});

writeFileSync(targetsFile, recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code);
}
writeFileSync(
targetsFile,
recast.print(targetsAst, { tabWidth: 2, quote: 'single' }).code
);
},
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*globals Ember, URL*/
/* globals Ember */
export default {
name: "dom-helper-patches",
name: 'dom-helper-patches',

initialize: function(App) {
initialize: function () {
// TODO: remove me
Ember.HTMLBars.DOMHelper.prototype.protocolForURL = function(url) {
Ember.HTMLBars.DOMHelper.prototype.protocolForURL = function (url) {
var protocol = URL.parse(url).protocol;
return (protocol == null) ? ':' : protocol;
return protocol == null ? ':' : protocol;
};

// TODO: remove me https://github.com/tildeio/htmlbars/pull/425
Ember.HTMLBars.DOMHelper.prototype.parseHTML = function(html) {
Ember.HTMLBars.DOMHelper.prototype.parseHTML = function (html) {
return this.document.createRawHTMLSection(html);
};
}
},
};
Loading