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 fix for "no-confusing-arrow" rule #8347

Merged
merged 1 commit into from Apr 20, 2017

Conversation

tikotzky
Copy link
Contributor

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[X] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)
Added a fix function to no-confusing-arrow which will auto wrap an arrow function body if allowParens is set to true.

Is there anything you'd like reviewers to focus on?
I'm doing an early return from the fix if allowParens not enabled, can you please advise if it acceptable to return undefined from the fix function in such a case.
(my testing seems to indicate that its fine, just wanted to double check)

@mention-bot
Copy link

@tikotzky, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @lukekarrys and @mysticatea to be potential reviewers.

@eslintbot
Copy link

LGTM

@jsf-clabot
Copy link

jsf-clabot commented Mar 28, 2017

CLA assistant check
All committers have signed the CLA.

@tikotzky tikotzky force-pushed the add-fix-for-no-confusing-arrow branch from 8a2a502 to e77c0db Compare March 28, 2017 20:38
@eslintbot
Copy link

LGTM

@platinumazure
Copy link
Member

Hi @tikotzky, thanks for your PR!

Returning undefined from a fixer function is okay.

@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Mar 29, 2017
@tikotzky
Copy link
Contributor Author

Thanks for the info.
I changed it so that its not actually returning undefined, rather its returning a falsy value.
I can update to explicitly return undefined if that is desired.

Also, I was not able to find how/where to add tests for the fixer functions. If you give a pointer i'd be glad to add some tests.

@platinumazure
Copy link
Member

@tikotzky We usually just use return; in fixers, but I personally don't have a problem with anything more specific.

Thanks for the note about fixer tests. Here's what you need to know:

  • Unit test files for rules are found in tests/lib/rules and are named the same as the rule.
  • We provide a RuleTester class for testing rules on code snippets.
  • You can test the output of a fixer by adding an output property to an invalid test object.
    • I'm now seeing this isn't in our documentation. That's not good! Sorry for the missing docs; in the meanwhile, you can use this example to get started for your use case.
    • You can probably just add output to the relevant invalid test cases. But feel free to create new test cases if you think they will help!

By the way, I wanted to mention that we have a process for accepting enhancements, so definitely feel free to wait until the issue is marked "accepted" if you want (to avoid possibly wasting your time if we don't accept the issue). That said, having an implementation and tests can also help persuade the team to accept an issue, so there's an incentive to finish up as well. Go figure! 😜

@eslint/eslint-team This seems like a pretty simple autofix enhancement request (only autofixing a very simple case under specific options). Anyone want to support this? I'll champion.

@platinumazure platinumazure self-assigned this Mar 29, 2017
@not-an-aardvark
Copy link
Member

It is documented here, but I think the documentation for RuleTester is split between "working with rules" and "working with plugins", which is probably confusing.

@tikotzky tikotzky force-pushed the add-fix-for-no-confusing-arrow branch from e77c0db to 606cad9 Compare March 29, 2017 04:53
@eslintbot
Copy link

LGTM

@tikotzky
Copy link
Contributor Author

thanks @platinumazure, I am aware of the process. Adding tests looks easy (and fun 😄) so I gave it a shot.
thank you both for the pointers!
I was able to add some tests let me know if there is anything else I can add/change to this PR.

@platinumazure
Copy link
Member

Awesome work @tikotzky. Just one thing-- as of ESLint 3.17.0, you can now use output: null to indicate that a test case should not apply fixes. Personally I find that more readable than using the same output string.

Thanks for augmenting the test cases!

@tikotzky tikotzky force-pushed the add-fix-for-no-confusing-arrow branch from 606cad9 to d221dce Compare March 29, 2017 05:03
@eslintbot
Copy link

LGTM

@tikotzky
Copy link
Contributor Author

yup I agree that output: null is nicer.
updated and pushed 😄

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR! Sorry for not reviewing this sooner. Hopefully we can merge this as soon as the PR is accepted.

@platinumazure platinumazure added the do not merge This pull request should not be merged yet label Apr 17, 2017
@platinumazure
Copy link
Member

Adding "do not merge" until this accepted. PR looks good from an implementation standpoint, though!

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion and removed do not merge This pull request should not be merged yet evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Apr 18, 2017
@platinumazure
Copy link
Member

Now we have enough support to accept this, so I've labeled accordingly.

@eslint/eslint-team I'd love a second set of eyes on this just to be sure all looks well, can someone else review?

Copy link
Member

@gyandeeps gyandeeps left a comment

Choose a reason for hiding this comment

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

Please update the docs for this rule for the fix functionality.

@not-an-aardvark
Copy link
Member

@gyandeeps It's not necessary to manually add the header line anymore because it's autogenerated from metadata.

@platinumazure
Copy link
Member

@gyandeeps @not-an-aardvark Do we still want a note about the limited nature of the auto-fix somewhere?

@gyandeeps
Copy link
Member

Opps you right @not-an-aardvark . But i think its good to have a note for its limited nature.

@kaicataldo
Copy link
Member

LGTM. Thanks for contributing to ESLint!

@kaicataldo kaicataldo merged commit 53fefb3 into eslint:master Apr 20, 2017
@tikotzky tikotzky deleted the add-fix-for-no-confusing-arrow branch April 20, 2017 22:32
@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
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants