An ESLint plugin that ensures all of your Ember Data relationships are sync.
We think async relationships do more harm than good. If you agree, you can use this ESLint plugin to help you migrate an app away from async relationships and ensure no new async relationships are added by mistake.
Install the plugin as a dev dependency in your Ember CLI project.
npm install --save-dev eslint-plugin-ember-data-sync-relationships
This makes the plugin available to ESLint.
Add the plugin and rule to your app's .eslintrc.js
:
// .eslintrc.js
module.exports = {
plugins: [
'ember-data-sync-relationships'
],
rules: {
"ember-data-sync-relationships/no-async-relationships": "warn" // warn or error
}
};
You can make the rule either "warn" or "error".
Using warn will show ESLint warnings whenever you build your app, for example when you run ember serve
.
If you'd like to start removing async relationships from an existing app that relies on them, this is a good option, since it won't fail your test suite. You can eliminate async relationships one at a time until you arrive at fully synchronous bliss, at which time you can switch this ESLint rule to "error".
Using error will add any failures to your test suite. This is a stronger way to enforce all relationships stay sync, since Ember Data's default is async and it can be easy to forget the additional { async: false }
.
If you use Mirage you may see their relationships coming up as false-positives.
Exclude them by adding the following to your app's .eslint.js
overrides array:
overrides: [
// don't check mirage models
{
files: 'mirage/**/*.js',
rules: {
"ember-data-sync-relationships/no-async-relationships": "off"
},
}
]
This library is developed and maintained by EmberMap. If your company is looking to see how it can get the most out of Ember, please get in touch!