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

Improved error messages for order-in rules #23

Merged
merged 19 commits into from Feb 9, 2017

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Feb 7, 2017

This PR implements improved error messages for order-in rules and also makes those rules configurable if someone would like to use a different order.

Example: The "currentUser" service injection should be above the inherited "queryParams" property on line 2

/cc @michalsnik

Copy link
Collaborator

@jbandura jbandura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢 left two minor comments - nothing urgent

return 'service';
}

if (parentType === 'component') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly style preference, but why not

if(parentType === 'component' && ember.isComponentLifecycleHook(node)) {
...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly just for consistency with the model condition below and the fact that this will be easier to extend should we want to add a second condition that only applies to components

}

function getOrder(ORDER, type) {
for (var i = 0, len = ORDER.length; i < len; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we're using ES6 features in some places already, it would be cleaner IMO to use forEach - could just as well be addressed as a bulk change in later PR's though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't use forEach here because there is no way to break out of a forEach before having iterated over the whole array. in this case though we can stop iterating once we've found what we're looking for.

//------------------------------------------------------------------------------
// Organizing - Organize your components and keep order in objects
//------------------------------------------------------------------------------

module.exports = function(context) {
var options = context.options[0] || {};
var order = options.order || ORDER;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good idea with giving developers option to change default order 👍

@michalsnik
Copy link
Member

I'm really happy with these changes @Turbo87 :) I think that we should address ES6 changes later @jbandura, and like you say - bulk update whole project.

One thing that is missing here is documentations for those rules. We should add information about the possibility of changing default order. Other than that truly good job! 🚀

@Turbo87
Copy link
Member Author

Turbo87 commented Feb 9, 2017

@michalsnik I'd say lets test this out first as an experimental option and document it for the release after that. just in case something is not yet working as expected and we'd like to change some behavior.

@michalsnik
Copy link
Member

Alright, makes sense.

@michalsnik michalsnik merged commit e02828d into ember-cli:master Feb 9, 2017
@Turbo87 Turbo87 deleted the order branch February 9, 2017 16:01
@davidpett
Copy link

@michalsnik is a new release going to be cut for this merge?

@michalsnik
Copy link
Member

Yes, however I wanted to test it before releasing on master. I'll try to do this today. Unfortunately I didn't release beta if that's what you're asking too.

@davidpett
Copy link

No worries, was just curious. I can also help test the master version

@michalsnik
Copy link
Member

Thanks! Let me know if you find something :)

@davidpett
Copy link

The only issue I am seeing is that the order states that services should come before inherited props, when i do that, the ember/query-params-on-top rule throws. @Turbo87 is there a way to update to check/override other rules?

@Turbo87
Copy link
Member Author

Turbo87 commented Feb 14, 2017

@davidpett I think that issue already existed before my PR. I'm not sure how to solve this properly...

@michalsnik
Copy link
Member

This indeed seems to be an issue that existed before as well.. Regarding current order rules I think the best way would be to just set queryParams as the next thing after service injections and get rid of query-params-on-top rule, or at least disable it in default and recommended config. If anyone wants to change order in controller he can in eslint's configuration anyway. Let me open separate issue with this so that we can better track this problem :)

@michalsnik
Copy link
Member

Released https://github.com/netguru/eslint-plugin-ember/releases/tag/v2.2.0 🎉 Great work @Turbo87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants