Skip to content

Commit

Permalink
added newline
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Haase <[email protected]>
  • Loading branch information
FHaase committed Oct 26, 2018
1 parent 11d3a42 commit 7ca2de2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
42 changes: 22 additions & 20 deletions flake8_rst/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,34 @@
re.MULTILINE,
)

EXPRESSIONS = (RST_RE, ANCHOR_RE)


def find_sourcecode(src):
for expression in [RST_RE, ANCHOR_RE]:
for match in expression.finditer(src):
origin_code = match.group('code')
matches = (match for expression in EXPRESSIONS for match in expression.finditer(src))
for match in matches:
origin_code = match.group('code')

try:
min_indent = min(INDENT_RE.findall(origin_code))
except ValueError:
min_indent = ''
try:
min_indent = min(INDENT_RE.findall(origin_code))
except ValueError:
min_indent = ''

indent = len(min_indent)
code = textwrap.dedent(origin_code)
indent = len(min_indent)
code = textwrap.dedent(origin_code)

if '>>>' in code:
indent += 4
lines = []
if '>>>' in code:
indent += 4
lines = []

for i, line in enumerate(code.split('\n')):
for anchor in ANCHORS:
if line.startswith(anchor):
lines.append(line[len(anchor):])
break
for i, line in enumerate(code.split('\n')):
for anchor in ANCHORS:
if line.startswith(anchor):
lines.append(line[len(anchor):])
break

code = '\n'.join(lines)
code = '\n'.join(lines)

line_number = src[:match.start()].count('\n') + match.group('before').count('\n')
line_number = src[:match.start()].count('\n') + match.group('before').count('\n')

yield code.rstrip(), indent, line_number
yield code.rstrip(), indent, line_number
2 changes: 1 addition & 1 deletion tests/data/example_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
>>> print('This line is highlighted.')
This line is highlighted.
"""
"""
12 changes: 6 additions & 6 deletions tests/result_py2/result_10.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
('test_precisely',
[('F821', 20, 10, "undefined name 'LdaModel'", None),
('F821', 20, 26, "undefined name 'mm'", None),
('F821', 20, 38, "undefined name 'id2word'", None),
('F821', 22, 10, "undefined name 'LdfModel'", None),
('F821', 22, 26, "undefined name 'cm'", None),
('F821', 22, 38, "undefined name 'id2word'", None)],
[('F821', 21, 10, "undefined name 'LdaModel'", None),
('F821', 21, 26, "undefined name 'mm'", None),
('F821', 21, 38, "undefined name 'id2word'", None),
('F821', 23, 10, "undefined name 'LdfModel'", None),
('F821', 23, 26, "undefined name 'cm'", None),
('F821', 23, 38, "undefined name 'id2word'", None)],
{'logical lines': 5, 'physical lines': 6, 'tokens': 52})
12 changes: 6 additions & 6 deletions tests/result_py3/result_10.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
('test_precisely',
[('F821', 20, 10, "undefined name 'LdaModel'", None),
('F821', 20, 26, "undefined name 'mm'", None),
('F821', 20, 38, "undefined name 'id2word'", None),
('F821', 22, 10, "undefined name 'LdfModel'", None),
('F821', 22, 26, "undefined name 'cm'", None),
('F821', 22, 38, "undefined name 'id2word'", None)],
[('F821', 21, 10, "undefined name 'LdaModel'", None),
('F821', 21, 26, "undefined name 'mm'", None),
('F821', 21, 38, "undefined name 'id2word'", None),
('F821', 23, 10, "undefined name 'LdfModel'", None),
('F821', 23, 26, "undefined name 'cm'", None),
('F821', 23, 38, "undefined name 'id2word'", None)],
{'logical lines': 5, 'physical lines': 6, 'tokens': 52})

0 comments on commit 7ca2de2

Please sign in to comment.