Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rules/avoid-leaking-state-in-ember-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function isAllowed(value) {
ember.isFunctionExpression(value) ||
types.isLiteral(value) ||
types.isIdentifier(value) ||
types.isCallExpression(value) ||
// NOTE: CallExpression intentionally removed — myProp: A() or
// myProp: EmberObject.create() creates a shared instance across all
// object instances, leaking state. See issue #300.
types.isBinaryExpression(value) ||
types.isTemplateLiteral(value) ||
types.isTaggedTemplateExpression(value) ||
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/avoid-leaking-state-in-ember-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,27 @@ eslintTester.run('avoid-leaking-state-in-ember-objects', rule, {
},
],
},
{
// myProp: A() creates a shared instance across all Ember object instances
code: 'export default Foo.extend({ someProp: A() });',
output: null,
errors: [
{
message:
'Only string, number, symbol, boolean, null, undefined, and function are allowed as default properties',
},
],
},
{
// EmberObject.create() as a default property leaks shared state
code: 'export default Foo.extend({ someProp: EmberObject.create() });',
output: null,
errors: [
{
message:
'Only string, number, symbol, boolean, null, undefined, and function are allowed as default properties',
},
],
},
],
});