-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add UseAssertIn lint rule to Fixit #159
Conversation
96bdcb6
to
da76a5e
Compare
@jimmylai PTAL.
But it works fine locally when I run isort manually. |
@mvismonte PTAL! |
You can fix the error by sorting the imports properly using command |
da76a5e
to
eb6baaa
Compare
@jimmylai thanks that did the trick. However, it looks like the builds are still failing b/c of a test in another rule:
Seems like autofix is replacing the first |
It's likely caused by a new change in new version of LibCST. There is a fix that @zsol is working on Instagram/LibCST#423. For now, to unblock this PR, we can pin LibCST version to the previous stable version |
fixit/rules/use_assert_in.py
Outdated
|
||
class UseAssertInRule(CstLintRule): | ||
""" | ||
Discourages use of ``assertTrue(x in y)`` and ``assertFalse(x in y)`` as it is deprecated (https://docs.python.org/3.8/library/unittest.html#deprecated-aliases). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use reStructuredText here; please wrap to a reasonable line length too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shortened the string length.
fixit/rules/use_assert_in.py
Outdated
Use ``assertIn(x, y)`` and ``assertNotIn(x, y)``) instead. | ||
""" | ||
|
||
ONCALL_SHORTNAME = "instagram_server_framework" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't in the open-source version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for catching. removed.
if m.matches( | ||
node, | ||
m.Call( | ||
func=m.Attribute(value=m.Name("self"), attr=m.Name("assertTrue")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is based on some pre-existing code, but I think you can do this more effectively with a single extract; save whether you see the couple of places "not" could be, whether the method is assertTrue or assertFalse, and construct once with the xor of those 3 without a page of if
statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense.
this was taken from the internal rule though. i'll leave it for now so there's consistency between both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, use a single extract can be more effective and that can leave as future work. @dkteo can you add a # TODO:
comment to the code as a note?
Also, once this is merged, we'll want to remove the internal copy to avoid duplication since this will be released to internal dev environment.
8ae4fde
to
00558e1
Compare
Codecov Report
@@ Coverage Diff @@
## master #159 +/- ##
==========================================
+ Coverage 84.71% 84.99% +0.28%
==========================================
Files 86 88 +2
Lines 3532 3613 +81
==========================================
+ Hits 2992 3071 +79
- Misses 540 542 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Overall LGTM. Just some comments.
requirements.txt
Outdated
@@ -1,3 +1,3 @@ | |||
flake8>=3.8.1 | |||
libcst>=0.3.10 | |||
libcst>=0.3.13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do!
if m.matches( | ||
node, | ||
m.Call( | ||
func=m.Attribute(value=m.Name("self"), attr=m.Name("assertTrue")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, use a single extract can be more effective and that can leave as future work. @dkteo can you add a # TODO:
comment to the code as a note?
Also, once this is merged, we'll want to remove the internal copy to avoid duplication since this will be released to internal dev environment.
00558e1
to
0434d2c
Compare
@jimmylai I've addressed the comments but am unable to merge b/c I don't have write access to the repo. Could you help me merge the PR? Thanks! |
Co-authored-by: Jimmy Lai <[email protected]>
@dkteo, thanks for contributing! |
Summary
assertIn/assertNotIn
.assertTrue(x in y)/assertFalse(x in y)
which is deprecated in Py3.8. See deprecated rulesTest Plan
Ran
tox -e py38 -- fixit.tests.UseAssertInRule
Ran
tox -e autofix