-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Add rule to disallow this.$
to prepare apps to remove jQuery
#121
Conversation
Thank you for the PR @cibernox! Personally I think this is a fantastic idea and definitely a step in the right direction. I also agree on not making the rule enabled by default, since it would break a lot of apps. |
README.md
Outdated
|
||
| | Rule ID | Description | | ||
|:---|:--------|:------------| | ||
| | [no-this-jquery](./docs/rules/no-this-jquery.md) | Disallow use of `this.# eslint-plugin-ember |
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.
Seems that the script doesn't like this.$
🤔
I added docs and regenerated the readme, but I think there is too many changes. |
After some conversation, this rule is going to be edited to be Tasks:
|
8baabdd
to
d875eb5
Compare
I've updated the PR to be a no-jquery, which covers pretty much any reasonable usage of jQuery. |
README.md
Outdated
|
||
| | Rule ID | Description | | ||
|:---|:--------|:------------| | ||
| | [no-jquery](./docs/rules/no-jquery.md) | Disallow use of `this.# eslint-plugin-ember |
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.#
should be this.$
(and there is a missing backtick)
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 know, but this is autogenerated. If we don't fix the error in the generator the next one in running the script will ruin this again.
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.
Gotcha! I didn't realize it was auto-generated, sorry 😸
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 make sure to create an issue for that (so we can track down the bug).
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.
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.
👍
Have a look at https://github.com/ember-best-practices/eslint-plugin-ember-best-practices/blob/master/lib/rules/no-jquery-methods.js might help cover any corner-cases you run into. |
@lynchbomb I believe that I've covered all that. Do you see anything not covered? |
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.
Please set additionally in no-global-jquery
's meta docs:
replacedBy: 'no-jquery',
deprecated: true
I'll add extra list with replaced rules in readme later.
lib/rules/no-jquery.js
Outdated
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Disallow use of `this.$` on components or tests', |
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.
You should update description of the rule, as now it disallows any jQuery usage. When you'll do this, please revert readme and execute npm run update
once again.
lib/rules/no-jquery.js
Outdated
}, | ||
|
||
MemberExpression(node) { | ||
if ((node.object.name === 'Ember' || node.object.name === 'Em' || (emberImportAliasName && node.object.name === emberImportAliasName)) && node.property.name === '$') { |
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.
Please wrap this line to make it more readable
lib/rules/no-jquery.js
Outdated
context.report(node, message); | ||
} | ||
|
||
if (isThisJquery(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.
I'm fine with this, however just to let you know you could also use eslint selectors:
'CallExpression > MemberExpression > ThisExpression' (node) {
if (node.parent.property.name === '$') {
// busted
}
}
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.
TIL. I'm pretty new to ESLint rules, but this is neat 👌
lib/rules/no-jquery.js
Outdated
|
||
MemberExpression(node) { | ||
if ((node.object.name === 'Ember' || node.object.name === 'Em' || (emberImportAliasName && node.object.name === emberImportAliasName)) && node.property.name === '$') { | ||
report(node, 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.
This function doesn't expect second argument. Anyway you should either use report
function everywhere or context.report
lib/rules/no-jquery.js
Outdated
} | ||
|
||
if (isThisJquery(node)) { | ||
report(node, specialisedMessageForThisJquery); |
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 I wrote above report
doesn't seem to accept the second argument.
tests/lib/rules/no-jquery.js
Outdated
}] | ||
}, | ||
{ | ||
code: ` |
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.
Just to make this test case complete, please add filename
field with real path including tests/
@michalsnik I've applied the feedback |
This seems good if we're extending no-global-jquery. I'm all for consolidating in this rule. The intent of no-global-jquery was to ensure that people were using Perhaps we should instead keep them distinct? |
@michalsnik As part of this PR, requested on the code review, I've marked the I wouldn't oppose to allow both to coexist. This one is a superset of the other one, so there is no point in enabling the other one if this one is, but I think it's just a matter of documenting in the readme how both rules are different and people can decide which one they want to enable. |
Yeah that was my recommendation if we were to remove the other rule in the next major release. But if we decide to leave it than my recommendation was wrong and we should keep both rules, but only of them marked as Sorry for the confusion @cibernox. But I thought this through once more after last comment from @scalvert and I'd remove:
which I proposed before. We're probably not going to deprecate this rule, as in old living projects removing jQuery could be a truly daunting task, but making sure that it doesn't use global jquery would be a quick win, small step towards better code base. With this in mind removing |
@michalsnik again I strongly advise against yet another major release in the near future. It will create a lot of unnecessary churn and IMHO we should wait a few months until things have settled down a bit. |
In modern browsers jQuery is less and less needed as many features are not built in into modern browsers and the bugs that jQuery used to help you avoid have been fixed. However, jQuery still adds ~30KB (min + gzip) to every Ember app, which can add up to 1 second of download + parse times on mobile devices. Is is not possible to remove jQuery from Ember apps, and one of the main features in Ember that cannot be used on an app that intends to remove jQuery in a near future is `this.$`, either inside component's methods or within tests. This PR adds a rule, that is entirely options and **I do not think** it should be enabled by default to yell at anyone who uses `this.$`. Please let me know what else has to be done (documentation, etc...) to make this mergeable.
aa988fe
to
419cd50
Compare
419cd50
to
d55c791
Compare
@michalsnik I've removed those options so both rules coexist. Also since I've changed the description of the rule, #127 doesn't affect the new docs. |
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.
LGTM 👍
Can we merge? |
Thanks @cibernox ! Released in |
In modern browsers jQuery is less and less needed as many features are not built in
into modern browsers and the bugs that jQuery used to help you avoid have been fixed.
However, jQuery still adds ~30KB (min + gzip) to every Ember app, which can add up to
1 second of download + parse times on mobile devices. Is is now possible to remove
jQuery from Ember apps, and one of the main features in Ember that cannot be used on
an app that intends to remove jQuery in a near future is
this.$
, either insidecomponent's methods or within tests.
This PR adds a rule, that is entirely optional and I do not think it should
be enabled by default to yell at anyone who uses
this.$
.Please let me know what else has to be done (documentation, etc...) to make
this mergeable.