Ejemplo n.º 1
0
    def compute(self, code, annotations):
        start_line = 0
        no_whitespace_run = 0
        levels = None

        for line_no, line in enumerate(code.lines):

            level = code.levels[line_no]
            if no_whitespace_run > 0:
                if not code.levels[line_no]:
                    if no_whitespace_run > MAX_NON_WHITESPACE_LINES:
                        error = "Not enough whitespace"
                        self.add_to_annotations(start_line, error, annotations)
                    no_whitespace_run = 0
                    continue

                levels = levels & set(level)  # check for consistent indent
                if len(levels) == 0 or is_whitespace_line(line):
                    if no_whitespace_run > MAX_NON_WHITESPACE_LINES:
                        error = "Not enough whitespace"
                        self.add_to_annotations(start_line, error, annotations)
                    no_whitespace_run = 0
                else:
                    if 0 not in code.levels[line_no]:
                        no_whitespace_run += 1

            elif not is_whitespace_line(line) and not is_comment(line) and level:
                levels = set(level)
                no_whitespace_run = 1
                start_line = line_no
Ejemplo n.º 2
0
 def compute(self, code, annotations):
     for line_no, line in enumerate(code.lines):
         _line = line.strip()
         if not _line:
             continue
         if not is_comment(_line):
             error = "Each file should have a comment at the top"
             self.add_to_annotations(0, error, annotations)
         return
Ejemplo n.º 3
0
    def test_is_comment(self):
        from utils.line_features import is_comment

        self.assertEqual(is_comment("  // comment "), True)
        self.assertEqual(is_comment("  /* comment "), True)
        self.assertEqual(is_comment("\t\t// comment "), True)
        self.assertEqual(is_comment("  Something(); // comment "), False)
        self.assertEqual(is_comment("  Something();  "), False)
        self.assertEqual(is_comment("    "), False)