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

Add prettier to linting configuration #154

Merged
merged 2 commits into from
Oct 1, 2019
Merged
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
31 changes: 11 additions & 20 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
sourceType: 'module',
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
plugins: ['ember', 'prettier'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:prettier/recommended'],
env: {
browser: true,
embertest: true,
},
rules: {
'ember/no-new-mixins': 'off',
},
overrides: [
// node files
Expand All @@ -28,26 +24,21 @@ module.exports = {
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
'tests/dummy/config/**/*.js',
],
excludedFiles: ['addon/**', 'addon-test-support/**', 'app/**', 'tests/dummy/app/**'],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
ecmaVersion: 2015,
},
env: {
browser: false,
node: true
node: true,
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
}),
},
],
};
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 100
}
2 changes: 1 addition & 1 deletion .template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
extends: 'recommended',
};
36 changes: 20 additions & 16 deletions addon/-private/diff-route-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export let createPrefetchChangeSet;

if (gte('3.6.0')) {
// remove guard for Ember 3.8 LTS and rev major
function createList(enumerable) { // eslint-disable-line no-inner-declarations
// eslint-disable-next-line no-inner-declarations
function createList(enumerable) {
let out = [];

if (enumerable === null) return out;
Expand All @@ -24,10 +25,7 @@ if (gte('3.6.0')) {

diffQPs = function(from, to) {
let diff = {};
let params = [
...Object.keys(from.queryParams),
...Object.keys(to.queryParams)
];
let params = [...Object.keys(from.queryParams), ...Object.keys(to.queryParams)];

for (let param of params) {
if (from.queryParams[param] !== to.queryParams[param]) {
Expand All @@ -36,16 +34,17 @@ if (gte('3.6.0')) {
}

return Object.keys(diff);
}
};

shouldRefreshModel = function(routeQueryParams, changedQPs) {
let routeQPKeys = Object.keys(routeQueryParams);
return routeQPKeys.some(key => {
return routeQueryParams[key].refreshModel && changedQPs.indexOf(key) > -1;
});
}
};

function paramsMatch(from, to) { // eslint-disable-line no-inner-declarations
// eslint-disable-next-line no-inner-declarations
function paramsMatch(from, to) {
return to.paramNames.every((paramName, i) => {
return from.paramNames[i] === paramName && from.params[paramName] === to.params[paramName];
});
Expand All @@ -64,7 +63,7 @@ if (gte('3.6.0')) {
}

return [mismatch, pivotIndex];
}
};

paramsDiffer = function(from, to) {
let pivotIndex = -1;
Expand All @@ -85,9 +84,10 @@ if (gte('3.6.0')) {
}

return [mismatch, pivotIndex];
}
};

function qpsDiffer(privateRouter, to, transition) { // eslint-disable-line no-inner-declarations
// eslint-disable-next-line no-inner-declarations
function qpsDiffer(privateRouter, to, transition) {
let routes = getPrefetched(privateRouter, to);
if (transition.from === null) {
return { shouldCall: true, for: routes };
Expand All @@ -98,7 +98,7 @@ if (gte('3.6.0')) {
if (diff.length > 0) {
let prefetchRoutes = [];

routes.forEach((info) => {
routes.forEach(info => {
let { route } = info;
if (shouldRefreshModel(route.queryParams, diff)) {
prefetchRoutes.push(info);
Expand All @@ -111,13 +111,17 @@ if (gte('3.6.0')) {
return { shouldCall: false, for: [] };
}

function getPrefetched(privateRouter, to) { // eslint-disable-line no-inner-declarations
// eslint-disable-next-line no-inner-declarations
function getPrefetched(privateRouter, to) {
let routes = [];
for (let i = 0; i < to.length; i++) {
let info = to[i];
let route = privateRouter.getRoute(info.name);
if (route !== undefined && route !== null) {
routes.push({ route, fullParams: assign({}, info.params, { queryParams: info.queryParams }) });
routes.push({
route,
fullParams: assign({}, info.params, { queryParams: info.queryParams }),
});
}
}

Expand Down Expand Up @@ -154,5 +158,5 @@ if (gte('3.6.0')) {

// Query Params changed
return qpsDiffer(privateRouter, toList, transition);
}
}
};
}
2 changes: 1 addition & 1 deletion addon/initializers/prefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function initialize() {

export default {
name: 'prefetch',
initialize: initialize
initialize: initialize,
};
11 changes: 8 additions & 3 deletions addon/initializers/redirect-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { lte } from 'ember-compatibility-helpers';
let hasInitialized = false;

export function initialize() {
if (lte('3.5.1')) { // Delete all of this in the Ember 3.8 LTS and rev major
if (lte('3.5.1')) {
// Delete all of this in the Ember 3.8 LTS and rev major
if (!hasInitialized) {
hasInitialized = true;

Expand Down Expand Up @@ -43,7 +44,11 @@ export function initialize() {
// `willTransition` hook uses `Ember.run.once` to fire the event, which
// gurantees that it will not trigger `willTransition` multiple times.
if (stack.length === 1 && transition) {
emberRouter.willTransition(latest.oldInfos, transition.state.handlerInfos, latest.transition);
emberRouter.willTransition(
latest.oldInfos,
transition.state.handlerInfos,
latest.transition
);
latest = null;
}

Expand All @@ -59,5 +64,5 @@ export function initialize() {

export default {
name: 'redirect-patch',
initialize: initialize
initialize: initialize,
};
24 changes: 15 additions & 9 deletions addon/instance-initializers/prefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function initialize(instance) {
} else {
// Delete all of this in the Ember 3.8 LTS and rev major
const ROUTER_NAME = 'router:main';
const router =instance.lookup(ROUTER_NAME);
const router = instance.lookup(ROUTER_NAME);

router.on('willTransition', function(transition) {
if (!transition.handlerInfos) {
Expand All @@ -25,7 +25,10 @@ export function initialize(instance) {
let handlerPromiseChain = resolve();
transition.handlerInfos.forEach(function(handlerInfo) {
// Bail if we're tearing down
if ((handlerInfo.handler && handlerInfo.handler.isDestroying === true) || router.isDestroying === true) {
if (
(handlerInfo.handler && handlerInfo.handler.isDestroying === true) ||
router.isDestroying === true
) {
return;
}

Expand Down Expand Up @@ -53,27 +56,30 @@ export function initialize(instance) {

// Run the prefetch hook if the route has one.
if (!handlerInfo.handler && handlerInfo.handlerPromise) {
handlerPromiseChain = handlerPromiseChain.then(() => (
handlerInfo.handlerPromise.then((handler) => {
handlerPromiseChain = handlerPromiseChain.then(() =>
handlerInfo.handlerPromise.then(handler => {
if (handler.isDestroying === true) {
return;
}
handler._prefetched = runHook('prefetch', handlerInfo, transition, [fullParams]);
})
));
);
} else {
handlerInfo.handler._prefetched = runHook('prefetch', handlerInfo, transition, [fullParams]);
handlerInfo.handler._prefetched = runHook('prefetch', handlerInfo, transition, [
fullParams,
]);
}
});
});

function runHook(hookName, handlerInfo, transition, args) { // eslint-disable-line no-inner-declarations
// eslint-disable-next-line no-inner-declarations
function runHook(hookName, handlerInfo, transition, args) {
/*
`runSharedModelHook` was deleted as part of an internal cleanup
and is now moved to a function much like this one. This detects
if the `runSharedModelHook` exists or not.
*/
if (handlerInfo.runSharedModelHook === undefined) {
if (handlerInfo.runSharedModelHook === undefined) {
// This branch will be taken if the version of router_js is >= 2.0.0.
if (handlerInfo.handler !== undefined && handlerInfo.handler[hookName] !== undefined) {
if (handlerInfo.queryParams !== undefined) {
Expand Down Expand Up @@ -105,5 +111,5 @@ export function initialize(instance) {

export default {
name: 'prefetch',
initialize
initialize,
};
2 changes: 1 addition & 1 deletion addon/mixins/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default Mixin.create({
return _super.call(this, ...arguments);
}

return prefetched.then((value) => {
return prefetched.then(value => {
// If a prefetch hook is not defined, the default model hook is used.
if (value === PREFETCH_NOT_DEFINED) {
return _super.call(this, ...arguments);
Expand Down
14 changes: 7 additions & 7 deletions addon/services/prefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ if (gte('3.6.0')) {
let { route, fullParams } = changeSet.for[i];
if (seenRoutes.has(route)) continue;

route._prefetched = new RSVP.Promise(r => {
return r(route.prefetch(fullParams, transition))
});
seenRoutes.set(route, true);
if (transition.isAborted) return;
route._prefetched = new RSVP.Promise(r => {
return r(route.prefetch(fullParams, transition));
});
seenRoutes.set(route, true);
if (transition.isAborted) return;
}
}
}
Expand All @@ -42,8 +42,8 @@ if (gte('3.6.0')) {
this.router.on('routeDidChange', () => {
seenRoutes = new WeakMap();
});
}
},
});
}

export default PrefetchService;
export default PrefetchService;
Loading