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

New rule: no-global-jquery #103

Merged
merged 5 commits into from
Aug 1, 2017
Merged

New rule: no-global-jquery #103

merged 5 commits into from
Aug 1, 2017

Conversation

jbandura
Copy link
Collaborator

@jbandura jbandura commented Jul 19, 2017

Resolves #53.

Description

This PR introduces rule no-global-jquery ported (with some modifications and added tests) from ember-best-practices plugin (see #53).

package.json Outdated
@@ -50,7 +50,8 @@
"eslint": "^3.15.0",
"eslint-config-airbnb-base": "^11.1.0",
"eslint-plugin-import": "^2.2.0",
"jest": "^20.0.4"
"jest": "^20.0.4",
"jest-environment-node-debug": "^2.0.0"
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 somewhat controversial - it's required to make the debugging of jest tests in the terminal work. However I'm perfectly happy just to install it everytime for myself - I'd welcome any thoughts on this :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with this package. But then I think we should update readme and explain how to work with this + we should add an information about the workflow with ASTExplorer. That would make life of potential contributors easier. That being said, I'd prefer to move this to another PR and update Readme there as well. What do you think @jbandura ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 will move it to separate PR

@jbandura jbandura changed the title Add rule no-global-jquery New rule: no-global-jquery Jul 19, 2017
let emberImportAliasName;
let destructuredAssignment;

//----------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove those redundant comments

*/
function getEmberImportAliasName(importDeclaration) {
if (!importDeclaration.source) return null;
if (importDeclaration.source.raw !== "'ember'") return null;
Copy link
Member

Choose a reason for hiding this comment

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

I think importDeclaration.source.value !== 'ember' would be enough, no need to check the raw field.

*/
function isGlobalCallExpression(node, desctructuredName, aliases) {
const isDestructured = node && node.callee && node.callee.name === desctructuredName;
const isGlobalJquery = node.callee && aliases.indexOf(node.callee.name) > -1;
Copy link
Member

Choose a reason for hiding this comment

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

isGlobalJquery name is not relevant in the given context

});`,
parserOptions,
errors: [{
message: MESSAGE
Copy link
Member

Choose a reason for hiding this comment

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

If this is valid then why is there errors array here? Please check all valid test cases and remove errors if they should not be there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good question 😅 will fix that 👍

* @param {Object} initialObjToBinding relevant bindings
* @return {Array} list of object pattern bindings
*/
function collectObjectPatternBindings(node, initialObjToBinding) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't support one case at this moment:

const $ = Ember.$;

Are we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, we're not, good catch! 👍

@jbandura jbandura force-pushed the 53-no-global-jquery branch from 8ea46d8 to d7dd7c4 Compare July 20, 2017 12:46
@scalvert
Copy link
Collaborator

It just occurred to me during this migration of rules from our old repo to this one - we're losing attribution of the original author during this process.

We could do one of two things:

  1. Provide attribution via distinguishing between the author and committer
  2. Generate a Contributors.md, which would include contributors from both repos.

I'd prefer the first, and am happy to retrofit #99 to correctly attribute @chadhietala.

Thoughts, @jbandura @michalsnik?

@jbandura
Copy link
Collaborator Author

I agree @scalvert. However, since after the first migration from ember-best-practices we cannot rely on the fact that committer == author of the rule, we'll have to add attribution to all the existing rules as well. WDYT @michalsnik?

@michalsnik
Copy link
Member

michalsnik commented Jul 21, 2017 via email

@scalvert
Copy link
Collaborator

@jbandura - my point is we should separate the committer and author, so that we can distinguish between the two. The committer may in fact be the author, or they may not. We can specify the author if the committer != author.

Does this make sense?

@michalsnik - I'll go ahead and amend the commit for #99 to correctly set the author as @chadhietala.

@scalvert
Copy link
Collaborator

Actually @michalsnik I think you have to do it. I've not been added as a collaborator on this repo yet, and as such cannot rewrite history.

@michalsnik
Copy link
Member

I'm not a big fun of rewriting history @scalvert.. Feel free to create a separate PR. I'll do the same with the rest of the files anyway. Are you ok with this? :)

Cover cases such as `const $ = Ember.$`
@jbandura
Copy link
Collaborator Author

@michalsnik applied your suggestions and added test cases for const $ = Ember.$ case, let me know what you think

@michalsnik
Copy link
Member

LGTM 🚀

@michalsnik michalsnik merged commit d0f3c02 into master Aug 1, 2017
@michalsnik michalsnik deleted the 53-no-global-jquery branch August 1, 2017 07:09
@amk221
Copy link

amk221 commented Aug 1, 2017

@jbandura Should this be supported?

import jQuery from 'jquery';
const $myEl = jQuery('.my-element'); 

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.

5 participants