Skip to content

Commit

Permalink
bin/lesson_check.py: allow exceptions to line length limit
Browse files Browse the repository at this point in the history
Allow lines that contain a single image or a single link
to go over the suggested line length limit.
  • Loading branch information
maxim-belkin committed May 6, 2021
1 parent 6d5b41e commit ab46307
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit ab46307

Please sign in to comment.