Skip to content

fix: warn on call expression defaults in avoid-leaking-state rule - #2834

Open
0x5t4l1n wants to merge 1 commit into
ember-cli:masterfrom
0x5t4l1n:fix/leaking-state-call-expression
Open

fix: warn on call expression defaults in avoid-leaking-state rule#2834
0x5t4l1n wants to merge 1 commit into
ember-cli:masterfrom
0x5t4l1n:fix/leaking-state-call-expression

Conversation

@0x5t4l1n

@0x5t4l1n 0x5t4l1n commented Aug 2, 2026

Copy link
Copy Markdown

Summary\n\nFixes #300myProp: A() and myProp: EmberObject.create() were not flagged by the avoid-leaking-state-in-ember-objects rule, even though they create a shared object instance across all instances of the Ember object, leaking state just like an inline array/object literal.\n\nRoot cause: isAllowed() had types.isCallExpression(value) in its allow-list.\n\nFix: Remove CallExpression from the allow-list. Users who intentionally call a factory that returns a primitive can add the property name to ignoredProperties.\n\n## Test plan\n- [ ] npx eslint --rulesdir lib/rules . — no regressions\n- [ ] Add test: myProp: A() → rule fires\n- [ ] myProp: () => {} → rule does not fire (still allowed as FunctionExpression)\n\n🤖 Generated with Claude Code

…ssion

Resolves ember-cli#300. The avoid-leaking-state-in-ember-objects rule called
isAllowed() which unconditionally permitted any CallExpression value
(e.g. myProp: A()). Call expressions that return objects or arrays
produce a shared instance across all instances of the Ember object,
leaking state just like an inline array/object literal would.

Remove types.isCallExpression from the isAllowed allow-list so that
myProp: A(), myProp: EmberObject.create(), etc. are flagged. Pure
function calls that return primitives will also be flagged, but that is
the safe default — users can add them to the ignoredProperties list for
their specific case.
@NullVoxPopuli

Copy link
Copy Markdown
Contributor

Can you provide a failing test for your change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants