Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/lesson_check.py: allow exceptions to line length limit #594

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions bin/lesson_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
# Pattern to match {% include ... %} statements
P_INTERNAL_INCLUDE_LINK = re.compile(r'^{% include ([^ ]*) %}$')

# Pattern to match image-only and link-only lines
P_LINK_IMAGE_LINE = re.compile("^[> ]*(!?)\[([^]]+)\][([]([^)]+)[])][ ]*$")

# What kinds of blockquotes are allowed?
KNOWN_BLOCKQUOTES = {
'callout',
Expand Down Expand Up @@ -376,12 +379,19 @@ def check_line_lengths(self):
"""Check the raw text of the lesson body."""

if self.args.line_lengths:
over = [i for (i, l, n) in self.lines if (
n > MAX_LINE_LEN) and (not l.startswith('!'))]
self.reporter.check(not over,
over_limit = []

for (i, l, n) in self.lines:
# Report lines that are longer than the suggested
# line length limit only if they're not
# link-only or image-only lines.
if n > MAX_LINE_LEN and not P_LINK_IMAGE_LINE.match(l):
over_limit.append(i)

self.reporter.check(not over_limit,
self.filename,
'Line(s) too long: {0}',
', '.join([str(i) for i in over]))
', '.join([str(i) for i in over_limit]))

def check_trailing_whitespace(self):
"""Check for whitespace at the ends of lines."""
Expand Down