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

Adding new rule: require-ember-lifeline #62

Merged
merged 7 commits into from
Jun 26, 2017
Merged

Conversation

scalvert
Copy link
Collaborator

@scalvert scalvert commented Jun 22, 2017

This rule identifies the use of Ember.run.* and indicates the requirement to use runTask, debounceTask, or throttleTask from ember-lifeline in favor of the run variant.

Copy link
Member

@trentmwillis trentmwillis left a comment

Choose a reason for hiding this comment

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

Do we expect there to be anything else we lint for with ember-lifeline? If so, we might want a more specific rule name.


Ember applications have long life-cycles. A user may navigate to several pages and use many different features before they leave the application. This makes JavaScript and Ember development unlike Rails development, where the lifecycle of a request is short and the environment disposed of after each request. It makes Ember development much more like iOS or video game development than traditional server-side web development.

It is good to note that this isn't something inherent to just Ember. Any single-page app framework or solution (Angular, React, Vue, Backbone...) must deal this lifecycles of objects, and specifically with how async tasks can be bounded by a lifecycle.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: "must deal this lifecycles" -> "must deal with the lifecycles"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

}
},

ImportDefaultSpecifier(node) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can we move this above ObjectPattern? Since it is expected to run prior to that function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yessir!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

return {
ObjectPattern(node) {
if (emberImportBinding) {
LATER_PATTERNS = LATER_PATTERNS.concat(collectObjectPatternBindings(node, {
Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly, this code catches if run.later was bound to something else, correct? If so, can we add a test for this scenario?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, on it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,48 @@
/**
* @fileOverview Require the use of ember-lifeline's runTask over using Ember.run.later.
* @author Steve Calvert
Copy link
Member

Choose a reason for hiding this comment

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

After spending a bit of time thinking about it, I'd like for us to stop placing @author annotations in these files. They feel territorial and might off put newer contributors.

If we want to acknowledge authors/contributors, we should go the route of placing an AUTHORS.txt file in the root of the repo which can be generated from the git history (example from QUnit).

Copy link
Member

Choose a reason for hiding this comment

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

Totally agree. AUTHORS.txt works for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But how will the world know about my amazing feats of coding?

Totally agree. I'll remove from all rules in a separate PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is done.

@@ -0,0 +1,48 @@
/**
* @fileOverview Require the use of ember-lifeline's runTask over using Ember.run.later.
* @author Steve Calvert
Copy link
Member

Choose a reason for hiding this comment

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

Totally agree. AUTHORS.txt works for me.


module.exports = {
docs: {
description: 'Please use runTask from ember-lifeline in favor of Ember.run.later.',
Copy link
Member

@lynchbomb lynchbomb Jun 23, 2017

Choose a reason for hiding this comment

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

Can you leverage the MESSAGE variable rather than duplicating this message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As you can see now, the message is dynamically generated based on the node being inspected. I've adjusted it now.

});
}
});`,
parserOptions: {
Copy link
Member

Choose a reason for hiding this comment

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

Can we move the parserOptions up into the RuleTester() and then remove the duplicated parserOptions?

example:

const ruleTester = new RuleTester({
  parserOptions: { ... }
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fo sho.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@scalvert
Copy link
Collaborator Author

@trentmwillis updated to include both debounce and throttle. Can you take another look?

@scalvert
Copy link
Collaborator Author

Bump @trentmwillis

ecmaVersion: 6,
sourceType: 'module'
}
parserOptions
Copy link
Member

Choose a reason for hiding this comment

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

Can we delete these redundant parserOptions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above.

@@ -1,26 +1,31 @@
const rule = require('../../../lib/rules/require-ember-lifeline');
const MESSAGE = rule.meta.message;
const getMessage = rule.meta.message;
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester();
Copy link
Member

Choose a reason for hiding this comment

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

Can we just pass the parserOptions object directly into the instantiation of RuleTester(). That way we can delete the redundant parserOptions from each assertion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can, but do we care? If we do, we should do this across all the test files. That should be done separately in a different PR. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

IDK I think it's more than a nit. We should prob make this change to all the tests. Figure it's still early days within this repo and we can solidify the ideals.

Essentially we have lines of code within tests that are redundant. I'm all for a balance of succinct yet grokkable. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm happy to refactor this, just want it to be in a separate PR. I created #65 to address this.


return {
ImportDefaultSpecifier(node) {
emberImportBinding = getEmberImportBinding(node);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also handle:

import run from '@ember/runloop';
import { debounce } from '@ember/runloop';
import { throttle } from '@ember/runloop';
import { later } from '@ember/runloop';
import { next } from '@ember/runloop';

Could be done in a follow up PR though...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added #66

@scalvert scalvert merged commit 7604b1e into master Jun 26, 2017
@scalvert scalvert deleted the require-ember-lifeline branch June 26, 2017 22:03
lynchbomb pushed a commit to lynchbomb/eslint-plugin-ember-best-practices that referenced this pull request Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants