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

Add missing tests #91

Merged
merged 2 commits into from
Oct 3, 2017
Merged

Add missing tests #91

merged 2 commits into from
Oct 3, 2017

Conversation

hjdivad
Copy link
Collaborator

@hjdivad hjdivad commented Sep 27, 2017

This adds a couple of failing tests and a passing but previously missing test.

The missing test added is for calling set which was destructured from import Ember from 'ember'

One failing test is to handle the case where Ember.computed is called from an import that isn't named Ember, eg

import E from 'ember';
E.computed()

Another failing test illustrates that ember import bindings are clobbered if followed by any other default import, as in:

import Ember from 'ember';
import AnythingElse from 'anywhere';

tl;dr things to fix

  • don't clobber ember import bindings
  • move module scope information to context arg
  • more intelligently detect Ember.computed

This adds two failing tests to highlight bugs and a passing but
previously missing test.

The missing test added is for calling `set` which was destructured from
`import Ember from 'ember'`

One failing test is to handle the case where `Ember.computed` is called
from an import that isn't named `Ember`, eg
```
import E from 'ember';
E.computed()
```

Another failing test illustrates that ember import bindings are
clobbered if followed by any other default import, as in:
```
import Ember from 'ember';
import AnythingElse from 'anywhere';
```
@hjdivad
Copy link
Collaborator Author

hjdivad commented Sep 27, 2017

cc @rwjblue

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.

Sure would be nice if there was something like a todo test 😉

@rwjblue
Copy link
Collaborator

rwjblue commented Sep 30, 2017

Hehe. Confirm. Really need to get that wired up right through testem and whatnot.

@rwjblue
Copy link
Collaborator

rwjblue commented Oct 1, 2017

OK, just did a pass across this rule to fix the largest issues that @hjdivad pointed out above. I pushed the fix commits directly to this branch, so it should be ready for review...

code: `
import Ember from 'ember';
import SomethingElse from 'something-else';
const { set } = Ember;
Copy link
Collaborator

@scalvert scalvert Oct 2, 2017

Choose a reason for hiding this comment

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

Can we space in these lines in to line them up with the code below. It's a bit hard to read like this.

{
code: `
import Ember from 'ember';
const { set } = Ember;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here re: spacing.

},
{
code: `
import E from 'ember';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here re: spacing.

}
return false;
}

module.exports = function isCPGetter(node) {
return isCPDesc(node, 'get') || isCPAccessor(node) || isPrototypeExtCP(node);
module.exports = function isCPGetter(node, importedCPName, importedEmberName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For some reason it feels more natural to have importedEmberName come before importedCPName, like in hierarchical order.

return true;
}
if (callee.type === 'MemberExpression') {
let caller = getCaller(callee);
return caller === 'Ember.computed' || caller === 'Em.computed';
return caller === 'Ember.computed' || caller === 'Em.computed' || caller === importedEmberName + '.computed';
Copy link
Collaborator

@scalvert scalvert Oct 2, 2017

Choose a reason for hiding this comment

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

You could template string ${importedEmberName}.computed

Copy link
Collaborator

@scalvert scalvert left a comment

Choose a reason for hiding this comment

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

This is looking good. It appears to do as advertised. I just dropped a few comments.

@hjdivad
Copy link
Collaborator Author

hjdivad commented Oct 2, 2017

LGTM 👍

Fixes a number of the errors previously identified, as well as a few
additional ones (tests added in this commit).
@rwjblue
Copy link
Collaborator

rwjblue commented Oct 2, 2017

@scalvert - I believe that the latest push addresses all of your comments. Let me know if you spot anything else...

@scalvert
Copy link
Collaborator

scalvert commented Oct 3, 2017

LGTM

@scalvert scalvert merged commit 126d16a into master Oct 3, 2017
@scalvert scalvert deleted the hjdivad/no-set-cp-bug branch October 3, 2017 23:13
mwpastore pushed a commit to mwpastore/eslint-plugin-ember-best-practices that referenced this pull request Nov 29, 2017
* Add missing tests

This adds two failing tests to highlight bugs and a passing but
previously missing test.

The missing test added is for calling `set` which was destructured from
`import Ember from 'ember'`

One failing test is to handle the case where `Ember.computed` is called
from an import that isn't named `Ember`, eg
```
import E from 'ember';
E.computed()
```

Another failing test illustrates that ember import bindings are
clobbered if followed by any other default import, as in:
```
import Ember from 'ember';
import AnythingElse from 'anywhere';
```

* Clean up no-side-effect-cp rule.

Fixes a number of the errors previously identified, as well as a few
additional ones (tests added in this commit).
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.

None yet

4 participants