Lesson checking parameter handling
authorGreg Wilson <gvwilson@third-bit.com>
Fri, 1 Jul 2016 18:10:07 +0000 (14:10 -0400)
committerGreg Wilson <gvwilson@third-bit.com>
Fri, 1 Jul 2016 18:10:07 +0000 (14:10 -0400)
bin/lesson_check.py

index c85661e649271864c57b6adea0a13baf5b24926d..aaec64fac6929c20adc27addf06701d95deedf97 100755 (executable)
@@ -40,6 +40,9 @@ REQUIRED_FILES = {
 # Episode filename pattern.
 P_EPISODE_FILENAME = re.compile(r'/_episodes/(\d\d)-[-\w]+.md$')
 
+# Pattern to match lines ending with whitespace.
+P_TRAILING_WHITESPACE = re.compile(r'\s+$')
+
 # What kinds of blockquotes are allowed?
 KNOWN_BLOCKQUOTES = {
     'callout',
@@ -106,6 +109,7 @@ def parse_args():
     parser = OptionParser()
     parser.add_option('-l', '--linelen',
                       default=False,
+                      action="store_true",
                       dest='line_lengths',
                       help='Check line lengths')
     parser.add_option('-p', '--parser',
@@ -118,6 +122,7 @@ def parse_args():
                       help='source directory')
     parser.add_option('-w', '--whitespace',
                       default=False,
+                      action="store_true",
                       dest='trailing_whitespace',
                       help='Check for trailing whitespace')
 
@@ -263,11 +268,11 @@ class CheckBase(object):
         """Check for whitespace at the ends of lines."""
 
         if self.args.trailing_whitespace:
-            trailing = [i for (i, l, n) in self.lines if l.endswidth(' ')]
+            trailing = [i for (i, l, n) in self.lines if P_TRAILING_WHITESPACE.match(l)]
             self.reporter.check(not trailing,
                                 self.filename,
                                 'Line(s) end with whitespace: {0}',
-                                ', '.join([str[i] for i in over]))
+                                ', '.join([str(i) for i in trailing]))
 
 
     def check_blockquote_classes(self):