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 new no-get-properties rule #403

Merged
merged 1 commit into from Apr 12, 2019
Merged

Add new no-get-properties rule #403

merged 1 commit into from Apr 12, 2019

Conversation

bmish
Copy link
Member

@bmish bmish commented Apr 7, 2019

No description provided.

@bmish bmish requested a review from Turbo87 April 7, 2019 00:09
'const { abc } = getProperties(this, MY_PROP);',
'const { abc } = getProperties(this, [MY_PROP]);'
],
invalid: [
Copy link
Member

Choose a reason for hiding this comment

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

can you add a test case for e.g. this.getProperties('while')? this should not convert to let { while } = ... since that would be illegal. but then again, this rule only triggers when there was already destructuring used before, right?

(see also https://github.com/rondale-sc/es5-getter-ember-codemod/blob/6e7929832301485ff15c0f4384363a1040eabb5c/transforms/es5-getter-ember-codemod/index.js#L3-L7)

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting! However, I don't think that applies here, because this rule is only suggesting removing the getProperties call, and not changing the existing destructuring.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

FWIW, applying this rule across the board is not "safe".

Specifically, destructuring from any object that is an Ember.ObjectProxy, an Ember.ArrayProxy, or any object with an unknownProperty method will result in an error. The documentation for the new rule should be updated to include this information.

I believe the rule should only apply to this.getProperties and getProperties(this, ...) by default (calling someForeignObject.getProperties is much more problematic due to the exceptions I mentioned above).

@bmish
Copy link
Member Author

bmish commented Apr 9, 2019

@rwjblue thanks for the reminder about proxies! I removed the autofixer as a result. I also updated the documentation to call that out.

However, I would prefer if the rule continues to catch someForeignObject.getProperties, because:

  • It no longer autofixes
  • es5-getter-ember-codemod currently converts that (the codemod isn't limited to this only)

How does that sound?

@bmish bmish changed the title Add new no-unnecessary-get-properties rule Add new no-get-properties rule Apr 9, 2019
@Turbo87
Copy link
Member

Turbo87 commented Apr 9, 2019

I would propose to keep the autofixer, but make the rule configurable. By default it would only work for this, but you could either configure other variable names for which it should also work, or you define a wildcard or something like that 🤔

Copy link
Member

rwjblue commented Apr 9, 2019

es5-getter-ember-codemod currently converts that (the codemod isn't limited to this only)

There are a number of reported issues on that repo around this exact issue. The codemod absolutely should be restricted to this.

@bmish
Copy link
Member Author

bmish commented Apr 9, 2019

@rwjblue thanks for calling that out, I updated this rule to be limited to this.getProperties only.

@Turbo87 I would still lean towards leaving the autofixer out because:

  • If someone wants to fix violations, they can run the codemod.
  • Even when the rule is limited to this.getProperties only, it still can easily cause breaking behavior changes because of proxy objects / unknownProperty.

However, I'd like to follow-up in a separate PR to add an catchForeignObjects boolean configuration property (default false) to this rule for those who want to be more aggressive.

@bmish bmish mentioned this pull request Apr 10, 2019
Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

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

👍

@bmish bmish merged commit 2fa1e08 into ember-cli:master Apr 12, 2019
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.

None yet

3 participants