Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting Ember Data relationship inverses #1776

Closed
jede opened this issue Feb 8, 2023 · 2 comments · Fixed by #2155
Closed

Linting Ember Data relationship inverses #1776

jede opened this issue Feb 8, 2023 · 2 comments · Fixed by #2155
Labels
enhancement New Rule Idea for a new lint rule

Comments

@jede
Copy link

jede commented Feb 8, 2023

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

@bmish bmish added enhancement New Rule Idea for a new lint rule labels Feb 8, 2023
@bmish
Copy link
Member

bmish commented Feb 8, 2023

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

PR welcome.

@jede
Copy link
Author

jede commented Feb 9, 2023

Great! I'll give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New Rule Idea for a new lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants