Linter warning about object as default property

My linter return the following warning: Only string, number, symbol, boolean, null, undefined, and function are allowed as default properties ember/avoid-leaking-state-in-ember-object

for this line in a model :

providerValues:{someprovider:'Some Provider',otherprovider:'Other Provider' }

That I use to complete this property : provider:DS.attr('string')

How should I set static values in a model to avoid this warning ?

The two most common solutions I’ve seen are returning it from a “dummy” computed property or, cleaner and better IMO, wrapping it in Object.freeze() e.g.

providerValues: Object.freeze({ someprovider:'Some Provider',otherprovider:'Other Provider' })

This signals that it won’t be mutated at runtime, which follows the both the letter of the law and the spirit, as it were. Here’s another thread for more reading.

1 Like