ember-cli / ember-cli/eslint-plugin-ember

`require-computed-property-dependencies`: false positive for spread array of keys

Open
#1,317 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
263
Forks
214
Avg merge
30m
Merged PRs (30d)
5

Description

Repro:

```js
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;
}),
});
```
![image](https://user-images.githubusercontent.com/20871346/135323364-213f0e7e-7de0-4652-8bf0-233fff98a247.png)

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.