Skip to content

Commit

Permalink
Skip lines with strings tokens that have non-skip tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
brianv0 committed Dec 1, 2017
1 parent 0ec42bb commit b8a2b13
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pycodestyle.py
Expand Up @@ -1467,11 +1467,19 @@ def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):
return

prev_token = None
skip_lines = set()
# Skip lines that
for token_type, text, start, end, line in tokens:
if token_type not in SKIP_COMMENTS.union([tokenize.STRING]):
skip_lines.add(line)

for token_type, text, start, end, line in tokens:
# Skip lines that aren't pure strings
if token_type == tokenize.STRING and skip_lines:
continue
if token_type in (tokenize.STRING, tokenize.COMMENT):
# Only check comment-only lines
if prev_token is None or prev_token in SKIP_TOKENS:
line_start = start[0]
lines = line.splitlines()
for line_num, physical_line in enumerate(lines):
if hasattr(physical_line, 'decode'): # Python 2
Expand All @@ -1491,11 +1499,10 @@ def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):
length - len(chunks[-1]) < MAX_DOC_LENGTH):
continue
if length > max_doc_length:
doc_error = (line_start, max_doc_length)
doc_error = (start[0] + line_num, max_doc_length)
yield (doc_error, "W504 doc line too long "
"(%d > %d characters)"
% (length, max_doc_length))
line_start += 1
prev_token = token_type


Expand Down

0 comments on commit b8a2b13

Please sign in to comment.