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-duplicate-dependent-keys #104

Merged
merged 8 commits into from
Aug 7, 2017

Conversation

jbandura
Copy link
Collaborator

@jbandura jbandura commented Jul 20, 2017

Resolves #59.

Introducing new rule no-duplicate-dependent-keys.

@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:

Provide attribution via distinguishing between the author and committer
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, but this rule is not a migration :) I added my thoughts in #103.

@scalvert
Copy link
Collaborator

Ah, you're right. Thanks!

* @param {CallExpression} callExp Given call expression
* @return {Boolean} Flag whether dependent keys present.
*/
function hasDuplicateDependentKeys(callExp) {
Copy link
Member

Choose a reason for hiding this comment

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

This function should be in ember.js util. We want these utils to be independent from ember-related stuff.

* @param {CallExpression} callExp CallExpression to examine
* @return {Array} Array of unwrapped dependent keys
*/
function parseDependentKeys(callExp) {
Copy link
Member

Choose a reason for hiding this comment

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

This too

* @param {Array} dependentKeys array of strings containing unprocessed dependent keys.
* @return {Array} Array of unwrapped dependent keys
*/
function unwrapBraceExpressions(dependentKeys) {
Copy link
Member

Choose a reason for hiding this comment

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

And perhaps this

* @return {Array} Array of unwrapped dependent keys
*/
function parseDependentKeys(callExp) {
const isMemberExpCallExp = callExp.arguments.length === 0 && callExp.callee.object;
Copy link
Member

Choose a reason for hiding this comment

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

I'd add comment above why do we check this. I was confused at first and then I saw a case with .volatile in tests.

You should also check it rather like so:

!callExp.arguments.length &&
isMemberExpression(callExp.callee) &&
isCallExpression(callExp.callee.object)

const dependentKeys = args
.filter(arg => isLiteral(arg))
.map(literal => literal.value);
return unwrapBraceExpressions(dependentKeys);
Copy link
Member

Choose a reason for hiding this comment

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

Add empty line before return

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 point, we should probably configure it in the project's eslint I think

Copy link
Member

Choose a reason for hiding this comment

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

yup, feel free to add it :)

return properties.map(property => `${prefix}.${property}`);
});

return unwrappedExpressions
Copy link
Member

Choose a reason for hiding this comment

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

What if you have dependent key like: lorem.ipsum.{dolor,sit}? I think this function will return:

[
  'lorem.ipsum'
]

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 point!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

on the other hand, this will not work in Ember, as only one level of nesting is supported, WDYT @michalsnik?

Copy link
Member

Choose a reason for hiding this comment

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

This works actually @jbandura, only multi-level braces nesting is not allowed. See:
https://ember-twiddle.com/57f5af38632a6770fcae0c0904c07e08?openFiles=controllers.application.js%2C

{
code: `
{
foo: computed('model.foo', 'model.bar', 'model.baz', function() {})
Copy link
Member

Choose a reason for hiding this comment

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

We should test more cases, those with @each and [] too. People tend to create really crazy dependent keys and we need to make sure we support all of those weird cases, so I recommend to enlarge the test suite for this rule significantly :) WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, will do 👍

Add support for unwrapping keys with .@each and .[] along with multiple
nesting
@jbandura
Copy link
Collaborator Author

fleshed out the test suite + added support for more complex dependent keys, let me know what you think @michalsnik :)

…slint-plugin-ember into 59-no-duplicate-dependent-keys
@kevinkucharczyk
Copy link
Contributor

Looks like we have some conflicts, please take care of them :)

@Turbo87
Copy link
Member

Turbo87 commented Aug 3, 2017

@michalsnik I'd prefer it if we could rebase this branch on master instead of merging master in. otherwise we'll end up with a very complicated history graph in git.

@michalsnik
Copy link
Member

@Turbo87 I'm squashing PRs while merging anyway, so master's history will not be disrupted :)

@Turbo87
Copy link
Member

Turbo87 commented Aug 4, 2017

@michalsnik I'm not a huge fan of squashing commits since it makes git bisect much less useful

@michalsnik
Copy link
Member

michalsnik commented Aug 4, 2017

@Turbo87 I get it, on the other hand squased PRs result in much cleaner history. I don't remember the need of digging into single commits inside PRs - those are usually not so big anyway and squashed are well-contained and easier to grasp. Knowing which PR broke something was more than enough in my case. Single commits inside PRs are often not too descriptive and contain bunch of bugs resolved by further commits inside the same PR..

docs: {
description: 'Disallow repeating dependent keys',
category: 'General',
recommended: true
Copy link
Member

@michalsnik michalsnik Aug 7, 2017

Choose a reason for hiding this comment

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

Please make it not recommended, so we can do a minor release first. I didn't catch this earlier

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@michalsnik michalsnik merged commit 606b2c9 into master Aug 7, 2017
@michalsnik michalsnik deleted the 59-no-duplicate-dependent-keys branch August 7, 2017 12:55
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