Skip to content

Commit

Permalink
feat: implementing the new rule. Build yet to be debugged. Issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Mael MADON authored and Mema5 committed Feb 24, 2020
1 parent 44f757e commit c02aa31
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions wemake_python_styleguide/visitors/tokenize/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class WrongStringTokenVisitor(BaseTokenVisitor):

_implicit_raw_strigns: ClassVar[Pattern] = re.compile(r'\\{2}.+')

_contains_backslash: ClassVar[Pattern] = re.compile(r'\\')

def __init__(self, *args, **kwargs) -> None:
"""Initializes new visitor and saves all docstrings."""
super().__init__(*args, **kwargs)
Expand All @@ -165,12 +167,14 @@ def visit_string(self, token: tokenize.TokenInfo) -> None:
WrongMultilineStringViolation
ImplicitRawStringViolation
WrongUnicodeEscapeViolation
RawStringNotNeededViolation
"""
self._check_correct_multiline(token)
self._check_string_modifiers(token)
self._check_implicit_raw_string(token)
self._check_wrong_unicode_escape(token)
self._check_unnecessary_raw_string(token)

def _check_correct_multiline(self, token: tokenize.TokenInfo) -> None:
_, string_def = split_prefixes(token)
Expand Down Expand Up @@ -231,6 +235,15 @@ def _check_wrong_unicode_escape(self, token: tokenize.TokenInfo) -> None:
# character can never be the start of a new backslash escape.
index += 2

def _check_unnecessary_raw_string(self, token: tokenize.TokenInfo) -> None:
modifiers, string_def = split_prefixes(token)

if 'r' in modifiers.lower():
if not self._contains_backslash.search(string_def):
self.add_violation(
RawStringNotNeededViolation(token, text=token.string),
)


@final
class WrongStringConcatenationVisitor(BaseTokenVisitor):
Expand Down

0 comments on commit c02aa31

Please sign in to comment.