Starting in Ember 3.1, native ES5 getters are available, which eliminates much of the need to use get / getProperties on Ember objects.
This rule disallows:
this.get('someProperty')whenthis.somePropertycan be usedthis.getProperties('prop1', 'prop2')when{ prop1: this.prop1, prop2: this.prop2 }can be used
WARNING: there are a number of circumstances where get / getProperties still need to be used, and you may need to manually disable the rule for these:
- Ember proxy objects (
ObjectProxy,ArrayProxy) - Objects implementing the
unknownPropertymethod
Examples of incorrect code for this rule:
const foo = this.get('someProperty');import { get } from '@ember/object';
const foo = get(this, 'someProperty');const { prop1, prop2 } = this.getProperties('prop1', 'prop2');import { getProperties } from '@ember/object';
const foo = getProperties(this, 'prop1', 'prop2');Examples of correct code for this rule:
const foo = this.someProperty;const foo = this.get('some.nested.property'); // Allowed because of nested path.const { prop1, prop2 } = this;const foo = { prop1: this.prop1, prop2: this.prop2 };- Ember 3.1 Release Notes describing "ES5 Getters for Computed Properties"
- Ember get Spec
- Ember getProperties Spec
- Ember ES5 Getter RFC
- es5-getter-ember-codemod
- More context about the proxy object exception to this rule