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

Update: add fixer for prefer-arrow-callback (fixes #7002) #7004

Merged
merged 1 commit into from Sep 8, 2016

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Aug 29, 2016

What issue does this pull request address?
#7002

What changes did you make? (Give an overview)

This allows errors reported by the prefer-arrow-callback rule to be autofixed, matching the behavior described in #7002.

Is there anything you'd like reviewers to focus on?

I'm unsure about whether this check is correct. The intention is to detect whether the current parser configuration supports arrow functions, to avoid causing SyntaxErrors if ES6-mode is off. However, there might be a better/more complete way to do this.

#7002 has not been marked as accepted, so this PR should not be merged yet. (edit: #7002 is now marked as accepted.)

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the annotation information on this pull request, we identified @kaicataldo, @mysticatea and @vitorbal to be potential reviewers

@eslintbot
Copy link

LGTM

@platinumazure platinumazure added the do not merge This pull request should not be merged yet label Aug 29, 2016
@platinumazure
Copy link
Member

Marking "do not merge" since issue has not yet been accepted.

fix(fixer) {

// FIXME: Is there a better way to detect parser support for arrow functions?
if (!context.parserOptions || !context.parserOptions.ecmaVersion || context.parserOptions.ecmaVersion < 6) {
Copy link
Member

Choose a reason for hiding this comment

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

It's unnecessary, I think.
Developers always can disable this rule.

Other ES2015 rules (e.g. no-var, prefer-const) also don't check the language version.

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case, should I just use parserOptions: { ecmaVersion: 6 } for all the tests?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@eslintbot
Copy link

LGTM

* @param {ASTNode[]} paramsList The list of parameters for a function
* @returns {boolean} `true` if the list of parameters contains any duplicates
*/
function hasDuplicateParams(paramsList) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This should probably be replaced with a function like the one described here.

The current implementation will work in all cases where the function body has valid syntax, but it will fail in certain cases with complex parameter lists due to the parser bug described here.

foo(function(a, a = 5) { }) // the parser incorrectly considers this to be valid.

foo((a, a = 5) => { }) // the parser correctly considers this to be invalid.

Copy link
Member

Choose a reason for hiding this comment

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

I think this implementation is no problem.
Acorn should be fixed about the duplication error of non-simple parameters.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in Acorn: acornjs/acorn#457

@eslintbot
Copy link

LGTM

@nzakas nzakas removed the do not merge This pull request should not be merged yet label Sep 3, 2016
@nzakas
Copy link
Member

nzakas commented Sep 3, 2016

Issue is now accepted, so removing "do not merge".

@nzakas
Copy link
Member

nzakas commented Sep 7, 2016

LGTM.

@mysticatea ?

@mysticatea
Copy link
Member

LGTM.

@mysticatea mysticatea merged commit 883316d into eslint:master Sep 8, 2016
@not-an-aardvark not-an-aardvark deleted the issue7002 branch September 9, 2016 05:27
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 6, 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.

None yet

7 participants