eslint-plugin-ember
eslint-plugin-ember copied to clipboard
`require-computed-property-dependencies`: false positive for spread array of keys
Repro:
import { computed } from '@ember/object';
import Component from '@ember/component';
const keys = ['prop']; // could change at runtime
const frozenKeys = Object.freeze(keys); // definitely not changing
export default Component.extend({
prop: 10,
inlineDecl: computed('prop', function () { // rule ok
return this.prop * 10 > 100;
}),
arrayDecl: computed(...keys, function () { // Could use AST to determine if `keys` or its elements are modified anywhere in this file and warn if so.
return this.prop * 10 > 100;
}),
frozenDecl: computed(...frozenKeys, function () { // rule triggers, should definitely not.
return this.prop * 10 > 100;
}),
});
Is it ill-formed to pass computed
an array of dependent keys? If not, can this rule be updated to handle arrays whose values are known at compile time? I understand that it's probably not feasible to handle arrays containing values that reference imports, but for fixed & known keys I would expect the rule to work.
Yes I believe the rule should be updated to allow this.
getStaticValue
could be used to attempt to get the key(s) from any variables passed as dependent keys.