-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/rules/require-ember-lifeline.js
Outdated
} | ||
}, | ||
|
||
ImportDefaultSpecifier(node) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yessir!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/rules/require-ember-lifeline.js
Outdated
return { | ||
ObjectPattern(node) { | ||
if (emberImportBinding) { | ||
LATER_PATTERNS = LATER_PATTERNS.concat(collectObjectPatternBindings(node, { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, on it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/rules/require-ember-lifeline.js
Outdated
@@ -0,0 +1,48 @@ | |||
/** | |||
* @fileOverview Require the use of ember-lifeline's runTask over using Ember.run.later. | |||
* @author Steve Calvert |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done.
lib/rules/require-ember-lifeline.js
Outdated
@@ -0,0 +1,48 @@ | |||
/** | |||
* @fileOverview Require the use of ember-lifeline's runTask over using Ember.run.later. | |||
* @author Steve Calvert |
There was a problem hiding this comment.
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.
lib/rules/require-ember-lifeline.js
Outdated
|
||
module.exports = { | ||
docs: { | ||
description: 'Please use runTask from ember-lifeline in favor of Ember.run.later.', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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: { ... }
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fo sho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@trentmwillis updated to include both |
Bump @trentmwillis |
ecmaVersion: 6, | ||
sourceType: 'module' | ||
} | ||
parserOptions |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added #66
* Adding new rule: require-ember-lifeline
This rule identifies the use of
Ember.run.*
and indicates the requirement to userunTask
,debounceTask
, orthrottleTask
from ember-lifeline in favor of the run variant.