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

Issue #506 #526

Merged
merged 19 commits into from
Mar 27, 2019
Merged

Issue #506 #526

merged 19 commits into from
Mar 27, 2019

Conversation

SizovIgor
Copy link
Contributor

@SizovIgor SizovIgor commented Mar 27, 2019

Forbid multiline conditions, closes #506

@coveralls
Copy link

coveralls commented Mar 27, 2019

Pull Request Test Coverage Report for Build 1162

  • 12 of 12 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1147: 0.0%
Covered Lines: 2544
Relevant Lines: 2544

💛 - Coveralls

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

The main thing with this PR is that it introduces too many changes.
Please, fix your diffs and address my comments.

Thanks a lot for your hard-work! I really appreciate that. 🚀


incorrect_or_conditions1 = """
if some or (
other==1
Copy link
Member

Choose a reason for hiding this comment

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

other == 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Complete

other,
):
...
"""
Copy link
Member

Choose a reason for hiding this comment

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

Please, also include:

  1. Correct conditions with multiple and and or
  2. Correct conditions with () like function calls, prioritisation, and tuples
  3. Incorrect conditions for multiple lines: 2, 3 and 4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Complete


error_template = 'Found nested `try` block'
code = 464
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

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

This diff is incorrect, please fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


for violation in IGNORED_VIOLATIONS:
assert stdout.count(violation) > 0
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

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

This diff is incorrect, please fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

raise TypeError('Second')
except TypeError:
print('WTF?')
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

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

This diff is incorrect, please fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Forbids to use magic numbers in your code.

What we call a "magic number"? Well, it is actually any number that
appears in your code ou
Copy link
Member

Choose a reason for hiding this comment

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

Also: use variables.

Forbids to use magic numbers in your code.

What we call a "magic number"? Well, it is actually any number that
appears in your code ou
Copy link
Member

Choose a reason for hiding this comment

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

0.9.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Complete

self._check_negated_conditions(node)
self._check_redundant_else(node)
self.generic_visit(node)
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

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

This diff is incorrect, please fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


def _check_multiline_conditions(self, node: ast.If) -> None:
"""Checks multiline conditions ``if`` statement nodes."""
if isinstance(node.test, ast.BoolOp):
Copy link
Member

Choose a reason for hiding this comment

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

In this case you are ignoring cases like:

if very_long_call_name(
    long_parameter_name=long_variable_name,
):

Please, make sure it is covered and tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change and tested it

Copy link
Contributor Author

@SizovIgor SizovIgor left a comment

Choose a reason for hiding this comment

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

Complete. Please, review

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Almost ready, just two minor comments.
Awesome refactoring work. Thanks a lot!

@@ -378,3 +378,40 @@ def bad_default_values( # noqa: Z459
raise TypeError('Second')
except TypeError:
print('WTF?')

if some and ( # noqa: Z465
Copy link
Member

Choose a reason for hiding this comment

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

There's no need in putting all of these cases inside noqa.py.
It only contains integration tests. One is enough.
Move other cases into unit tests.

@@ -151,6 +151,7 @@ def test_noqa_fixture_disabled(absolute_path, all_violations):
'Z462': 1,
'Z463': 1,
'Z464': 1,
'Z465': 5,
Copy link
Member

Choose a reason for hiding this comment

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

1

"""

correct_conditions3 = """
if (some_func(k) and some) or other in (1,2,3):
Copy link
Member

Choose a reason for hiding this comment

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

Please, add:

correct_conditions4 = """
if one:
    if two:
         ...
"""

Copy link
Contributor Author

@SizovIgor SizovIgor left a comment

Choose a reason for hiding this comment

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

I did it.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

@shok9894 congrats! 🎉

Please, take other tasks if you want to.

@sobolevn sobolevn merged commit 8459040 into wemake-services:master Mar 27, 2019
@SizovIgor SizovIgor deleted the issue-#506 branch March 28, 2019 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forbid multiline conditions
3 participants