From 7004708c968440f94d9583c2a6154d8bc50844a4 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 20 Oct 2018 17:08:01 -0700 Subject: Fix line offset for 'invalid escape sequence' --- CONTRIBUTING.rst | 2 +- pycodestyle.py | 3 ++- testsuite/W60.py | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f55c5e9..18b5a88 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -62,7 +62,7 @@ All the tests should pass for all available interpreters, with the summary of:: congratulations :) -At this point you can create a pull request back to the official pycodestyles +At this point you can create a pull request back to the official pycodestyle repository for review! For more information on how to make a pull request, GitHub has an excellent `guide`_. diff --git a/pycodestyle.py b/pycodestyle.py index 0d725d2..8b608b0 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1522,6 +1522,7 @@ def python_3000_invalid_escape_sequence(logical_line, tokens): for token_type, text, start, end, line in tokens: if token_type == tokenize.STRING: + orig_start = start quote = text[-3:] if text[-3:] in ('"""', "'''") else text[-1] # Extract string modifiers (e.g. u or r) quote_pos = text.index(quote) @@ -1535,7 +1536,7 @@ def python_3000_invalid_escape_sequence(logical_line, tokens): pos += 1 if string[pos] not in valid: yield ( - line.lstrip().find(text), + orig_start, "W605 invalid escape sequence '\\%s'" % string[pos], ) diff --git a/testsuite/W60.py b/testsuite/W60.py index 030bec5..3f1b77c 100644 --- a/testsuite/W60.py +++ b/testsuite/W60.py @@ -19,6 +19,10 @@ regex = '\.png$' regex = ''' \.png$ ''' +#: W605:2:5 +f( + '\_' +) #: Okay regex = r'\.png$' regex = '\\.png$' -- cgit v1.2.1 From 59f7604333b695677eaf23a61a4758969a2cee1c Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 21 Oct 2018 07:31:30 -0700 Subject: Add offsets for other W605 tests --- testsuite/W60.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/W60.py b/testsuite/W60.py index 3f1b77c..1b03099 100644 --- a/testsuite/W60.py +++ b/testsuite/W60.py @@ -13,9 +13,9 @@ if x <> 0: x = 0 #: W604 val = `1 + 2` -#: W605 +#: W605:1:9 regex = '\.png$' -#: W605 +#: W605:1:9 regex = ''' \.png$ ''' -- cgit v1.2.1