🔧 This rule is automatically fixable by the --fix CLI option.
Note: this rule will not be added to the recommended configuration because it enforces an opinionated, stylistic preference.
| Name | Type |
|---|---|
order |
Array |
const rules = {
'ember/order-in-routes': [
2,
{
order: [
'spread',
'service',
'inherited-property',
'property',
'single-line-function',
'multi-line-function',
'beforeModel',
'model',
'afterModel',
'serialize',
'redirect',
'activate',
'setupController',
'renderTemplate',
'resetController',
'deactivate',
'actions',
['method', 'empty-method'],
],
},
],
};If you want some of properties to be treated equally in order you can group them into arrays, like so:
order: [
'service',
['inherited-property', 'property'],
'model',
[
'beforeModel',
'model',
'afterModel',
'serialize',
'redirect',
'activate',
'setupController',
'renderTemplate',
'resetController',
'deactivate',
],
'actions',
['method', 'empty-method'],
];If you would like to specify ordering for a property type that is not listed, you can use the custom property syntax custom:myPropertyName in the order list to specify where the property should go.
You can find the full list of properties in property-order.js.
You should write code grouped and ordered in this way:
- Services
- Default route's properties
- Custom properties
- beforeModel() hook
- model() hook
- afterModel() hook
- Other lifecycle hooks in execution order (serialize, redirect, etc)
- Actions
- Custom / private methods
const {
Route,
inject: { service },
} = Ember;
export default Route.extend({
// 1. Services
currentUser: service(),
// 2. Default route's properties
queryParams: {
sortBy: { refreshModel: true },
},
// 3. Custom properties
customProp: 'test',
// 4. beforeModel hook
beforeModel() {
if (!this.currentUser.isAdmin) {
this.transitionTo('index');
}
},
// 5. model hook
model() {
return this.store.findAll('article');
},
// 6. afterModel hook
afterModel(articles) {
for (const article of articles) {
article.set('foo', 'bar');
}
},
// 7. Other route's methods
setupController(controller) {
controller.set('foo', 'bar');
},
// 8. All actions
actions: {
sneakyAction() {
return this._secretMethod();
},
},
// 9. Custom / private methods
_secretMethod() {
// custom secret method logic
},
});This rule checks ordering only; it does not enforce indentation or other whitespace formatting.