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

Implement TypeOf matcher #384

Merged
merged 5 commits into from
Sep 10, 2020
Merged

Conversation

isidentical
Copy link
Contributor

Summary

Implemented a matcher for matching concrete types (instead of instances);

m.OneOf(
    m.BinaryOperation(left=m.Call(func=m.Name("foo"))),
    m.BooleanOperation(left=m.Call(func=m.Name("foo"))),
)

would be equal to

pattern = (m.BinaryOperation | m.BooleanOperation)(
    left=m.Call(func=m.Name("foo"))
)

Test Plan

  • Added unittests to cover mostly everything

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 5, 2020
@zsol zsol requested a review from jimmylai September 6, 2020 08:40
@zsol
Copy link
Member

zsol commented Sep 6, 2020

I'll leave this to @jimmylai as I'm not at all familiar with matcher implementations.

Copy link
Contributor

@jimmylai jimmylai left a comment

Choose a reason for hiding this comment

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

Excellent! This can make the operator node matcher patterns simpler.
The code quality is really good with high test coverage.
Just some comments.

CHANGELOG.md Outdated Show resolved Hide resolved
libcst/matchers/__init__.py Show resolved Hide resolved
libcst/matchers/_matcher_base.py Show resolved Hide resolved
libcst/matchers/_matcher_base.py Show resolved Hide resolved
libcst/matchers/tests/test_matchers.py Show resolved Hide resolved
libcst/matchers/_matcher_base.py Show resolved Hide resolved
@jimmylai jimmylai merged commit 6ae2583 into Instagram:master Sep 10, 2020
@isidentical
Copy link
Contributor Author

Thanks for the merge @jimmylai! This would definitely help me in the future for writing Fixit rules [when the new version got released and linked to the Fixit]

@jimmylai
Copy link
Contributor

Thanks for the merge @jimmylai! This would definitely help me in the future for writing Fixit rules [when the new version got released and linked to the Fixit]

@isidentical , you're very welcome. Thank you for your contribution. Look forward to see more cool autofixers from you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants