eslint-plugin-ember icon indicating copy to clipboard operation
eslint-plugin-ember copied to clipboard

Linting Ember Data relationship inverses

Open jede opened this issue 3 years ago • 2 comments

Since Ember Data now require you to specify an inverse relation in hasMany and belongsTo relations I wrote a crude script to check if it all maps out and if there are any inconsistencies. After I wrote it I realised that it could probably be turned into some kind of eslint rule.

Basically it would give warnings in for instance the following situation since the inverse is not correctly specified both ways:

// app/models/email.js

@belongsTo('user', {async: true, inverse: null}) user
// app/models/user.js

@hasMany('email', {async: true, inverse: 'user'}) emails

However I'm not sure if this is within the scope of this project? If you find it relevant let me know and I can try to make a rule of it and send a PR.

Here it the script for checking inverses in Ember Data: https://gist.github.com/jede/cce91a376384fef466d70c254ad73b02

jede avatar Feb 08 '23 09:02 jede

Neat! We do accept lint rules related to Ember Data: https://github.com/ember-cli/eslint-plugin-ember#ember-data

PR welcome.

bmish avatar Feb 08 '23 16:02 bmish

Great! I'll give it a try!

jede avatar Feb 09 '23 09:02 jede