Ejemplo n.º 1
0
 def _process_line(self, line_number, line_content):
     if match('(^|\ +)#', line_content):
         # ignore comment line
         return
     l = line_content.expandtabs(4)
     # check command like message( "testing")
     if search('\(\ +', l):
         self._handle_style_error(line_number, 'whitespace/parentheses', 5,
                                  'No space after "("')
     # check command like message("testing" )
     if search('\ +\)', l) and not search('^\ +\)$', l):
         self._handle_style_error(line_number, 'whitespace/parentheses', 5,
                                  'No space before ")"')
     self._check_trailing_whitespace(line_number, l)
     self._check_no_space_cmds(line_number, l)
     self._check_one_space_cmds(line_number, l)
     self._check_indent(line_number, line_content)
Ejemplo n.º 2
0
 def _check_one_space_cmds(self, line_number, line_content):
     # check command like "IF (" or "if(" or "if   (" or "If ()"
     for t in self.ONE_SPACE_CMDS:
         self._check_non_lowercase_cmd(line_number, line_content, t)
         if search('(^|\ +)' + t.lower() + '(\(|\ \ +\()', line_content):
             msg = 'One space between command "' + t.lower(
             ) + '" and its parentheses, should be "' + t + ' ("'
             self._handle_style_error(line_number, 'whitespace/parentheses',
                                      5, msg)
Ejemplo n.º 3
0
 def _check_no_space_cmds(self, line_number, line_content):
     # check command like "SET    (" or "Set("
     for t in self.NO_SPACE_CMDS:
         self._check_non_lowercase_cmd(line_number, line_content, t)
         if search('(^|\ +)' + t.lower() + '\ +\(', line_content):
             msg = 'No space between command "' + t.lower(
             ) + '" and its parentheses, should be "' + t + '("'
             self._handle_style_error(line_number, 'whitespace/parentheses',
                                      5, msg)
Ejemplo n.º 4
0
    def check_entry(self, first_line_checked, entry_lines):
        if not entry_lines:
            return
        for line in entry_lines:
            if parse_bug_id_from_changelog(line):
                break
            if searchIgnorecase("Unreviewed", line):
                break
            if searchIgnorecase("build", line) and searchIgnorecase(
                    "fix", line):
                break
        else:
            self.handle_style_error(first_line_checked, "changelog/bugnumber",
                                    5, "ChangeLog entry has no bug number")
        # check file change descriptions for style violations
        line_no = first_line_checked - 1
        for line in entry_lines:
            line_no = line_no + 1
            # filter file change descriptions
            if not match('\s*\*\s', line):
                continue
            if search(':\s*$', line) or search(':\s', line):
                continue
            self.handle_style_error(
                line_no, "changelog/filechangedescriptionwhitespace", 5,
                "Need whitespace between colon and description")

        # check for a lingering "No new tests (OOPS!)." left over from prepare-changeLog.
        line_no = first_line_checked - 1
        for line in entry_lines:
            line_no = line_no + 1
            if match('\s*No new tests \(OOPS!\)\.$', line):
                self.handle_style_error(
                    line_no, "changelog/nonewtests", 5,
                    "You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible."
                )

        self.check_for_unwanted_security_phrases(first_line_checked,
                                                 entry_lines)
Ejemplo n.º 5
0
    def _check_list_order(self, lines):
        last_line = None

        for line_number, line in enumerate(lines, start=1):
            matched = search('\$\{.*\}', line)
            if matched:
                continue
            line = line.strip()

            if last_line == None:
                matched = match(
                    '(set\(|list\((APPEND|REMOVE_ITEM) )(?P<name>\w+)(?P<item>\s+\w+)?$',
                    line)
                if matched:
                    # FIXME: Add handling for include directories.
                    if 'INCLUDE_DIRECTORIES' in matched.group('name'):
                        continue
                    empty_lines_count = 0
                    last_line = ''
                    if matched.group('item'):
                        msg = 'First listitem "%s" should be in a new line.' % matched.group(
                            'item').strip()
                        self._handle_style_error(line_number,
                                                 'list/parentheses', 5, msg)
            else:
                matched = match('(?P<item>.+)?\)$', line)
                if matched:
                    last_line = None
                    if matched.group('item'):
                        msg = 'The parentheses after the last listitem "%s" should be in a new line.' % matched.group(
                            'item').strip()
                        self._handle_style_error(line_number,
                                                 'list/parentheses', 5, msg)
                elif line == '':
                    empty_lines_count += 1
                else:
                    last_line_path = self._list_item_path(last_line)
                    line_path = self._list_item_path(line)

                    if line == last_line:
                        msg = 'The item "%s" should be added only once to the list.' % line
                        self._handle_style_error(line_number, 'list/duplicate',
                                                 5, msg)
                    elif line_path < last_line_path or line_path == last_line_path and line < last_line:
                        msg = 'Alphabetical sorting problem. "%s" should be before "%s".' % (
                            line, last_line)
                        self._handle_style_error(line_number, 'list/order', 5,
                                                 msg)
                    elif last_line != '':
                        if line_path != last_line_path:
                            if empty_lines_count != 1:
                                msg = 'There should be exactly one empty line instead of %d between "%s" and "%s".' % (
                                    empty_lines_count, last_line, line)
                                self._handle_style_error(
                                    line_number, 'list/emptyline', 5, msg)
                        elif empty_lines_count != 0:
                            msg = 'There should be no empty line between "%s" and "%s".' % (
                                last_line, line)
                            self._handle_style_error(line_number,
                                                     'list/emptyline', 5, msg)

                    last_line = line
                    empty_lines_count = 0
Ejemplo n.º 6
0
 def _check_non_lowercase_cmd(self, line_number, line_content, cmd):
     if searchIgnorecase('(^|\ +)' + cmd + '\ *\(', line_content) and \
        (not search('(^|\ +)' + cmd.lower() + '\ *\(', line_content)):
         msg = 'Use lowercase command "' + cmd.lower() + '"'
         self._handle_style_error(line_number, 'command/lowercase', 5, msg)