Skip to content

New: the prefer-reflect rule (fixes #2939) - #2996

Merged
ilyavolodin merged 1 commit into
eslint:masterfrom
keithamus:feature-prefer-reflect
Jul 17, 2015
Merged

New: the prefer-reflect rule (fixes #2939)#2996
ilyavolodin merged 1 commit into
eslint:masterfrom
keithamus:feature-prefer-reflect

Conversation

@keithamus

Copy link
Copy Markdown
Contributor

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

Comment thread tests/lib/rules/prefer-reflect.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apply only takes two arguments.

@nzakas

nzakas commented Jul 15, 2015

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

@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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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

@keithamus

Copy link
Copy Markdown
Contributor Author

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

@keithamus

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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

Docs updated now. This should be good to go.

Comment thread lib/rules/prefer-reflect.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add JSDoc comments here

@keithamus

Copy link
Copy Markdown
Contributor Author

Added jsdoc block for report function.

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

@keithamus

Copy link
Copy Markdown
Contributor Author

Fixed lint errors JSDoc.

Comment thread tests/lib/rules/prefer-reflect.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

All done @nzakas. Anything else?

Comment thread docs/rules/prefer-reflect.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@ilyavolodin

Copy link
Copy Markdown
Member

LGTM. Btw, awesome documentation!

@keithamus

Copy link
Copy Markdown
Contributor Author

😄 thanks @ilyavolodin

Comment thread docs/rules/prefer-reflect.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Closing square brace is in the wrong place.

@nzakas

nzakas commented Jul 17, 2015

Copy link
Copy Markdown
Member

Can you rebase?

@keithamus

Copy link
Copy Markdown
Contributor Author

Rebased @nzakas

@ilyavolodin

Copy link
Copy Markdown
Member

Thanks @keithamus for sticking with this!

ilyavolodin added a commit that referenced this pull request Jul 17, 2015
@ilyavolodin
ilyavolodin merged commit fb33c63 into eslint:master Jul 17, 2015
@keithamus

Copy link
Copy Markdown
Contributor Author

🎉

@keithamus
keithamus deleted the feature-prefer-reflect branch July 17, 2015 13:48
@eslint-deprecated eslint-deprecated Bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated Bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

archived due to age This issue has been archived; please open a new issue for any further discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule Proposal: prefer-reflect

4 participants