Skip to content

Commit

Permalink
Fixes build
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Feb 24, 2020
1 parent 53ae135 commit e43c5bd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@
# Correct:

correct_newline = 'print(1)\nprint(2)'
correct_string_composed = 'some_string = "\r"'
correct_nl = 'print(1,\n 2)'
correct_string = '"\r"'
correct_raw_string = 'r"\r"'
correct_real_newline = """
print(1)
print(2)
"""

# Wrong:

wrong_newline_single = 'print(1)\rprint(2)'
wrong_newline_sequenced = 'print(1)\r\nprint(2)'
wrong_newline_in_multiline = """print(1)\rprint(2)\r
print(3).
wrong_newline_single = 'print(1)\r\nprint(2)'
wrong_newline_sequenced1 = 'print(1)\nprint(2)\r\n'
wrong_newline_sequenced2 = 'print(1)\r\nprint(2)\n'
wrong_newline_sequenced3 = 'print(1,\r\n 2)'
wrong_newline_in_multiline = """print(2)\r
print(3)
"""


@pytest.mark.parametrize('code', [
wrong_newline_single,
wrong_newline_sequenced,
wrong_newline_sequenced1,
wrong_newline_sequenced2,
wrong_newline_sequenced3,
wrong_newline_in_multiline,
])
def test_string_wrong_line_breaks(
Expand All @@ -47,7 +57,10 @@ def test_string_wrong_line_breaks(

@pytest.mark.parametrize('code', [
correct_newline,
correct_string_composed,
correct_nl,
correct_string,
correct_raw_string,
correct_real_newline,
])
def test_string_proper_line_breaks(
parse_tokens,
Expand Down
4 changes: 3 additions & 1 deletion wemake_python_styleguide/violations/oop.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ class UselessOverwrittenMethodViolation(ASTViolation):
# Correct:
class Test(Base):
...
def method(self, argument):
super().method(argument)
return argument # or None, or anything!
# Wrong:
class Test(object):
Expand Down
9 changes: 7 additions & 2 deletions wemake_python_styleguide/visitors/tokenize/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
MissingSpaceBetweenKeywordAndParenViolation,
)
from wemake_python_styleguide.visitors.base import BaseTokenVisitor
from wemake_python_styleguide.visitors.decorators import alias


@final
@alias('visit_any_newline', (
'visit_newline',
'visit_nl',
))
class WrongKeywordTokenVisitor(BaseTokenVisitor):
"""Visits keywords and finds violations related to their usage."""

Expand All @@ -37,7 +42,7 @@ def visit_dot(self, token: tokenize.TokenInfo) -> None:
"""
self._check_line_starts_with_dot(token)

def visit_newline(self, token: tokenize.TokenInfo) -> None:
def visit_any_newline(self, token: tokenize.TokenInfo) -> None:
r"""
Checks ``\r`` (carriage return) in line breaks.
Expand All @@ -64,5 +69,5 @@ def _check_line_starts_with_dot(self, token: tokenize.TokenInfo) -> None:
def _check_line_comprise_carriage_return(
self, token: tokenize.TokenInfo,
) -> None:
if token.string.startswith('\r') and token.line.endswith('\r'):
if '\r' in token.string:
self.add_violation(LineCompriseCarriageReturnViolation(token))

0 comments on commit e43c5bd

Please sign in to comment.