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: the `prefer-reflect` rule (fixes #2939) #2996

Merged
merged 1 commit into from Jul 17, 2015

Conversation

Projects
None yet
4 participants
@keithamus
Copy link
Contributor

commented Jul 14, 2015

This PR adds a rule to warn when the user is using "effectively deprecated" methods - which Reflect.* replaces, as discussed in #2939. Fixes #2939.

As the docs/tests suggest, each section can be disabled - meaning the user can configure this how they need to, for example if they want to use reflect for all but the delete operator, then they can configure it as [2, "delete"].

Let me know if you need anything else from me to merge this.

Oh, also, so close!
screen shot 2015-07-15 at 00 22 52

]
},
{
code: "(function(){}).apply(null, 1, 2)",

This comment has been minimized.

Copy link
@nzakas

nzakas Jul 15, 2015

Member

Apply only takes two arguments.

@nzakas

This comment has been minimized.

Copy link
Member

commented Jul 15, 2015

Overall looks good. I would like to change the options to be more in line with how we've defined exceptions in other rules. I can see two possible options:

prefer-reflect: [2, { exceptions: [ "delete"]}]

prefer-reflect: [2, { delete: false}]

Kinda leaning towards the second, but could be convinced otherwise.

@michaelficarra

This comment has been minimized.

Copy link
Member

commented Jul 15, 2015

@nzakas The second permits a tri-state with different falsey values (false and undefined) meaning different things. That's not a good interface in my opinion.

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2015

I went more inline with a ruleset similar to no-restricted-modules. I'm happy to change it to the first example you show though.

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2015

Rebased, fixed tests and changed rule options to be {exceptions: [...]} as per @nzakas instruction

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2015

io.js travis build seems to be stuck, but I cant stop or restart it: https://travis-ci.org/eslint/eslint/jobs/71037738

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2015

Failure is down to travis timing out trying to install iojs:

$ nvm install iojs
                                                                           0.4%
Your test run exceeded 120 minutes. 
One possible solution is to split up your test run.

Force pushed to trigger a new build. Should pass now.

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2015

Oops, forgot to update docs in respect to change to using {exceptions:[]} syntax.

Docs updated now. This should be good to go.


var exceptions = (context.options[0] || {}).exceptions || [];

function report(node, existing, substitute) {

This comment has been minimized.

Copy link
@nzakas

nzakas Jul 15, 2015

Member

Please add JSDoc comments here

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2015

Added jsdoc block for report function.

@nzakas is there anything else you'd like me to change?

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2015

Fixed lint errors JSDoc.

},
{
code: "Object.isExtensible({})",
args: [2, { exceptions: "apply" }],

This comment has been minimized.

Copy link
@nzakas

nzakas Jul 16, 2015

Member

Can you use options instead of args?

options: [{exceptions: "apply"}]

You can leave off the initial 2, and any place with args: 2 can just be removed.

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2015

All done @nzakas. Anything else?


If you want to use Reflect methods, but keep using the `delete` keyword, then your config would look like `prefer-reflect: [2, { exceptions: ["delete"]] }`.

These can be combined as much as you like. To make all methods exceptions (thereby rendering this rule useless), use `prefer-reflect: [2, { exceptions: ["apply }", "call]", "defineProperty", "getOwnPropertyDescriptor", "getPrototypeOf", "setPrototypeOf", "isExtensible", "getOwnPropertyNames", "preventExtensions", "delete"]`

This comment has been minimized.

Copy link
@ilyavolodin

ilyavolodin Jul 16, 2015

Member

I think there's an extra closing brace inside the array and one missing at the end of the line.

@ilyavolodin

This comment has been minimized.

Copy link
Member

commented Jul 16, 2015

LGTM. Btw, awesome documentation!

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2015

😄 thanks @ilyavolodin


The `exceptions` option allows you to pass an array of methods names you'd like to continue to use in the old style.

For example if you wish to use all Reflect methods, except for `Function.prototype.apply` then your config would look like `prefer-reflect: [2, { exceptions: ["apply"]] }`.

This comment has been minimized.

Copy link
@ilyavolodin

ilyavolodin Jul 16, 2015

Member

Closing square brace is in the wrong place.


For example if you wish to use all Reflect methods, except for `Function.prototype.apply` then your config would look like `prefer-reflect: [2, { exceptions: ["apply"]] }`.

If you want to use Reflect methods, but keep using the `delete` keyword, then your config would look like `prefer-reflect: [2, { exceptions: ["delete"]] }`.

This comment has been minimized.

Copy link
@ilyavolodin

ilyavolodin Jul 16, 2015

Member

Here too

@nzakas

This comment has been minimized.

Copy link
Member

commented Jul 17, 2015

Can you rebase?

@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 17, 2015

Rebased @nzakas

@ilyavolodin

This comment has been minimized.

Copy link
Member

commented Jul 17, 2015

Thanks @keithamus for sticking with this!

ilyavolodin added a commit that referenced this pull request Jul 17, 2015

Merge pull request #2996 from keithamus/feature-prefer-reflect
New: the `prefer-reflect` rule (fixes #2939)

@ilyavolodin ilyavolodin merged commit fb33c63 into eslint:master Jul 17, 2015

2 checks passed

continuous-integration/appveyor AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@keithamus

This comment has been minimized.

Copy link
Contributor Author

commented Jul 17, 2015

🎉

@keithamus keithamus deleted the keithamus:feature-prefer-reflect branch Jul 17, 2015

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.