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 NoReduntantLambdaFunction #112

Merged
merged 3 commits into from
Sep 4, 2020

Conversation

isidentical
Copy link
Contributor

I am not sure whether this tool itself accepts new rules or not, I just wanted to play with it a little bit so drafted a PR, if the built-in ruleset is intended to kept only for 'selected' rules, it is OK to close this PR.

Summary

  • Implements a lint rule for 'redundant lambda wrapping'.
    The pattern mostly happens on function compositions, like Pool.execute(<func>) or even map.
def square(x):
    return x ** 2
map(lambda x: square(x), [1,2,3,4])

becomes

def square(x):
    return x ** 2
map(square, [1,2,3,4])

Test Plan

I've added both valid and invalid test cases, not sure if more are needed.

@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 3, 2020
@jimmylai
Copy link
Contributor

jimmylai commented Sep 3, 2020

@isidentical new rules are definite welcome, especially those generic rules that can make code cleaner, safer or more efficient.

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.

Thanks for contributing! This is a very useful autofixer which can make the code simpler and more efficient!
I was able to easily find hundreds of violations in our codebase.
Just some minor change requests.

fixit/rules/no_redundant_lambda.py Outdated Show resolved Hide resolved
fixit/rules/no_redundant_lambda.py Outdated Show resolved Hide resolved
fixit/rules/no_redundant_lambda.py Show resolved Hide resolved
@isidentical isidentical requested a review from jimmylai September 4, 2020 22:19
@jimmylai
Copy link
Contributor

jimmylai commented Sep 4, 2020

Looks awesome!

@jimmylai jimmylai merged commit 0c292a2 into Instagram:master Sep 4, 2020
@isidentical
Copy link
Contributor Author

isidentical commented Sep 4, 2020

Looks awesome!

Wow, Thanks! (You are so fast!)

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.

3 participants