fix: warn on call expression defaults in avoid-leaking-state rule - #2834
Open
0x5t4l1n wants to merge 1 commit into
Open
fix: warn on call expression defaults in avoid-leaking-state rule#28340x5t4l1n wants to merge 1 commit into
0x5t4l1n wants to merge 1 commit into
Conversation
…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.
Contributor
|
Can you provide a failing test for your change? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary\n\nFixes #300 —
myProp: A()andmyProp: EmberObject.create()were not flagged by theavoid-leaking-state-in-ember-objectsrule, 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()hadtypes.isCallExpression(value)in its allow-list.\n\nFix: RemoveCallExpressionfrom the allow-list. Users who intentionally call a factory that returns a primitive can add the property name toignoredProperties.\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