diff --git a/.eslintrc.js b/.eslintrc.js index ade61fb..4aea94e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,7 +22,16 @@ module.exports = { env: { browser: true, }, - rules: {}, + rules: { + 'ember/no-controller-access-in-routes': 1, + 'ember/no-computed-properties-in-native-classes': 1, + 'ember/no-classic-classes': 1, + 'ember/avoid-leaking-state-in-ember-objects': 1, + 'n/no-missing-require': 1, + 'ember/no-new-mixins': 1, + 'ember/no-arrow-function-computed-properties': 1, + 'ember/no-actions-hash': 1, + }, overrides: [ // node files { @@ -46,11 +55,16 @@ module.exports = { node: true, }, extends: ['plugin:n/recommended'], + rules: {}, }, { // test files files: ['tests/**/*-test.{js,ts}'], extends: ['plugin:qunit/recommended'], + rules: { + 'qunit/no-assert-equal': 1, + 'qunit/require-expect': 1, + }, }, ], }; diff --git a/addon/-private/parachute-event.js b/addon/-private/parachute-event.js index 47cb7f6..603abf0 100644 --- a/addon/-private/parachute-event.js +++ b/addon/-private/parachute-event.js @@ -45,7 +45,7 @@ export default class ParachuteEvent { return changedParams; }, {}, - undefined + undefined, ); /** @@ -57,7 +57,7 @@ export default class ParachuteEvent { * Whether or not a model refresh should occur */ this.shouldRefresh = emberArray(keys(this.changed)).any( - key => queryParams[key].refresh + (key) => queryParams[key].refresh, ); /** diff --git a/addon/-private/parachute-meta.js b/addon/-private/parachute-meta.js index 2d77c79..e88260c 100644 --- a/addon/-private/parachute-meta.js +++ b/addon/-private/parachute-meta.js @@ -24,9 +24,9 @@ export default class ParachuteMeta { }, {}); this.queryParamsArray = emberArray( - keys(this.queryParams).map(key => { + keys(this.queryParams).map((key) => { return this.queryParams[key]; - }) + }), ); this.qpMapForController = this.queryParamsArray.reduce( @@ -34,12 +34,12 @@ export default class ParachuteMeta { qps[key] = { as, scope }; return qps; }, - {} + {}, ); // Meta info used by the decorators Object.defineProperty(this.qpMapForController, PARACHUTE_QPS, { - value: true + value: true, }); this.qpMapForRoute = this.queryParamsArray.reduce( @@ -47,7 +47,7 @@ export default class ParachuteMeta { qps[key] = { replace }; return qps; }, - {} + {}, ); this.defaultValues = this.queryParamsArray.reduce( @@ -55,7 +55,7 @@ export default class ParachuteMeta { defaults[key] = defaultValue; return defaults; }, - {} + {}, ); } } diff --git a/addon/-private/query-param.js b/addon/-private/query-param.js index e35e7b1..7d4e138 100644 --- a/addon/-private/query-param.js +++ b/addon/-private/query-param.js @@ -15,7 +15,7 @@ export default class QueryParam { constructor(key, options = {}) { assert( `[ember-parachute] You must specify a key to the QueryParam Class`, - isPresent(key) + isPresent(key), ); this.key = key; diff --git a/addon/-private/state.js b/addon/-private/state.js index a1a21db..7025e05 100644 --- a/addon/-private/state.js +++ b/addon/-private/state.js @@ -19,12 +19,12 @@ function queryParamsState(queryParamsArray, controller) { serializedValue: qp.serializedValue(controller), as: qp.as, defaultValue: qp.defaultValue, - changed: JSON.stringify(value) !== JSON.stringify(qp.defaultValue) + changed: JSON.stringify(value) !== JSON.stringify(qp.defaultValue), }; return state; }, {}, - undefined + undefined, ); } @@ -39,7 +39,7 @@ function queryParamsState(queryParamsArray, controller) { export default function queryParamsStateFor(controller) { assert( '[ember-parachute] Cannot construct query params state object without a controller', - isPresent(controller) + isPresent(controller), ); let { queryParamsArray } = QueryParams.metaFor(controller); return queryParamsState(queryParamsArray, controller); diff --git a/addon/decorators/-private/query-params-for.js b/addon/decorators/-private/query-params-for.js index d1000e9..2010d0d 100644 --- a/addon/decorators/-private/query-params-for.js +++ b/addon/decorators/-private/query-params-for.js @@ -11,6 +11,6 @@ export function getQueryParamsFor(klass) { export function addQueryParamFor(klass, key, definition) { QP_MAP.set( klass, - getQueryParamsFor(klass).extend({ [key]: definition || {} }) + getQueryParamsFor(klass).extend({ [key]: definition || {} }), ); } diff --git a/addon/decorators/query-param.js b/addon/decorators/query-param.js index ed0db88..0921a11 100644 --- a/addon/decorators/query-param.js +++ b/addon/decorators/query-param.js @@ -2,7 +2,7 @@ import { A } from '@ember/array'; import { PARACHUTE_QPS } from 'ember-parachute/-private/symbols'; import { addQueryParamFor, - getQueryParamsFor + getQueryParamsFor, } from './-private/query-params-for'; function createDescriptor(desc, qpDefinition) { @@ -30,7 +30,7 @@ function createDescriptor(desc, qpDefinition) { } return klass; - } + }, }; if (desc.kind === 'field') { @@ -53,5 +53,5 @@ export default function queryParam(qpDefinition) { } // Handle `@queryParam()` usage - return desc => createDescriptor(desc, qpDefinition); + return (desc) => createDescriptor(desc, qpDefinition); } diff --git a/addon/decorators/with-parachute.js b/addon/decorators/with-parachute.js index 331c122..1cd4031 100644 --- a/addon/decorators/with-parachute.js +++ b/addon/decorators/with-parachute.js @@ -7,6 +7,6 @@ export default function withParachute(desc) { klass.reopen(new QueryParams().Mixin); return klass; - } + }, }; } diff --git a/addon/initializers/ember-parachute.js b/addon/initializers/ember-parachute.js index 0cf3f5c..bc580bf 100644 --- a/addon/initializers/ember-parachute.js +++ b/addon/initializers/ember-parachute.js @@ -88,7 +88,7 @@ export function initialize(/* application */) { // Check if routeInfos have already been loaded. // If so, don't return a promise as it will result in // the loading screen/state flashing. - if (routeInfos.every(x => x.isResolved)) { + if (routeInfos.every((x) => x.isResolved)) { return this._super(params, transition); } @@ -97,20 +97,20 @@ export function initialize(/* application */) { // https://github.com/emberjs/ember.js/issues/15291 const _super = this._super.bind(this); - return RSVP.all(routeInfos.map(x => x.routePromise)).then(() => - _super(params, transition) + return RSVP.all(routeInfos.map((x) => x.routePromise)).then(() => + _super(params, transition), ); } else { const { handlerInfos } = transition; - if (!handlerInfos.find(x => !x.handler)) { + if (!handlerInfos.find((x) => !x.handler)) { return this._super(params, transition); } const _super = this._super.bind(this); - return RSVP.all(handlerInfos.map(x => x.handlerPromise)).then(() => - _super(params, transition) + return RSVP.all(handlerInfos.map((x) => x.handlerPromise)).then(() => + _super(params, transition), ); } }, @@ -190,11 +190,15 @@ export function initialize(/* application */) { */ _setupParachuteQueryParamsMap(controller) { if (!this.__hasSetupParachuteQPs) { - let qpMap = this.get('queryParams'); + let qpMap = this.queryParams; let { qpMapForRoute } = QueryParams.metaFor(controller); - keys(qpMapForRoute).forEach(key => { - qpMapForRoute[key] = Object.assign({}, qpMapForRoute[key], qpMap[key]); + keys(qpMapForRoute).forEach((key) => { + qpMapForRoute[key] = Object.assign( + {}, + qpMapForRoute[key], + qpMap[key], + ); }); this.set('queryParams', qpMapForRoute); @@ -219,13 +223,13 @@ export function initialize(/* application */) { this._scheduleParachuteChangeEvent( routeName, controller, - Object.assign({}, changed, removed) + Object.assign({}, changed, removed), ); } return this._super(...arguments); - } - } + }, + }, }); Route.reopenClass({ _didInitializeParachute: true }); @@ -233,5 +237,5 @@ export function initialize(/* application */) { export default { name: 'ember-parachute', - initialize + initialize, }; diff --git a/addon/query-params.js b/addon/query-params.js index bb7d423..b450b0c 100644 --- a/addon/query-params.js +++ b/addon/query-params.js @@ -60,7 +60,7 @@ export default class QueryParams { static metaFor(controller) { assert( `[ember-parachute] The controller '${controller}' is not set up with ember-parachute.`, - this.hasParachute(controller) + this.hasParachute(controller), ); return get(controller, PARACHUTE_META); } @@ -114,7 +114,7 @@ export default class QueryParams { return qps; }, {}, - undefined + undefined, ); } @@ -150,7 +150,7 @@ export default class QueryParams { return defaults; }, {}, - undefined + undefined, ); setProperties(controller, defaults); @@ -171,7 +171,7 @@ export default class QueryParams { let { queryParams } = this.metaFor(controller); assert( `[ember-parachute] The query parameter '${param}' does not exist.`, - queryParams[param] + queryParams[param], ); set(queryParams[param], 'defaultValue', defaultValue); } @@ -195,11 +195,8 @@ export default class QueryParams { * @returns {Ember.Mixin} */ _generateMixin() { - let { - queryParams, - defaultValues, - qpMapForController - } = this._generateMeta(); + let { queryParams, defaultValues, qpMapForController } = + this._generateMeta(); let ControllerMixin = Mixin.create(defaultValues, { /** @@ -230,7 +227,7 @@ export default class QueryParams { * @public * @property {Ember.ComputedProperty} */ - allQueryParams: computed(...keys(queryParams), function() { + allQueryParams: computed(...keys(queryParams), function () { return QueryParams.queryParamsFor(this); }).readOnly(), @@ -243,9 +240,9 @@ export default class QueryParams { queryParamsState: computed( ...keys(queryParams), `${PARACHUTE_META}.queryParamsArray.@each.defaultValue`, - function() { + function () { return QueryParams.stateFor(this); - } + }, ).readOnly(), /** @@ -269,7 +266,7 @@ export default class QueryParams { */ setDefaultQueryParamValue(key, defaultValue) { QueryParams.setDefaultValue(this, key, defaultValue); - } + }, }); return ControllerMixin; diff --git a/addon/utils/lookup-controller.js b/addon/utils/lookup-controller.js index 0df95af..28313b5 100644 --- a/addon/utils/lookup-controller.js +++ b/addon/utils/lookup-controller.js @@ -1,4 +1,3 @@ -import { get } from '@ember/object'; import { getOwner } from '@ember/application'; /** @@ -10,7 +9,7 @@ import { getOwner } from '@ember/application'; * @returns {Ember.Controller} */ export default function lookupController(route, ownerLookupFn = getOwner) { - let controller = get(route, 'controller'); + let controller = route.controller; if (!controller) { /** @@ -19,10 +18,9 @@ export default function lookupController(route, ownerLookupFn = getOwner) { * (especially with authentication) due to the controller being created * prematurely. */ - let controllerName = - get(route, 'controllerName') || get(route, 'routeName'); + let controllerName = route.controllerName || route.routeName; let factory = ownerLookupFn(route).factoryFor( - `controller:${controllerName}` + `controller:${controllerName}`, ); return factory.class.proto(); } diff --git a/app/initializers/ember-parachute.js b/app/initializers/ember-parachute.js index e53a50a..3710aa4 100644 --- a/app/initializers/ember-parachute.js +++ b/app/initializers/ember-parachute.js @@ -1 +1,4 @@ -export { default, initialize } from 'ember-parachute/initializers/ember-parachute'; +export { + default, + initialize, +} from 'ember-parachute/initializers/ember-parachute'; diff --git a/config/changelog.js b/config/changelog.js index 4b19551..5cb8d60 100644 --- a/config/changelog.js +++ b/config/changelog.js @@ -2,7 +2,6 @@ // For details on each option run `ember help release` module.exports = { - // angular style guide: https://github.com/angular/angular.js/blob/v1.4.8/CONTRIBUTING.md#commit // jquery style guide: https://contribute.jquery.org/commits-and-pull-requests/#commit-guidelines // ember style guide: https://github.com/emberjs/ember.js/blob/master/CONTRIBUTING.md#commit-tagging @@ -18,6 +17,5 @@ module.exports = { groupSort: function(commits) { return { commits: commits }; }, format: function(commit) { return commit.title; }, */ - } - + }, }; diff --git a/config/release.js b/config/release.js index a0bfb22..ce3c32b 100644 --- a/config/release.js +++ b/config/release.js @@ -1,18 +1,17 @@ var execSync = require('child_process').execSync; -// eslint-disable-next-line node/no-unpublished-require -var generateChangelog = require('ember-cli-changelog/lib/tasks/release-with-changelog'); +// var generateChangelog = require('ember-cli-changelog/lib/tasks/release-with-changelog'); module.exports = { publish: true, - beforeCommit: generateChangelog, + // beforeCommit: generateChangelog, - afterPublish: function(project, versions) { + afterPublish: function (project, versions) { runCommand( - 'ember github-pages:commit --message "Released ' + versions.next + '"' + 'ember github-pages:commit --message "Released ' + versions.next + '"', ); runCommand('git push origin gh-pages:gh-pages'); - } + }, }; function runCommand(command) { diff --git a/package.json b/package.json index 5d7090f..9f843e1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "scripts": { "build": "ember build --environment=production", "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", - "lint:css": "stylelint \"**/*.css\"", + "lint:css": "stylelint \"**/*.css\" --allow-empty-input", "lint:css:fix": "concurrently \"npm:lint:css -- --fix\"", "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", "lint:hbs": "ember-template-lint .", diff --git a/tests/dummy/app/controllers/index.js b/tests/dummy/app/controllers/index.js index 078daad..7ddf3e5 100644 --- a/tests/dummy/app/controllers/index.js +++ b/tests/dummy/app/controllers/index.js @@ -13,7 +13,7 @@ export default class IndexController extends Controller { }, deserialize(value) { return value === 'open' ? true : false; - } + }, }) parachuteOpen = true; @@ -28,17 +28,21 @@ export default class IndexController extends Controller { }, deserialize(value = '') { return value.split(','); - } + }, }) tags = ['Ember', 'Parachute']; get queryParamsChanged() { - return this.queryParamsState.page.changed || this.queryParamsState.search.changed || this.queryParamsState.tags.changed + return ( + this.queryParamsState.page.changed || + this.queryParamsState.search.changed || + this.queryParamsState.tags.changed + ); } setup({ queryParams }) { if (queryParams.parachuteOpen) { - this.get('fetchModel').perform(); + this.fetchModel.perform(); } } @@ -50,7 +54,7 @@ export default class IndexController extends Controller { queryParamsDidChange({ shouldRefresh, queryParams }) { if (shouldRefresh && queryParams.parachuteOpen) { - this.get('fetchModel').perform(); + this.fetchModel.perform(); } } @@ -76,8 +80,8 @@ export default class IndexController extends Controller { @action setDefaults() { - ['search', 'page', 'tags'].forEach(key => { - let value = key === 'tags' ? this.get(key).concat() : this.get(key); + ['search', 'page', 'tags'].forEach((key) => { + let value = key === 'tags' ? this[key].concat() : this[key]; this.setDefaultQueryParamValue(key, value); }); } diff --git a/tests/dummy/app/routes/index.js b/tests/dummy/app/routes/index.js index 812aee5..1368a8a 100644 --- a/tests/dummy/app/routes/index.js +++ b/tests/dummy/app/routes/index.js @@ -6,12 +6,12 @@ export default Route.extend({ queryParams: { page: { refreshModel: true }, tags: { refreshModel: true }, - search: { refreshModel: true } + search: { refreshModel: true }, }, model({ parachuteOpen }) { if (!parachuteOpen) { - return new Promise(resolve => later(resolve, 1000)); + return new Promise((resolve) => later(resolve, 1000)); } - } + }, }); diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index c12b05a..57dc933 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -1,4 +1,4 @@ -