✅ The "extends": "plugin:ember/recommended"
property in a configuration file enables this rule.
Accessing the controller in a route outside of setupController
/resetController
hooks (where it is passed as an argument) is discouraged.
If access is required regardless, controllerFor
must be used to assert the controller isn't undefined as it is not guaranteed to be eagerly loaded (for optimization purposes).
This rule disallows routes from accessing the controller outside of setupController
/resetController
.
Examples of incorrect code for this rule:
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class MyRoute extends Route {
@action
myAction() {
const controller = this.controller;
}
}
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class MyRoute extends Route {
@action
myAction() {
const controller = this.controllerFor('my');
}
}
Examples of correct code for this rule:
import Route from '@ember/routing/route';
export default class MyRoute extends Route {
setupController(controller, ...args) {
super.setupController(controller, ...args);
const foo = controller.foo;
}
}
import Route from '@ember/routing/route';
export default class MyRoute extends Route {
resetController(controller, ...args) {
super.resetController(controller, ...args);
const foo = controller.foo;
}
}
- object -- containing the following properties:
- boolean --
allowControllerFor
-- whether the rule should allow or disallow routes from accessing the controller outside ofsetupController
/resetController
viacontrollerFor
(default:false
)
- boolean --