Add new rule no-controllers - #661
Conversation
| @tracked category = null; | ||
| ... | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Would the rule prevent code other than queryParams and the category property?
There was a problem hiding this comment.
Currently no. I'm enforcing the following simplified rule: If queryParams is defined inside the controller, then the controller and any other code in it is allowed. If queryParams is not defined inside the controller, then the controller is not allowed.
Why? Because it's non-trivial to determine if a particular line of code/function/property/observer/action handler/service injection/etc inside a controller is involved in or needed for reading or modifying a query parameter value.
For example, all the code below is needed for managing a query parameter value, but it would be very difficult for the lint rule to determine that.
export default Controller.extend({
queryParams: ['sortType'],
sortType: null,
hasDefaultSortType: equal('model.sortType', DEFAULT_SORT_TYPE),
sortObserver: observer('hasDefaultSortType', function() {
if (this.hasDefaultSortType) {
this.set('sortType', null);
} else {
this.set('sortType', this.model.sortType);
}
}),
});There was a problem hiding this comment.
makes sense. what happens if queryParams = [] is defined?
There was a problem hiding this comment.
If you're asking if the rule handles native class syntax, then yes, it will allow a native class controller as long as it has queryParams = [...].
|
Seems good to me, though we shouldn't enable it by default. |
Some people may want to avoid the use of controllers in their applications.
Controllers are only truly necessary for specifying
queryParamstoday, so this rule only allows controllers ifqueryParamsare present.While controllers are not currently deprecrated, the Ember 2019-2020 Roadmap RFC does mention:
Fixes #660. CC: @mehulkar.